From 1f0f5aa7c1bdeb2fa4f01eedfea6a2db0decee02 Mon Sep 17 00:00:00 2001 From: legobt <6wbvkn0j@anonaddy.me> Date: Tue, 30 Jul 2024 10:06:22 +0000 Subject: [PATCH] run: add support --no-build, --pull flags Allows setting build- and pull policies for `compose run` like for `docker run` and `compose up`. Signed-off-by: Petter Mikkelsen <6wbvkn0j@anonaddy.me> --- cmd/compose/run.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cmd/compose/run.go b/cmd/compose/run.go index b4a5da365fc..f0cb224d061 100644 --- a/cmd/compose/run.go +++ b/cmd/compose/run.go @@ -153,6 +153,13 @@ func runCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) * options.noTty = !options.tty } } + if cmd.Flags().Changed("build") { + if cmd.Flags().Changed("no-build") { + return fmt.Errorf("--build and --no-build are incompatible") + } else { + options.noTty = !options.tty + } + } return nil }), RunE: Adapt(func(ctx context.Context, args []string) error { @@ -189,6 +196,8 @@ func runCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) * flags.BoolVarP(&options.servicePorts, "service-ports", "P", false, "Run command with all service's ports enabled and mapped to the host") flags.BoolVar(&options.quietPull, "quiet-pull", false, "Pull without printing progress information") flags.BoolVar(&createOpts.Build, "build", false, "Build image before starting container") + flags.BoolVar(&createOpts.noBuild, "no-build", false, "Don't build an image, even if it's policy") + flags.StringVar(&createOpts.Pull, "pull", "policy", `Pull image before running ("always"|"missing"|"never")`) flags.BoolVar(&createOpts.removeOrphans, "remove-orphans", false, "Remove containers for services not defined in the Compose file") cmd.Flags().BoolVarP(&options.interactive, "interactive", "i", true, "Keep STDIN open even if not attached")