From 4ce6e50e2e1b4c761235916a6d1b9f186127cc0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Mon, 8 Jul 2024 14:40:51 +0200 Subject: [PATCH 1/3] push: Don't default to DOCKER_DEFAULT_PLATFORM MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Paweł Gronowski --- cli/command/image/push.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cli/command/image/push.go b/cli/command/image/push.go index 6abacbf71d..4460dda70f 100644 --- a/cli/command/image/push.go +++ b/cli/command/image/push.go @@ -8,7 +8,6 @@ import ( "encoding/json" "fmt" "io" - "os" "github.com/containerd/platforms" "github.com/distribution/reference" @@ -58,7 +57,11 @@ func NewPushCommand(dockerCli command.Cli) *cobra.Command { flags.BoolVarP(&opts.all, "all-tags", "a", false, "Push all tags of an image to the repository") flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Suppress verbose output") command.AddTrustSigningFlags(flags, &opts.untrusted, dockerCli.ContentTrustEnabled()) - flags.StringVar(&opts.platform, "platform", os.Getenv("DOCKER_DEFAULT_PLATFORM"), + + // Don't default to DOCKER_DEFAULT_PLATFORM env variable, always default to + // pushing the image as-is. This also avoids forcing the platform selection + // on older APIs which don't support it. + flags.StringVar(&opts.platform, "platform", "", `Push a platform-specific manifest as a single-platform image to the registry. 'os[/arch[/variant]]': Explicit platform (eg. linux/amd64)`) flags.SetAnnotation("platform", "version", []string{"1.46"}) From d40199440d7730f4974348aec89a475bcd584f26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Mon, 8 Jul 2024 14:20:10 +0200 Subject: [PATCH 2/3] c8d: Remove `docker convert` mention MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It's not merged yet. Signed-off-by: Paweł Gronowski --- cli/command/image/push.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/command/image/push.go b/cli/command/image/push.go index 4460dda70f..51c4a34528 100644 --- a/cli/command/image/push.go +++ b/cli/command/image/push.go @@ -84,7 +84,7 @@ func RunPush(ctx context.Context, dockerCli command.Cli, opts pushOptions) error printNote(dockerCli, `Selecting a single platform will only push one matching image manifest from a multi-platform image index. This means that any other components attached to the multi-platform image index (like Buildkit attestations) won't be pushed. -If you want to only push a single platform image while preserving the attestations, please use 'docker convert\n' +If you want to push a whole multi-platform image, make sure all image content is present and remove the --platform flag. `) } From 6c04adc05ebd479718207fe0d62d5a9cfdc93d46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Tue, 9 Jul 2024 15:35:36 +0200 Subject: [PATCH 3/3] push: Improve note message and colors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Paweł Gronowski --- cli/command/image/push.go | 29 ++++++++++++++++++------ docs/reference/commandline/image_push.md | 12 +++++----- docs/reference/commandline/push.md | 12 +++++----- 3 files changed, 34 insertions(+), 19 deletions(-) diff --git a/cli/command/image/push.go b/cli/command/image/push.go index 51c4a34528..d28fd93e7a 100644 --- a/cli/command/image/push.go +++ b/cli/command/image/push.go @@ -8,6 +8,7 @@ import ( "encoding/json" "fmt" "io" + "strings" "github.com/containerd/platforms" "github.com/distribution/reference" @@ -63,6 +64,7 @@ func NewPushCommand(dockerCli command.Cli) *cobra.Command { // on older APIs which don't support it. flags.StringVar(&opts.platform, "platform", "", `Push a platform-specific manifest as a single-platform image to the registry. +Image index won't be pushed, meaning that other manifests, including attestations won't be preserved. 'os[/arch[/variant]]': Explicit platform (eg. linux/amd64)`) flags.SetAnnotation("platform", "version", []string{"1.46"}) @@ -82,9 +84,9 @@ func RunPush(ctx context.Context, dockerCli command.Cli, opts pushOptions) error } platform = &p - printNote(dockerCli, `Selecting a single platform will only push one matching image manifest from a multi-platform image index. -This means that any other components attached to the multi-platform image index (like Buildkit attestations) won't be pushed. -If you want to push a whole multi-platform image, make sure all image content is present and remove the --platform flag. + printNote(dockerCli, `Using --platform pushes only the specified platform manifest of a multi-platform image index. +Other components, like attestations, will not be included. +To push the complete multi-platform image, remove the --platform flag. `) } @@ -182,9 +184,22 @@ func handleAux(dockerCli command.Cli) func(jm jsonmessage.JSONMessage) { func printNote(dockerCli command.Cli, format string, args ...any) { if dockerCli.Err().IsTerminal() { - _, _ = fmt.Fprint(dockerCli.Err(), aec.WhiteF.Apply(aec.CyanB.Apply("[ NOTE ]"))+" ") - } else { - _, _ = fmt.Fprint(dockerCli.Err(), "[ NOTE ] ") + format = strings.ReplaceAll(format, "--platform", aec.Bold.Apply("--platform")) + } + + header := " Info -> " + padding := len(header) + if dockerCli.Err().IsTerminal() { + padding = len("i Info > ") + header = aec.Bold.Apply(aec.LightCyanB.Apply(aec.BlackF.Apply("i")) + " " + aec.LightCyanF.Apply("Info → ")) + } + + _, _ = fmt.Fprint(dockerCli.Err(), header) + s := fmt.Sprintf(format, args...) + for idx, line := range strings.Split(s, "\n") { + if idx > 0 { + _, _ = fmt.Fprint(dockerCli.Err(), strings.Repeat(" ", padding)) + } + _, _ = fmt.Fprintln(dockerCli.Err(), aec.Italic.Apply(line)) } - _, _ = fmt.Fprintf(dockerCli.Err(), aec.Bold.Apply(format)+"\n", args...) } diff --git a/docs/reference/commandline/image_push.md b/docs/reference/commandline/image_push.md index d58282a1ac..91f6a41be1 100644 --- a/docs/reference/commandline/image_push.md +++ b/docs/reference/commandline/image_push.md @@ -9,12 +9,12 @@ Upload an image to a registry ### Options -| Name | Type | Default | Description | -|:---------------------------------------------|:---------|:--------|:--------------------------------------------------------------------------------------------------------------------------------------------| -| [`-a`](#all-tags), [`--all-tags`](#all-tags) | `bool` | | Push all tags of an image to the repository | -| `--disable-content-trust` | `bool` | `true` | Skip image signing | -| `--platform` | `string` | | Push a platform-specific manifest as a single-platform image to the registry.
'os[/arch[/variant]]': Explicit platform (eg. linux/amd64) | -| `-q`, `--quiet` | `bool` | | Suppress verbose output | +| Name | Type | Default | Description | +|:---------------------------------------------|:---------|:--------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| [`-a`](#all-tags), [`--all-tags`](#all-tags) | `bool` | | Push all tags of an image to the repository | +| `--disable-content-trust` | `bool` | `true` | Skip image signing | +| `--platform` | `string` | | Push a platform-specific manifest as a single-platform image to the registry.
Image index won't be pushed, meaning that other manifests, including attestations won't be preserved.
'os[/arch[/variant]]': Explicit platform (eg. linux/amd64) | +| `-q`, `--quiet` | `bool` | | Suppress verbose output | diff --git a/docs/reference/commandline/push.md b/docs/reference/commandline/push.md index 2d8358d6ff..9558d38e5e 100644 --- a/docs/reference/commandline/push.md +++ b/docs/reference/commandline/push.md @@ -9,12 +9,12 @@ Upload an image to a registry ### Options -| Name | Type | Default | Description | -|:--------------------------|:---------|:--------|:--------------------------------------------------------------------------------------------------------------------------------------------| -| `-a`, `--all-tags` | `bool` | | Push all tags of an image to the repository | -| `--disable-content-trust` | `bool` | `true` | Skip image signing | -| `--platform` | `string` | | Push a platform-specific manifest as a single-platform image to the registry.
'os[/arch[/variant]]': Explicit platform (eg. linux/amd64) | -| `-q`, `--quiet` | `bool` | | Suppress verbose output | +| Name | Type | Default | Description | +|:--------------------------|:---------|:--------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `-a`, `--all-tags` | `bool` | | Push all tags of an image to the repository | +| `--disable-content-trust` | `bool` | `true` | Skip image signing | +| `--platform` | `string` | | Push a platform-specific manifest as a single-platform image to the registry.
Image index won't be pushed, meaning that other manifests, including attestations won't be preserved.
'os[/arch[/variant]]': Explicit platform (eg. linux/amd64) | +| `-q`, `--quiet` | `bool` | | Suppress verbose output |