Skip to content
Open
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
4 changes: 4 additions & 0 deletions build/opt.go
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,10 @@ func CreateExports(entries []*buildflags.ExportEntry) ([]client.ExportEntry, []s
case "registry":
out.Type = client.ExporterImage
out.Attrs["push"] = "true"
// Skip unpacking when only pushing to registry (unless explicitly set)
if _, ok := out.Attrs["unpack"]; !ok {
out.Attrs["unpack"] = "false"
}
}

if supportDir {
Expand Down
75 changes: 75 additions & 0 deletions build/opt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,78 @@ func TestCacheOptions_DerivedVars(t *testing.T) {
},
}, CreateCaches(cacheFrom))
}

func TestCreateExports_RegistryUnpack(t *testing.T) {
tests := []struct {
name string
entries []*buildflags.ExportEntry
wantType string
wantPush string
wantUnpack string
}{
{
name: "registry type sets unpack=false",
entries: []*buildflags.ExportEntry{
{
Type: "registry",
Attrs: map[string]string{},
},
},
wantType: "image",
wantPush: "true",
wantUnpack: "false",
},
{
name: "registry type respects explicit unpack=true",
entries: []*buildflags.ExportEntry{
{
Type: "registry",
Attrs: map[string]string{
"unpack": "true",
},
},
},
wantType: "image",
wantPush: "true",
wantUnpack: "true",
},
{
name: "registry type respects explicit unpack=false",
entries: []*buildflags.ExportEntry{
{
Type: "registry",
Attrs: map[string]string{
"unpack": "false",
},
},
},
wantType: "image",
wantPush: "true",
wantUnpack: "false",
},
{
name: "image type without push does not set unpack",
entries: []*buildflags.ExportEntry{
{
Type: "image",
Attrs: map[string]string{},
},
},
wantType: "image",
wantPush: "",
wantUnpack: "",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
exports, _, err := CreateExports(tt.entries)
require.NoError(t, err)
require.Len(t, exports, 1)

require.Equal(t, tt.wantType, exports[0].Type)
require.Equal(t, tt.wantPush, exports[0].Attrs["push"])
require.Equal(t, tt.wantUnpack, exports[0].Attrs["unpack"])
})
}
}
17 changes: 12 additions & 5 deletions commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ func buildCmd(dockerCli command.Cli, rootOpts *rootOptions, debugger debuggerOpt

flags.StringArrayVar(&options.platforms, "platform", platformsDefault, "Set target platform for build")

flags.BoolVar(&options.exportPush, "push", false, `Shorthand for "--output=type=registry"`)
flags.BoolVar(&options.exportPush, "push", false, `Shorthand for "--output=type=registry,unpack=false"`)

flags.BoolVarP(&options.quiet, "quiet", "q", false, "Suppress the build output and print image ID on success")

Expand Down Expand Up @@ -1047,15 +1047,22 @@ func RunBuild(ctx context.Context, dockerCli command.Cli, in *BuildOptions, inSt
for i := range outputs {
if outputs[i].Type == client.ExporterImage {
outputs[i].Attrs["push"] = "true"
// Skip unpacking when only pushing to registry (unless explicitly set)
if _, ok := outputs[i].Attrs["unpack"]; !ok {
outputs[i].Attrs["unpack"] = "false"
}
pushUsed = true
}
}
if !pushUsed {
attrs := map[string]string{
"push": "true",
}
// Skip unpacking when only pushing to registry
attrs["unpack"] = "false"
outputs = append(outputs, client.ExportEntry{
Type: client.ExporterImage,
Attrs: map[string]string{
"push": "true",
},
Type: client.ExporterImage,
Attrs: attrs,
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/buildx_build.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Start a build
| [`--progress`](#progress) | `string` | `auto` | Set type of progress output (`auto`, `none`, `plain`, `quiet`, `rawjson`, `tty`). Use plain to show container output |
| [`--provenance`](#provenance) | `string` | | Shorthand for `--attest=type=provenance` |
| `--pull` | `bool` | | Always attempt to pull all referenced images |
| [`--push`](#push) | `bool` | | Shorthand for `--output=type=registry` |
| [`--push`](#push) | `bool` | | Shorthand for `--output=type=registry,unpack=false` |
| `-q`, `--quiet` | `bool` | | Suppress the build output and print image ID on success |
| [`--sbom`](#sbom) | `string` | | Shorthand for `--attest=type=sbom` |
| [`--secret`](#secret) | `stringArray` | | Secret to expose to the build (format: `id=mysecret[,src=/local/secret]`) |
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/buildx_dap_build.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Start a build
| `--progress` | `string` | `auto` | Set type of progress output (`auto`, `none`, `plain`, `quiet`, `rawjson`, `tty`). Use plain to show container output |
| `--provenance` | `string` | | Shorthand for `--attest=type=provenance` |
| `--pull` | `bool` | | Always attempt to pull all referenced images |
| `--push` | `bool` | | Shorthand for `--output=type=registry` |
| `--push` | `bool` | | Shorthand for `--output=type=registry,unpack=false` |
| `-q`, `--quiet` | `bool` | | Suppress the build output and print image ID on success |
| `--sbom` | `string` | | Shorthand for `--attest=type=sbom` |
| `--secret` | `stringArray` | | Secret to expose to the build (format: `id=mysecret[,src=/local/secret]`) |
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/buildx_debug_build.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Start a build
| `--progress` | `string` | `auto` | Set type of progress output (`auto`, `none`, `plain`, `quiet`, `rawjson`, `tty`). Use plain to show container output |
| `--provenance` | `string` | | Shorthand for `--attest=type=provenance` |
| `--pull` | `bool` | | Always attempt to pull all referenced images |
| `--push` | `bool` | | Shorthand for `--output=type=registry` |
| `--push` | `bool` | | Shorthand for `--output=type=registry,unpack=false` |
| `-q`, `--quiet` | `bool` | | Suppress the build output and print image ID on success |
| `--sbom` | `string` | | Shorthand for `--attest=type=sbom` |
| `--secret` | `stringArray` | | Secret to expose to the build (format: `id=mysecret[,src=/local/secret]`) |
Expand Down