Skip to content
Merged
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
32 changes: 16 additions & 16 deletions cmd/nerdctl/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,25 @@ import (
)

func NewBuilderCommand() *cobra.Command {
var builderCommand = &cobra.Command{
var cmd = &cobra.Command{
Annotations: map[string]string{helpers.Category: helpers.Management},
Use: "builder",
Short: "Manage builds",
RunE: helpers.UnknownSubcommandAction,
SilenceUsage: true,
SilenceErrors: true,
}
builderCommand.AddCommand(
cmd.AddCommand(
NewBuildCommand(),
newBuilderPruneCommand(),
newBuilderDebugCommand(),
)
return builderCommand
return cmd
}

func newBuilderPruneCommand() *cobra.Command {
shortHelp := `Clean up BuildKit build cache`
var buildPruneCommand = &cobra.Command{
var cmd = &cobra.Command{
Use: "prune",
Args: cobra.NoArgs,
Short: shortHelp,
Expand All @@ -58,11 +58,11 @@ func newBuilderPruneCommand() *cobra.Command {
SilenceErrors: true,
}

helpers.AddStringFlag(buildPruneCommand, "buildkit-host", nil, "", "BUILDKIT_HOST", "BuildKit address")
helpers.AddStringFlag(cmd, "buildkit-host", nil, "", "BUILDKIT_HOST", "BuildKit address")

buildPruneCommand.Flags().BoolP("all", "a", false, "Remove all unused build cache, not just dangling ones")
buildPruneCommand.Flags().BoolP("force", "f", false, "Do not prompt for confirmation")
return buildPruneCommand
cmd.Flags().BoolP("all", "a", false, "Remove all unused build cache, not just dangling ones")
cmd.Flags().BoolP("force", "f", false, "Do not prompt for confirmation")
return cmd
}

func builderPruneAction(cmd *cobra.Command, _ []string) error {
Expand Down Expand Up @@ -133,21 +133,21 @@ func processBuilderPruneOptions(cmd *cobra.Command) (types.BuilderPruneOptions,

func newBuilderDebugCommand() *cobra.Command {
shortHelp := `Debug Dockerfile`
var buildDebugCommand = &cobra.Command{
var cmd = &cobra.Command{
Use: "debug",
Short: shortHelp,
PreRunE: helpers.CheckExperimental("`nerdctl builder debug`"),
RunE: builderDebugAction,
SilenceUsage: true,
SilenceErrors: true,
}
buildDebugCommand.Flags().StringP("file", "f", "", "Name of the Dockerfile")
buildDebugCommand.Flags().String("target", "", "Set the target build stage to build")
buildDebugCommand.Flags().StringArray("build-arg", nil, "Set build-time variables")
buildDebugCommand.Flags().String("image", "", "Image to use for debugging stage")
buildDebugCommand.Flags().StringArray("ssh", nil, "Allow forwarding SSH agent to the build. Format: default|<id>[=<socket>|<key>[,<key>]]")
buildDebugCommand.Flags().StringArray("secret", nil, "Expose secret value to the build. Format: id=secretname,src=filepath")
return buildDebugCommand
cmd.Flags().StringP("file", "f", "", "Name of the Dockerfile")
cmd.Flags().String("target", "", "Set the target build stage to build")
cmd.Flags().StringArray("build-arg", nil, "Set build-time variables")
cmd.Flags().String("image", "", "Image to use for debugging stage")
cmd.Flags().StringArray("ssh", nil, "Allow forwarding SSH agent to the build. Format: default|<id>[=<socket>|<key>[,<key>]]")
cmd.Flags().StringArray("secret", nil, "Expose secret value to the build. Format: id=secretname,src=filepath")
return cmd
}

func builderDebugAction(cmd *cobra.Command, args []string) error {
Expand Down
60 changes: 30 additions & 30 deletions cmd/nerdctl/builder/builder_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
)

func NewBuildCommand() *cobra.Command {
var buildCommand = &cobra.Command{
var cmd = &cobra.Command{
Use: "build [flags] PATH",
Short: "Build an image from a Dockerfile. Needs buildkitd to be running.",
Long: `Build an image from a Dockerfile. Needs buildkitd to be running.
Expand All @@ -44,44 +44,44 @@ If Dockerfile is not present and -f is not specified, it will look for Container
SilenceUsage: true,
SilenceErrors: true,
}
helpers.AddStringFlag(buildCommand, "buildkit-host", nil, "", "BUILDKIT_HOST", "BuildKit address")
buildCommand.Flags().StringArray("add-host", nil, "Add a custom host-to-IP mapping (format: \"host:ip\")")
buildCommand.Flags().StringArrayP("tag", "t", nil, "Name and optionally a tag in the 'name:tag' format")
buildCommand.Flags().StringP("file", "f", "", "Name of the Dockerfile")
buildCommand.Flags().String("target", "", "Set the target build stage to build")
buildCommand.Flags().StringArray("build-arg", nil, "Set build-time variables")
buildCommand.Flags().Bool("no-cache", false, "Do not use cache when building the image")
buildCommand.Flags().StringP("output", "o", "", "Output destination (format: type=local,dest=path)")
buildCommand.Flags().String("progress", "auto", "Set type of progress output (auto, plain, tty). Use plain to show container output")
buildCommand.Flags().String("provenance", "", "Shorthand for \"--attest=type=provenance\"")
buildCommand.Flags().Bool("pull", false, "On true, always attempt to pull latest image version from remote. Default uses buildkit's default.")
buildCommand.Flags().StringArray("secret", nil, "Secret file to expose to the build: id=mysecret,src=/local/secret")
buildCommand.Flags().StringArray("allow", nil, "Allow extra privileged entitlement, e.g. network.host, security.insecure")
buildCommand.RegisterFlagCompletionFunc("allow", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
helpers.AddStringFlag(cmd, "buildkit-host", nil, "", "BUILDKIT_HOST", "BuildKit address")
cmd.Flags().StringArray("add-host", nil, "Add a custom host-to-IP mapping (format: \"host:ip\")")
cmd.Flags().StringArrayP("tag", "t", nil, "Name and optionally a tag in the 'name:tag' format")
cmd.Flags().StringP("file", "f", "", "Name of the Dockerfile")
cmd.Flags().String("target", "", "Set the target build stage to build")
cmd.Flags().StringArray("build-arg", nil, "Set build-time variables")
cmd.Flags().Bool("no-cache", false, "Do not use cache when building the image")
cmd.Flags().StringP("output", "o", "", "Output destination (format: type=local,dest=path)")
cmd.Flags().String("progress", "auto", "Set type of progress output (auto, plain, tty). Use plain to show container output")
cmd.Flags().String("provenance", "", "Shorthand for \"--attest=type=provenance\"")
cmd.Flags().Bool("pull", false, "On true, always attempt to pull latest image version from remote. Default uses buildkit's default.")
cmd.Flags().StringArray("secret", nil, "Secret file to expose to the build: id=mysecret,src=/local/secret")
cmd.Flags().StringArray("allow", nil, "Allow extra privileged entitlement, e.g. network.host, security.insecure")
cmd.RegisterFlagCompletionFunc("allow", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return []string{"network.host", "security.insecure"}, cobra.ShellCompDirectiveNoFileComp
})
buildCommand.Flags().StringArray("attest", nil, "Attestation parameters (format: \"type=sbom,generator=image\")")
buildCommand.Flags().StringArray("ssh", nil, "SSH agent socket or keys to expose to the build (format: default|<id>[=<socket>|<key>[,<key>]])")
buildCommand.Flags().BoolP("quiet", "q", false, "Suppress the build output and print image ID on success")
buildCommand.Flags().String("sbom", "", "Shorthand for \"--attest=type=sbom\"")
buildCommand.Flags().StringArray("cache-from", nil, "External cache sources (eg. user/app:cache, type=local,src=path/to/dir)")
buildCommand.Flags().StringArray("cache-to", nil, "Cache export destinations (eg. user/app:cache, type=local,dest=path/to/dir)")
buildCommand.Flags().Bool("rm", true, "Remove intermediate containers after a successful build")
buildCommand.Flags().String("network", "default", "Set type of network for build (format:network=default|none|host)")
buildCommand.RegisterFlagCompletionFunc("network", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
cmd.Flags().StringArray("attest", nil, "Attestation parameters (format: \"type=sbom,generator=image\")")
cmd.Flags().StringArray("ssh", nil, "SSH agent socket or keys to expose to the build (format: default|<id>[=<socket>|<key>[,<key>]])")
cmd.Flags().BoolP("quiet", "q", false, "Suppress the build output and print image ID on success")
cmd.Flags().String("sbom", "", "Shorthand for \"--attest=type=sbom\"")
cmd.Flags().StringArray("cache-from", nil, "External cache sources (eg. user/app:cache, type=local,src=path/to/dir)")
cmd.Flags().StringArray("cache-to", nil, "Cache export destinations (eg. user/app:cache, type=local,dest=path/to/dir)")
cmd.Flags().Bool("rm", true, "Remove intermediate containers after a successful build")
cmd.Flags().String("network", "default", "Set type of network for build (format:network=default|none|host)")
cmd.RegisterFlagCompletionFunc("network", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return []string{"default", "host", "none"}, cobra.ShellCompDirectiveNoFileComp
})
// #region platform flags
// platform is defined as StringSlice, not StringArray, to allow specifying "--platform=amd64,arm64"
buildCommand.Flags().StringSlice("platform", []string{}, "Set target platform for build (e.g., \"amd64\", \"arm64\")")
buildCommand.RegisterFlagCompletionFunc("platform", completion.Platforms)
buildCommand.Flags().StringArray("build-context", []string{}, "Additional build contexts (e.g., name=path)")
cmd.Flags().StringSlice("platform", []string{}, "Set target platform for build (e.g., \"amd64\", \"arm64\")")
cmd.RegisterFlagCompletionFunc("platform", completion.Platforms)
cmd.Flags().StringArray("build-context", []string{}, "Additional build contexts (e.g., name=path)")
// #endregion

buildCommand.Flags().String("iidfile", "", "Write the image ID to the file")
buildCommand.Flags().StringArray("label", nil, "Set metadata for an image")
cmd.Flags().String("iidfile", "", "Write the image ID to the file")
cmd.Flags().StringArray("label", nil, "Set metadata for an image")

return buildCommand
return cmd
}

func processBuildCommandFlag(cmd *cobra.Command, args []string) (types.BuilderBuildOptions, error) {
Expand Down
18 changes: 9 additions & 9 deletions cmd/nerdctl/compose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
)

func NewComposeCommand() *cobra.Command {
var composeCommand = &cobra.Command{
var cmd = &cobra.Command{
Use: "compose [flags] COMMAND",
Short: "Compose",
RunE: helpers.UnknownSubcommandAction,
Expand All @@ -33,14 +33,14 @@ func NewComposeCommand() *cobra.Command {
TraverseChildren: true, // required for global short hands like -f
}
// `-f` is a nonPersistentAlias, as it conflicts with `nerdctl compose logs --follow`
helpers.AddPersistentStringArrayFlag(composeCommand, "file", nil, []string{"f"}, nil, "", "Specify an alternate compose file")
composeCommand.PersistentFlags().String("project-directory", "", "Specify an alternate working directory")
composeCommand.PersistentFlags().StringP("project-name", "p", "", "Specify an alternate project name")
composeCommand.PersistentFlags().String("env-file", "", "Specify an alternate environment file")
composeCommand.PersistentFlags().String("ipfs-address", "", "multiaddr of IPFS API (default uses $IPFS_PATH env variable if defined or local directory ~/.ipfs)")
composeCommand.PersistentFlags().StringArray("profile", []string{}, "Specify a profile to enable")
helpers.AddPersistentStringArrayFlag(cmd, "file", nil, []string{"f"}, nil, "", "Specify an alternate compose file")
cmd.PersistentFlags().String("project-directory", "", "Specify an alternate working directory")
cmd.PersistentFlags().StringP("project-name", "p", "", "Specify an alternate project name")
cmd.PersistentFlags().String("env-file", "", "Specify an alternate environment file")
cmd.PersistentFlags().String("ipfs-address", "", "multiaddr of IPFS API (default uses $IPFS_PATH env variable if defined or local directory ~/.ipfs)")
cmd.PersistentFlags().StringArray("profile", []string{}, "Specify a profile to enable")

composeCommand.AddCommand(
cmd.AddCommand(
newComposeUpCommand(),
newComposeLogsCommand(),
newComposeConfigCommand(),
Expand All @@ -66,7 +66,7 @@ func NewComposeCommand() *cobra.Command {
newComposeCreateCommand(),
)

return composeCommand
return cmd
}

func getComposeOptions(cmd *cobra.Command, debugFull, experimental bool) (composer.Options, error) {
Expand Down
10 changes: 5 additions & 5 deletions cmd/nerdctl/compose/compose_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ import (
)

func newComposeBuildCommand() *cobra.Command {
var composeBuildCommand = &cobra.Command{
var cmd = &cobra.Command{
Use: "build [flags] [SERVICE...]",
Short: "Build or rebuild services",
RunE: composeBuildAction,
SilenceUsage: true,
SilenceErrors: true,
}
composeBuildCommand.Flags().StringArray("build-arg", nil, "Set build-time variables for services.")
composeBuildCommand.Flags().Bool("no-cache", false, "Do not use cache when building the image.")
composeBuildCommand.Flags().String("progress", "", "Set type of progress output (auto, plain, tty). Use plain to show container output")
cmd.Flags().StringArray("build-arg", nil, "Set build-time variables for services.")
cmd.Flags().Bool("no-cache", false, "Do not use cache when building the image.")
cmd.Flags().String("progress", "", "Set type of progress output (auto, plain, tty). Use plain to show container output")

return composeBuildCommand
return cmd
}

func composeBuildAction(cmd *cobra.Command, args []string) error {
Expand Down
14 changes: 7 additions & 7 deletions cmd/nerdctl/compose/compose_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ import (
)

func newComposeConfigCommand() *cobra.Command {
var composeConfigCommand = &cobra.Command{
var cmd = &cobra.Command{
Use: "config",
Short: "Validate and view the Compose file",
RunE: composeConfigAction,
SilenceUsage: true,
SilenceErrors: true,
}
composeConfigCommand.Flags().BoolP("quiet", "q", false, "Only validate the configuration, don't print anything.")
composeConfigCommand.Flags().Bool("services", false, "Print the service names, one per line.")
composeConfigCommand.Flags().Bool("volumes", false, "Print the volume names, one per line.")
composeConfigCommand.Flags().String("hash", "", "Print the service config hash, one per line.")
composeConfigCommand.RegisterFlagCompletionFunc("hash", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
cmd.Flags().BoolP("quiet", "q", false, "Only validate the configuration, don't print anything.")
cmd.Flags().Bool("services", false, "Print the service names, one per line.")
cmd.Flags().Bool("volumes", false, "Print the volume names, one per line.")
cmd.Flags().String("hash", "", "Print the service config hash, one per line.")
cmd.RegisterFlagCompletionFunc("hash", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return []string{"\"*\""}, cobra.ShellCompDirectiveNoFileComp
})
return composeConfigCommand
return cmd
}

func composeConfigAction(cmd *cobra.Command, args []string) error {
Expand Down
10 changes: 5 additions & 5 deletions cmd/nerdctl/compose/compose_cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ import (
func newComposeCopyCommand() *cobra.Command {
usage := `cp [OPTIONS] SERVICE:SRC_PATH DEST_PATH|-
nerdctl compose cp [OPTIONS] SRC_PATH|- SERVICE:DEST_PATH`
var composeCpCommand = &cobra.Command{
var cmd = &cobra.Command{
Use: usage,
Short: "Copy files/folders between a service container and the local filesystem",
Args: cobra.ExactArgs(2),
RunE: composeCopyAction,
SilenceUsage: true,
SilenceErrors: true,
}
composeCpCommand.Flags().Bool("dry-run", false, "Execute command in dry run mode")
composeCpCommand.Flags().BoolP("follow-link", "L", false, "Always follow symbol link in SRC_PATH")
composeCpCommand.Flags().Int("index", 0, "index of the container if service has multiple replicas")
return composeCpCommand
cmd.Flags().Bool("dry-run", false, "Execute command in dry run mode")
cmd.Flags().BoolP("follow-link", "L", false, "Always follow symbol link in SRC_PATH")
cmd.Flags().Int("index", 0, "index of the container if service has multiple replicas")
return cmd
}

func composeCopyAction(cmd *cobra.Command, args []string) error {
Expand Down
14 changes: 7 additions & 7 deletions cmd/nerdctl/compose/compose_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ import (
)

func newComposeCreateCommand() *cobra.Command {
var composeCreateCommand = &cobra.Command{
var cmd = &cobra.Command{
Use: "create [flags] [SERVICE...]",
Short: "Creates containers for one or more services",
RunE: composeCreateAction,
SilenceUsage: true,
SilenceErrors: true,
}
composeCreateCommand.Flags().Bool("build", false, "Build images before starting containers.")
composeCreateCommand.Flags().Bool("no-build", false, "Don't build an image even if it's missing, conflict with --build.")
composeCreateCommand.Flags().Bool("force-recreate", false, "Recreate containers even if their configuration and image haven't changed.")
composeCreateCommand.Flags().Bool("no-recreate", false, "Don't recreate containers if they exist, conflict with --force-recreate.")
composeCreateCommand.Flags().String("pull", "missing", "Pull images before running. (support always|missing|never)")
return composeCreateCommand
cmd.Flags().Bool("build", false, "Build images before starting containers.")
cmd.Flags().Bool("no-build", false, "Don't build an image even if it's missing, conflict with --build.")
cmd.Flags().Bool("force-recreate", false, "Recreate containers even if their configuration and image haven't changed.")
cmd.Flags().Bool("no-recreate", false, "Don't recreate containers if they exist, conflict with --force-recreate.")
cmd.Flags().String("pull", "missing", "Pull images before running. (support always|missing|never)")
return cmd
}

func composeCreateAction(cmd *cobra.Command, args []string) error {
Expand Down
8 changes: 4 additions & 4 deletions cmd/nerdctl/compose/compose_down.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ import (
)

func newComposeDownCommand() *cobra.Command {
var composeDownCommand = &cobra.Command{
var cmd = &cobra.Command{
Use: "down",
Short: "Remove containers and associated resources",
Args: cobra.NoArgs,
RunE: composeDownAction,
SilenceUsage: true,
SilenceErrors: true,
}
composeDownCommand.Flags().BoolP("volumes", "v", false, "Remove named volumes declared in the `volumes` section of the Compose file and anonymous volumes attached to containers.")
composeDownCommand.Flags().Bool("remove-orphans", false, "Remove containers for services not defined in the Compose file.")
return composeDownCommand
cmd.Flags().BoolP("volumes", "v", false, "Remove named volumes declared in the `volumes` section of the Compose file and anonymous volumes attached to containers.")
cmd.Flags().Bool("remove-orphans", false, "Remove containers for services not defined in the Compose file.")
return cmd
}

func composeDownAction(cmd *cobra.Command, args []string) error {
Expand Down
Loading
Loading