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

Add more validation and help to config #814

Merged
merged 7 commits into from
Feb 25, 2021
Merged

Conversation

dchw
Copy link
Collaborator

@dchw dchw commented Feb 25, 2021

Adds help text for main command, and for keys (at the expense of being able to set a value to --help.

Adds validation to ensure you can set the key to that value.

Copy link
Member

@vladaionescu vladaionescu left a comment

Choose a reason for hiding this comment

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

This is pretty neat!

config/config.go Outdated
DebuggerPort int `yaml:"debugger_port" help:"What port should the debugger (and other interactive sessions) use to communicate."`
BuildkitRestartTimeoutS int `yaml:"buildkit_restart_timeout_s" help:"How long to wait for buildkit to (re)start, in seconds."`
BuildkitAdditionalArgs []string `yaml:"buildkit_additional_args" help:"Additional args to pass to buildkit when it starts. Useful for custom certs, or user namespace complications."`
BuildkitAdditionalConfig string `yaml:"buildkit_additional_config" help:"Additional config to use when starting the buildkit container; like mounting volumes."`
Copy link
Member

Choose a reason for hiding this comment

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

Actually mounting volumes would be done through BuilkditAdditionalArgs. An example might be "using self-signed certificates"

@alexcb
Copy link
Collaborator

alexcb commented Feb 25, 2021

I got a panic when I ran this:

alex@mah:~/gh/earthly/earthly$ ./build/linux/amd64/earthly config git.bar blah
panic: reflect: call of reflect.Value.Type on zero Value [recovered]
	panic: reflect: call of reflect.Value.Type on zero Value

goroutine 1 [running]:
gopkg.in/yaml%2ev3.handleErr(0xc0002df170)
	/go/pkg/mod/gopkg.in/yaml.v3@v3.0.0-20210107192922-496545a6307b/yaml.go:294 +0x8d
panic(0xf65400, 0xc0001214b8)
	/usr/local/go/src/runtime/panic.go:965 +0x1b9
reflect.Value.Type(0x0, 0x0, 0x0, 0x70, 0x7ff3f4e54e28)
	/usr/local/go/src/reflect/value.go:1908 +0x189
gopkg.in/yaml%2ev3.(*decoder).unmarshal(0xc0004aa4d0, 0xc000498d20, 0x0, 0x0, 0x0, 0xc0004a4160)
	/go/pkg/mod/gopkg.in/yaml.v3@v3.0.0-20210107192922-496545a6307b/decode.go:487 +0xbe
gopkg.in/yaml%2ev3.(*Node).Decode(0xc000498d20, 0x0, 0x0, 0x0, 0x0)
	/go/pkg/mod/gopkg.in/yaml.v3@v3.0.0-20210107192922-496545a6307b/yaml.go:149 +0x1bd
github.com/earthly/earthly/config.keyAndValueCompatible(0x122f218, 0xf2fd80, 0xc000498d20, 0x0)
	/earthly/config/config.go:178 +0xb2
github.com/earthly/earthly/config.UpsertConfig(0x18e5f48, 0x0, 0x0, 0x7fff0bb8ed12, 0x7, 0x7fff0bb8ed1a, 0x4, 0x0, 0x184a820, 0x121b500, ...)
	/earthly/config/config.go:214 +0x275
main.(*earthlyApp).actionConfig(0xc000445500, 0xc00049e900, 0xc00046ad00, 0xc00046add0)
	/earthly/cmd/earthly/main.go:2040 +0x27e
github.com/urfave/cli/v2.(*Command).Run(0xc000477e60, 0xc00049e800, 0x0, 0x0)
	/go/pkg/mod/github.com/urfave/cli/v2@v2.3.0/command.go:163 +0x4dd
github.com/urfave/cli/v2.(*App).RunContext(0xc0003bf6c0, 0x121b008, 0xc0002e3bc0, 0xc000132000, 0x4, 0x4, 0x0, 0x0)
	/go/pkg/mod/github.com/urfave/cli/v2@v2.3.0/app.go:313 +0x810
main.(*earthlyApp).run(0xc000445500, 0x121b008, 0xc0002e3bc0, 0xc000132000, 0x4, 0x4, 0x0)
	/earthly/cmd/earthly/main.go:1112 +0xad
main.main()
	/earthly/cmd/earthly/main.go:225 +0x485

If it's relevant, I don't have a ~/.earthly/config.yml

@alexcb
Copy link
Collaborator

alexcb commented Feb 25, 2021

I think there's a missing newline required somewhere in the code:

alex@mah:~/gh/earthly/earthly$ ./build/linux/amd64/earthly config git --help
(map): Git configuration object. Requires YAML literal to set directly.alex@mah:~/gh/earthly/earthly$ 

@dchw
Copy link
Collaborator Author

dchw commented Feb 25, 2021

@alexcb Good catch on the missing newline; added/

Also, the panic is from deep down inside the YAML parser?? I'll add a panic handler and assume panics are incompatible, I guess

Nope. Forgot to assign val in the default case 🤦. Should be fixed now @alexcb

@@ -810,17 +810,37 @@ func newEarthlyApp(ctx context.Context, console conslogging.ConsoleLogger) *eart
Usage: "Edits your Earthly configuration file",
Hidden: true, // Experimental.
Action: app.actionConfig,
Description: `This command takes a path, and a value and sets it in your configuration file.
UsageText: `This command takes a path, and a value and sets it in your configuration file.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not a standard usage, but there isn't an Examples section. This kept the flow while being slightly wrong? Willing to reverse or hard-code in the examples section if needed. Also I could make the UsageText include the current english description,, and the Description include the examples.

Sample, as it is now:

NAME:
   earthly config - Edits your Earthly configuration file

USAGE:
   This command takes a path, and a value and sets it in your configuration file.

  As the configuration file is YAML, the key must be a valid key within the file. You can specify sub-keys by using "." to separate levels.
  If the sub-key you wish to use has a "." in it, you can quote that subsection, like this: git."github.com".

  Values must be valid YAML, and also be deserializable into the key you wish to assign them to.
  This means you can set higher level objects using a compact style, or single values with simple values.

  Only one key/value can be set per invocation.

  To get help with a specific key, do "config [key] --help". Or, visit https://docs.earthly.dev/earthly-config for more details.

DESCRIPTION:
   Set your cache size:
   
     config global.cache_size_mb 1234
   
   Set additional buildkit args, using a YAML array:
   
     config global.buildkit_additional_args ['userns', '--host']
   
   Set a key containing a period:
       
     config git."example.com".password hunter2
   
   Configure a server called example.com which stored git repos under /var/git/repos/name-of-repo.git and allowed access over ssh using port 2222 with the git username, you can configure earthly to recognize it as example.com/name-of-repo by configuring it with:
   
     config git "{example: {pattern: 'example.com/([^/]+)', substitute: 'ssh://git@example.com:2222/var/git/repos/\$1.git', auth: ssh}}"

OPTIONS:
   --dry-run   Print the changed config file to the consile instead of writing it out (default: false)
   --help, -h  show help (default: false)

Copy link
Collaborator

Choose a reason for hiding this comment

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

looks awesome!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I made your sentence a bulleted list:

   Set up a whole custom git repository for a server called example.com, using a single-line YAML literal:
     * which stores git repos under /var/git/repos/name-of-repo.git
     * allows access over ssh
     * using port 2222
     * sets the username to git
     * is recognized to earthly as example.com/name-of-repo
   
     config git "{example: {pattern: 'example.com/([^/]+)', substitute: 'ssh://git@example.com:2222/var/git/repos/\$1.git', auth: ssh}}"

@dchw dchw merged commit 2f9d52f into main Feb 25, 2021
@dchw dchw deleted the corey/config-validation-fixes branch February 25, 2021 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants