Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pass config to init #303

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,16 @@
"license": "MIT",
"dependencies": {
"async": "^2.6.1",
"base-x": "^3.0.4",
"boom": "^7.2.0",
"base-x": "^3.0.5",
"boom": "^7.2.1",
"debug": "^4.1.0",
"detect-node": "^2.0.4",
"dexie": "^2.0.4",
"execa": "^1.0.0",
"hapi": "^16.6.2",
"hat": "~0.0.3",
"ipfs-api": "^25.0.0",
"joi": "^13.1.2",
"ipfs-api": "^26.1.0",
"joi": "^14.0.3",
"libp2p-crypto": "~0.14.0",
"lodash.clone": "^4.5.0",
"lodash.defaults": "^4.2.0",
Expand All @@ -104,20 +104,20 @@
"protons": "^1.0.1",
"rimraf": "^2.6.2",
"safe-json-parse": "^4.0.0",
"safe-json-stringify": "^1.1.0",
"superagent": "^3.8.2"
"safe-json-stringify": "^1.2.0",
"superagent": "^4.0.0-beta.5"
},
"devDependencies": {
"aegir": "^17.0.0",
"chai": "^4.1.2",
"aegir": "^17.0.1",
"chai": "^4.2.0",
"dependency-check": "^3.2.1",
"detect-port": "^1.2.2",
"detect-port": "^1.2.3",
"dirty-chai": "^2.0.1",
"go-ipfs-dep": "0.4.17",
"ipfs": "~0.32.0",
"ipfs": "~0.33.0",
"is-running": "^2.1.0",
"mkdirp": "~0.5.1",
"proxyquire": "^2.0.1",
"proxyquire": "^2.1.0",
"superagent-mocker": "~0.5.2"
},
"repository": {
Expand Down
17 changes: 14 additions & 3 deletions src/ipfsd-daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ class Daemon {
}

const bits = initOptions.bits || this.bits
const args = ['init']
const args = [
'init',
this.opts.type === 'js' && JSON.stringify(this.opts.config)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why just JS?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we haz this for Go as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i talked about this in the ipfs pr ipfs/js-ipfs#1662 (comment)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Stebalien can you check this ^^

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go actually takes in an initial config as a file argument (positional). However, it won't merge it. Really, I'm not sure how I'd expect merging to work.

We also have a concept of "profiles" for patching our config.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Stebalien we added support for passing a json string has a positional arg to the init cmd like this https://github.com/ipfs/js-ipfs/pull/1662/files
We already had a config options https://github.com/ipfs/js-ipfs#optionsconfig so it was straight forward.
It's just a simple deep merge with the default config.

any chance we can get something similar in go ? we can consider other ways to do it!

we just want to reduce the number of child processes that ctl spawns

Right now we need to spawn 4 child_processes to start a node in ctl

ipfs init
ipfs config show
ipfs config replace
ipfs daemon

With this PR we would only need 2

ipfs init '{"Addresses":{"Swarm":["/ip4/0.0.0.0/tcp/4003"]}}'
ipfs daemon

Final goal is to just do

ipfs daemon --init --config "{}"

This will help a lot making our tests faster!!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A similar issue has come up with in cluster: ipfs/kubo#6262 (comment) (maybe, I may be misunderstanding the issue).

However, I believe they'll need to pass by-file. Would that work here or will we need two options.

].filter(Boolean)
// do not just set a default keysize,
// in case we decide to change it at
// the daemon level in the future
Expand All @@ -174,14 +177,22 @@ class Daemon {
args.push('--pass')
args.push('"' + initOptions.pass + '"')
}
run(this, args, { env: this.env }, (err, result) => {
run(this, args, { stdout: data => console.log(data.toString()), env: this.env }, (err, result) => {
if (err) {
return callback(err)
}

if (this.opts.type === 'js') {
this.clean = false
this.initialized = true
return callback(null, this)
}

waterfall([
(cb) => this.getConfig(cb),
(conf, cb) => this.replaceConfig(defaults({}, this.opts.config, conf), cb)
(conf, cb) => {
this.replaceConfig(defaults({}, this.opts.config, conf), cb)
}
], (err) => {
if (err) { return callback(err) }
this.clean = false
Expand Down