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

feat: add ability to use existing config during init #6489

Merged
merged 2 commits into from
Aug 28, 2019

Conversation

djdv
Copy link
Contributor

@djdv djdv commented Jul 9, 2019

Related to:
#6262

This patch adds
ipfs daemon --init --init-config-file=${PATH}
and
ipfs init --config-file=${PATH}
allowing users to specify existing configuration files instead of (re)generating them.

Does not deal with merging of existing configs and/or profiles (yet?).

Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

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

Good start. We can do merging in a followup.

cmd/ipfs/daemon.go Show resolved Hide resolved
cmd/ipfs/init.go Outdated
profile, _ := req.Options[profileOptionName].(string)

if cfgLocation != "" {
if profile != "" {
return errInitConfigArgs
Copy link
Member

Choose a reason for hiding this comment

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

Any reason to reject this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably not.
I was thinking we needed to merge profiles rather than use the config transformers. I'll update this.

Copy link
Contributor Author

@djdv djdv Jul 10, 2019

Choose a reason for hiding this comment

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

Okay so this works now.

set IPFS_PATH=Z:\ipfs-dev-tmp1
ipfs init
set IPFS_PATH=Z:\ipfs-dev-tmp2
ipfs daemon --init --init-config-file=Z:\ipfs-dev-tmp1\config --init-profile=badgerds,randomports
diff Z:\ipfs-dev-tmp1 Z:\ipfs-dev-tmp2
Only in Z:\ipfs-dev-tmp2: badgerds
Only in Z:\ipfs-dev-tmp1: blocks
diff "Z:\\ipfs-dev-tmp1/config" "Z:\\ipfs-dev-tmp2/config"
11,34c11,18
<       "mounts": [
<         {
<           "child": {
<             "path": "blocks",
<             "shardFunc": "/repo/flatfs/shard/v1/next-to-last/2",
<             "sync": true,
<             "type": "flatfs"
<           },
<           "mountpoint": "/blocks",
<           "prefix": "flatfs.datastore",
<           "type": "measure"
<         },
<         {
<           "child": {
<             "compression": "none",
<             "path": "datastore",
<             "type": "levelds"
<           },
<           "mountpoint": "/",
<           "prefix": "leveldb.datastore",
<           "type": "measure"
<         }
<       ],
<       "type": "mount"
---
>       "child": {
>         "path": "badgerds",
>         "syncWrites": true,
>         "truncate": true,
>         "type": "badgerds"
>       },
>       "prefix": "badger.datastore",
>       "type": "measure"
41,42c25,26
<       "/ip4/0.0.0.0/tcp/4001",
<       "/ip6/::/tcp/4001"
---
>       "/ip4/0.0.0.0/tcp/16936",
>       "/ip6/::/tcp/16936"
Only in Z:\ipfs-dev-tmp1: datastore
diff "Z:\\ipfs-dev-tmp1/datastore_spec" "Z:\\ipfs-dev-tmp2/datastore_spec"
1c1
< {"mounts":[{"mountpoint":"/blocks","path":"blocks","shardFunc":"/repo/flatfs/shard/v1/next-to-last/2","type":"flatfs"},{"mountpoint":"/","path":"datastore","type":"levelds"}],"type":"mount"}
\ No newline at end of file
---
> {"path":"badgerds","type":"badgerds"}
\ No newline at end of file
Common subdirectories: Z:\ipfs-dev-tmp1/keystore and Z:\ipfs-dev-tmp2/keystore

Copy link
Member

Choose a reason for hiding this comment

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

I'd say allow both (but we can stick to transformers for now). That is:

  1. Take the initial config, if supplied.
  2. Merge it with the default config (later).
  3. Apply transformers (if specified).

@djdv djdv force-pushed the feat/init-with-config-file branch 2 times, most recently from 73615a8 to 69893e3 Compare July 10, 2019 14:51
@djdv
Copy link
Contributor Author

djdv commented Jul 10, 2019

Rewrote the first commit to be more accurate

-               cmds.StringOption(configOptionName, "Use supplied config instead of generating one"),
+               cmds.StringOption(configOptionName, "Use supplied config as a base instead of the default"),

Edit:
now with the correct commit...

@djdv djdv force-pushed the feat/init-with-config-file branch from 69893e3 to 4bb2df4 Compare July 10, 2019 15:02
cmd/ipfs/init.go Outdated
var profiles []string
if profile != "" {
profiles = strings.Split(profile, ",")
if cfgLocation != "" {
Copy link
Member

Choose a reason for hiding this comment

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

Hm, it looks like we currently accept one argument for the "initial config". We should:

  1. Make sure we aren't passed both.
  2. Consider deprecating that?

Or maybe we don't need this flag on init (we could only support passing the config as an argument on init?). @hugomrdias, what's the state of javascript here?

cmd/ipfs/init.go Outdated
return err
}

return doInit(os.Stdout, cctx.ConfigRoot, false, nBitsForKeypairDefault, profiles, conf)
Copy link
Member

Choose a reason for hiding this comment

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

Why not use the doInit call below? This one drops the empty flag and passes the wrong nBitsForKeypair option (although I guess that doesn't do anything right now).

cmd/ipfs/daemon.go Show resolved Hide resolved
@djdv djdv force-pushed the feat/init-with-config-file branch 3 times, most recently from 915e376 to 7b3e818 Compare July 10, 2019 21:42
@Stebalien
Copy link
Member

Status: Blocked on ipfs init /path/to/config versus ipfs init --config /path/to/config. We currently do the former, this patch does both. I'd prefer to not have two ways to do the same thing if possible.

cc @hugomrdias?

@lanzafame
Copy link
Contributor

What does ipfs init /path/to/config do?

@Stebalien
Copy link
Member

@lanzafame at the moment, it initializes with an existing config.

@djdv
Copy link
Contributor Author

djdv commented Jul 12, 2019

@Stebalien

ipfs init --config /path/to/config

Whether this was intended or not, I have to be pedantic here since it's relevant.

ipfs init --config (global flag) is not the same as ipfs init --config-file or ipfs daemon --init --init-config-file (subcommand specific flags).

Calling that results in this

>set IPFS_PATH=Z:\itmp-1
>ipfs init
initializing IPFS node at Z:\itmp-1
...
>set IPFS_PATH=Z:\itmp-2
>ipfs init --config=Z:\itmp-1\config
initializing IPFS node at Z:\itmp-1\config
Error: unexpected error while checking writeablility of repo root: open Z:\itmp-1\config\test: The system cannot find the path specified.

It's also a bit of a hasty blunder on my part to have forgotten the existing --config flag as well as the <default-config> handling. There's a lot of redundancy happening in this patch.

If we can, I'm not opposed to using ipfs init --config to act the same as ipfs init --config-file.
But this may be confusing if we handle that global flag in a unique way inside of init than we do in other other commands.

Explicitly pointing out that init handles config via stdin or a file path argument where --config-file only handles file paths.

@Stebalien
Copy link
Member

Oh dear. --config appear to be equivalent to IPFS_PATH=... ipfs. That's really confusing and we should make that sane (i.e., make --config point to an out-of-repo config). But that's a separate issue.

Yeah, we need to make sure js/go agree here or it's going to be really confusing.

@hugomrdias
Copy link
Member

in js:

  • we don't have the global --config flag
  • ipfs init accepts a json string input
    • ipfs init "{}"
  • ipfs daemon doesn't support init or config
  • we do have IPFS_PATH for the repo path

making ipfs [cmd] --config point to an out-of-repo config will make ipfs init /path/config equal to ipfs init --config /path/config right ?
If the above is the way to go we don't need anything else, but that is probably a bigger change that we don't want right now.

so maybe,

  • ipfs init /path/config (no changes at all to master)
  • ipfs daemon --init --init-config /path/config

makes sense ?

On js side i'll code whatever we decide here no blockers there.

@djdv djdv force-pushed the feat/init-with-config-file branch from 7b3e818 to 8c9fab9 Compare July 17, 2019 03:01
@djdv
Copy link
Contributor Author

djdv commented Jul 17, 2019

Went ahead with the change.
Removed ipfs init --config-file flag (in favour of existing file+stdin handling via <default-config>).
ipfs daemon --init --init-config-file became ipfs daemon --init --init-config
Cleanup in init.go remains in patch.

@hugomrdias
Copy link
Member

@Stebalien can we unblock this ?

Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

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

Ok, code LGTM (sorry for the delay).

@djdv could you write a quick sharness test for this?

@djdv djdv force-pushed the feat/init-with-config-file branch from 0755391 to c85a98f Compare August 15, 2019 14:23
@djdv djdv force-pushed the feat/init-with-config-file branch from c85a98f to 21b8aba Compare August 26, 2019 01:37
@hugomrdias
Copy link
Member

@djdv anything i can do to help with this ?

@djdv
Copy link
Contributor Author

djdv commented Aug 26, 2019

@hugomrdias
Would you mind looking at the sharness tests? I'm not sure what's breaking things here.

@djdv djdv force-pushed the feat/init-with-config-file branch 3 times, most recently from 56746d0 to 1a89933 Compare August 26, 2019 17:49
@djdv djdv force-pushed the feat/init-with-config-file branch 3 times, most recently from f12f59d to 6996faa Compare August 26, 2019 21:16
@djdv djdv force-pushed the feat/init-with-config-file branch from 6996faa to e7e7000 Compare August 28, 2019 23:00
@Stebalien Stebalien merged commit d2a1ce3 into ipfs:master Aug 28, 2019
hugomrdias added a commit to ipfs/js-ipfs that referenced this pull request Sep 5, 2019
This PR aligns `ipfs init` and `ipfs daemon` with go-ipfs.

ipfs/kubo#6489

`ipfs init` changed to accept a file path as an argument

`ipfs daemon` changed to support `--init` and `--init-config` options.

Now we can do `ipfs daemon --init --init-config /path/to/custom-config`

refs:
ipfs/js-ipfsd-ctl#303
hugomrdias added a commit to ipfs/js-ipfs that referenced this pull request Sep 5, 2019
This PR aligns `ipfs init` and `ipfs daemon` with go-ipfs.

ipfs/kubo#6489

`ipfs init` changed to accept a file path as an argument

`ipfs daemon` changed to support `--init` and `--init-config` options.

Now we can do `ipfs daemon --init --init-config /path/to/custom-config`

refs:
ipfs/js-ipfsd-ctl#303
hugomrdias added a commit to ipfs/js-ipfs that referenced this pull request Sep 6, 2019
This PR aligns `ipfs init` and `ipfs daemon` with go-ipfs.

ipfs/kubo#6489

`ipfs init` changed to accept a file path as an argument

`ipfs daemon` changed to support `--init` and `--init-config` options.

Now we can do `ipfs daemon --init --init-config /path/to/custom-config`

refs:
ipfs/js-ipfsd-ctl#303
hugomrdias added a commit to ipfs/js-ipfs that referenced this pull request Sep 11, 2019
This PR aligns `ipfs init` and `ipfs daemon` with go-ipfs.

ipfs/kubo#6489

`ipfs init` changed to accept a file path as an argument

`ipfs daemon` changed to support `--init` and `--init-config` options.

Now we can do `ipfs daemon --init --init-config /path/to/custom-config`

refs:
ipfs/js-ipfsd-ctl#303
hugomrdias added a commit to ipfs/js-ipfs that referenced this pull request Sep 16, 2019
This PR aligns `ipfs init` and `ipfs daemon` with go-ipfs.

ipfs/kubo#6489

`ipfs init` changed to accept a file path as an argument

`ipfs daemon` changed to support `--init` and `--init-config` options.

Now we can do `ipfs daemon --init --init-config /path/to/custom-config`

refs:
ipfs/js-ipfsd-ctl#303
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants