-
Notifications
You must be signed in to change notification settings - Fork 249
Added --root-user flag to devbox generate #1359
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not super familiar with dockerfile changes. Some comments on golang changes.
devbox.go
Outdated
GenerateDevcontainer(ctx context.Context, force bool, rootUser bool) error | ||
GenerateDockerfile(ctx context.Context, force bool, rootUser bool) error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bool params are bad. Consider using struct. Could even be part of devopt.Opts
devopt.Opts{
GenerateOpts: devopt.GenerateOpts{
Force: force,
RootUser: rootUser,
}
}
internal/boxcli/generate.go
Outdated
@@ -63,6 +64,8 @@ func devcontainerCmd() *cobra.Command { | |||
} | |||
command.Flags().BoolVarP( | |||
&flags.force, "force", "f", false, "force overwrite on existing files") | |||
command.Flags().BoolVarP( | |||
&flags.rootUser, "root-user", "r", false, "Use root as default user inside the container") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should use a short flag for this (so no -r
). It's not a super common flag and we may want to use -r
for something else in the future. (when in doubt, it's a bit better not to add short flag)
internal/boxcli/generate.go
Outdated
@@ -80,6 +83,8 @@ func dockerfileCmd() *cobra.Command { | |||
} | |||
command.Flags().BoolVarP( | |||
&flags.force, "force", "f", false, "force overwrite existing files") | |||
command.Flags().BoolVarP( | |||
&flags.rootUser, "root-user", "r", false, "Use root as default user inside the container") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto, no short flag.
internal/impl/devbox.go
Outdated
@@ -394,15 +394,21 @@ func (d *Devbox) GenerateDevcontainer(ctx context.Context, force bool) error { | |||
return redact.Errorf("error creating dev container directory in <project>/%s: %w", | |||
redact.Safe(filepath.Base(devContainerPath)), err) | |||
} | |||
isDevcontainer := true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
generally prefer comments to local variable that is only used once, but even better would be to use struct to simulate named params.
type Generate struct { | ||
Ctx context.Context | ||
Path string | ||
RootUser bool | ||
IsDevcontainer bool | ||
Pkgs []string | ||
LocalFlakeDirs []string | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few issues:
- Not sure about the name (
generate.Generate
is repetitive and doesn't convey what it does). - As currently used it does not need to be exported.
- It should not contain context. (In general context should never be saved in a struct).
Proposal:
- Name it
Options
instead. - Remove context.
- Remove Open
Code would look like:
g := &generate.Options{...}
g.CreateDockerfile(ctx)
@@ -128,7 +158,10 @@ func getDevcontainerContent(pkgs []string) *devcontainerObject { | |||
}, | |||
}, | |||
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this comment still relevant?
## Summary Follow up for #1359 Updates docs for newly added flag for `devbox generate dockerfile` and `devbox generate devcontainer` ## How was it tested? N/A --------- Co-authored-by: Lucille Hua <[email protected]>
424dd8b
to
3266546
Compare
@mikeland73 I updated the PR based on the feedback. PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
I'm less confident about the dockerfile stuff so make sure that's well tested.
@@ -139,13 +144,17 @@ func runGenerateCmd(cmd *cobra.Command, flags *generateCmdFlags) error { | |||
if err != nil { | |||
return errors.WithStack(err) | |||
} | |||
generateOpts := devopt.GenerateOpts{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hack, if you embed devopt.GenerateOpts
to the flag struct you can pass flags.GenerateOpts
into the functions below.
Summary
follow up for #1325
This also potentially fixes an issue reported for users having permission issues with
.devbox/
directory inside devcontainer because ofroot
user inside the container.Added a
--root-user
flag to allow both single user installation and multi user installation for nix as well as setup for Dockerfile and devcontainer.json.This allows users to choose either
devbox
as a user in the container environment (default) orroot
as a user in the container environment (passing--root-user
flag).How was it tested?
devbox generate dockerfile -f -r
compare content of Dockerfile with
devbox generate dockerfile -f