From 0939d159a89f8f3db237dfb082dbbea59f44b9e3 Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Tue, 3 Jan 2023 10:54:03 +0100 Subject: [PATCH] introduce `--ignore-buildable` to ignore buildable images on pull Signed-off-by: Nicolas De Loof --- cmd/compose/pull.go | 13 ++++++++----- docs/reference/compose_pull.md | 14 +++++++++----- docs/reference/docker_compose_pull.yaml | 19 ++++++++++++++++--- pkg/api/api.go | 5 +++-- pkg/compose/pull.go | 9 +++++++++ 5 files changed, 45 insertions(+), 15 deletions(-) diff --git a/cmd/compose/pull.go b/cmd/compose/pull.go index 136a7db875..1839039360 100644 --- a/cmd/compose/pull.go +++ b/cmd/compose/pull.go @@ -37,6 +37,7 @@ type pullOptions struct { noParallel bool includeDeps bool ignorePullFailures bool + noBuildable bool } func pullCommand(p *ProjectOptions, backend api.Service) *cobra.Command { @@ -58,13 +59,14 @@ func pullCommand(p *ProjectOptions, backend api.Service) *cobra.Command { ValidArgsFunction: completeServiceNames(p), } flags := cmd.Flags() - flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Pull without printing progress information") - cmd.Flags().BoolVar(&opts.includeDeps, "include-deps", false, "Also pull services declared as dependencies") + flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Pull without printing progress information.") + cmd.Flags().BoolVar(&opts.includeDeps, "include-deps", false, "Also pull services declared as dependencies.") cmd.Flags().BoolVar(&opts.parallel, "parallel", true, "DEPRECATED pull multiple images in parallel.") flags.MarkHidden("parallel") //nolint:errcheck cmd.Flags().BoolVar(&opts.parallel, "no-parallel", true, "DEPRECATED disable parallel pulling.") flags.MarkHidden("no-parallel") //nolint:errcheck - cmd.Flags().BoolVar(&opts.ignorePullFailures, "ignore-pull-failures", false, "Pull what it can and ignores images with pull failures") + cmd.Flags().BoolVar(&opts.ignorePullFailures, "ignore-pull-failures", false, "Pull what it can and ignores images with pull failures.") + cmd.Flags().BoolVar(&opts.noBuildable, "ignore-buildable", false, "Ignore images that can be built.") return cmd } @@ -97,7 +99,8 @@ func runPull(ctx context.Context, backend api.Service, opts pullOptions, service } return backend.Pull(ctx, project, api.PullOptions{ - Quiet: opts.quiet, - IgnoreFailures: opts.ignorePullFailures, + Quiet: opts.quiet, + IgnoreFailures: opts.ignorePullFailures, + IgnoreBuildable: opts.noBuildable, }) } diff --git a/docs/reference/compose_pull.md b/docs/reference/compose_pull.md index cd5f08e71c..cf3712f4d3 100644 --- a/docs/reference/compose_pull.md +++ b/docs/reference/compose_pull.md @@ -5,11 +5,12 @@ Pull service images ### Options -| Name | Type | Default | Description | -|:-------------------------|:-----|:--------|:-------------------------------------------------------| -| `--ignore-pull-failures` | | | Pull what it can and ignores images with pull failures | -| `--include-deps` | | | Also pull services declared as dependencies | -| `-q`, `--quiet` | | | Pull without printing progress information | +| Name | Type | Default | Description | +|:-------------------------|:-----|:--------|:--------------------------------------------------------| +| `--ignore-buildable` | | | Ignore images that can be built. | +| `--ignore-pull-failures` | | | Pull what it can and ignores images with pull failures. | +| `--include-deps` | | | Also pull services declared as dependencies. | +| `-q`, `--quiet` | | | Pull without printing progress information. | @@ -62,3 +63,6 @@ $ docker compose pull db ⠹ 77a0c198cde5 Waiting 9.3s ⠹ c8752d5b785c Waiting 9.3s ``` + +`docker compose pull` will try to pull image for services with a build section. If pull fails, it will let +user know this service image MUST be built. You can skip this by setting `--ignore-buildable` flag diff --git a/docs/reference/docker_compose_pull.yaml b/docs/reference/docker_compose_pull.yaml index a06e8387fe..c07afde137 100644 --- a/docs/reference/docker_compose_pull.yaml +++ b/docs/reference/docker_compose_pull.yaml @@ -7,10 +7,20 @@ usage: docker compose pull [OPTIONS] [SERVICE...] pname: docker compose plink: docker_compose.yaml options: + - option: ignore-buildable + value_type: bool + default_value: "false" + description: Ignore images that can be built. + deprecated: false + hidden: false + experimental: false + experimentalcli: false + kubernetes: false + swarm: false - option: ignore-pull-failures value_type: bool default_value: "false" - description: Pull what it can and ignores images with pull failures + description: Pull what it can and ignores images with pull failures. deprecated: false hidden: false experimental: false @@ -20,7 +30,7 @@ options: - option: include-deps value_type: bool default_value: "false" - description: Also pull services declared as dependencies + description: Also pull services declared as dependencies. deprecated: false hidden: false experimental: false @@ -51,7 +61,7 @@ options: shorthand: q value_type: bool default_value: "false" - description: Pull without printing progress information + description: Pull without printing progress information. deprecated: false hidden: false experimental: false @@ -99,6 +109,9 @@ examples: |- ⠹ 77a0c198cde5 Waiting 9.3s ⠹ c8752d5b785c Waiting 9.3s ``` + + `docker compose pull` will try to pull image for services with a build section. If pull fails, it will let + user know this service image MUST be built. You can skip this by setting `--ignore-buildable` flag deprecated: false experimental: false experimentalcli: false diff --git a/pkg/api/api.go b/pkg/api/api.go index 805c833cea..76bb6a478a 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -193,8 +193,9 @@ type PushOptions struct { // PullOptions group options of the Pull API type PullOptions struct { - Quiet bool - IgnoreFailures bool + Quiet bool + IgnoreFailures bool + IgnoreBuildable bool } // ImagesOptions group options of the Images API diff --git a/pkg/compose/pull.go b/pkg/compose/pull.go index be27479667..a2b1663c07 100644 --- a/pkg/compose/pull.go +++ b/pkg/compose/pull.go @@ -102,6 +102,15 @@ func (s *composeService) pull(ctx context.Context, project *types.Project, opts } } + if service.Build != nil && opts.IgnoreBuildable { + w.Event(progress.Event{ + ID: service.Name, + Status: progress.Done, + Text: "Skipped - Image can be built", + }) + continue + } + if s, ok := imagesBeingPulled[service.Image]; ok { w.Event(progress.Event{ ID: service.Name,