Skip to content

Commit ee2ecd0

Browse files
authored
Merge pull request #3519 from vvoland/push-nounpack
build: Don't unpack by default when pushing
2 parents e33272c + 41a1782 commit ee2ecd0

6 files changed

Lines changed: 89 additions & 4 deletions

File tree

build/opt.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,10 @@ func CreateExports(entries []*buildflags.ExportEntry) ([]client.ExportEntry, []s
831831
case "registry":
832832
out.Type = client.ExporterImage
833833
out.Attrs["push"] = "true"
834+
// Skip unpacking when only pushing to registry (unless explicitly set)
835+
if _, ok := out.Attrs["unpack"]; !ok {
836+
out.Attrs["unpack"] = "false"
837+
}
834838
}
835839

836840
if supportDir {

build/opt_test.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,78 @@ func TestParseOCILayoutPath(t *testing.T) {
8181
assert.Equal(t, tt.tag, tag, "comparing tag: %s", tt.s)
8282
}
8383
}
84+
85+
func TestCreateExports_RegistryUnpack(t *testing.T) {
86+
tests := []struct {
87+
name string
88+
entries []*buildflags.ExportEntry
89+
wantType string
90+
wantPush string
91+
wantUnpack string
92+
}{
93+
{
94+
name: "registry type sets unpack=false",
95+
entries: []*buildflags.ExportEntry{
96+
{
97+
Type: "registry",
98+
Attrs: map[string]string{},
99+
},
100+
},
101+
wantType: "image",
102+
wantPush: "true",
103+
wantUnpack: "false",
104+
},
105+
{
106+
name: "registry type respects explicit unpack=true",
107+
entries: []*buildflags.ExportEntry{
108+
{
109+
Type: "registry",
110+
Attrs: map[string]string{
111+
"unpack": "true",
112+
},
113+
},
114+
},
115+
wantType: "image",
116+
wantPush: "true",
117+
wantUnpack: "true",
118+
},
119+
{
120+
name: "registry type respects explicit unpack=false",
121+
entries: []*buildflags.ExportEntry{
122+
{
123+
Type: "registry",
124+
Attrs: map[string]string{
125+
"unpack": "false",
126+
},
127+
},
128+
},
129+
wantType: "image",
130+
wantPush: "true",
131+
wantUnpack: "false",
132+
},
133+
{
134+
name: "image type without push does not set unpack",
135+
entries: []*buildflags.ExportEntry{
136+
{
137+
Type: "image",
138+
Attrs: map[string]string{},
139+
},
140+
},
141+
wantType: "image",
142+
wantPush: "",
143+
wantUnpack: "",
144+
},
145+
}
146+
147+
for _, tt := range tests {
148+
t.Run(tt.name, func(t *testing.T) {
149+
exports, _, err := CreateExports(tt.entries)
150+
require.NoError(t, err)
151+
require.Len(t, exports, 1)
152+
153+
require.Equal(t, tt.wantType, exports[0].Type)
154+
require.Equal(t, tt.wantPush, exports[0].Attrs["push"])
155+
require.Equal(t, tt.wantUnpack, exports[0].Attrs["unpack"])
156+
})
157+
}
158+
}

commands/build.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ func buildCmd(dockerCli command.Cli, rootOpts *rootOptions, debugger debuggerOpt
542542

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

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

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

@@ -1048,6 +1048,10 @@ func RunBuild(ctx context.Context, dockerCli command.Cli, in *BuildOptions, inSt
10481048
for i := range outputs {
10491049
if outputs[i].Type == client.ExporterImage {
10501050
outputs[i].Attrs["push"] = "true"
1051+
// Skip unpacking when only pushing to registry (unless explicitly set)
1052+
if _, ok := outputs[i].Attrs["unpack"]; !ok {
1053+
outputs[i].Attrs["unpack"] = "false"
1054+
}
10511055
pushUsed = true
10521056
}
10531057
}
@@ -1056,6 +1060,8 @@ func RunBuild(ctx context.Context, dockerCli command.Cli, in *BuildOptions, inSt
10561060
Type: client.ExporterImage,
10571061
Attrs: map[string]string{
10581062
"push": "true",
1063+
// Skip unpacking when only pushing to registry
1064+
"unpack": "false",
10591065
},
10601066
})
10611067
}

docs/reference/buildx_build.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Start a build
4141
| [`--progress`](#progress) | `string` | `auto` | Set type of progress output (`auto`, `none`, `plain`, `quiet`, `rawjson`, `tty`). Use plain to show container output |
4242
| [`--provenance`](#provenance) | `string` | | Shorthand for `--attest=type=provenance` |
4343
| `--pull` | `bool` | | Always attempt to pull all referenced images |
44-
| [`--push`](#push) | `bool` | | Shorthand for `--output=type=registry` |
44+
| [`--push`](#push) | `bool` | | Shorthand for `--output=type=registry,unpack=false` |
4545
| `-q`, `--quiet` | `bool` | | Suppress the build output and print image ID on success |
4646
| [`--sbom`](#sbom) | `string` | | Shorthand for `--attest=type=sbom` |
4747
| [`--secret`](#secret) | `stringArray` | | Secret to expose to the build (format: `id=mysecret[,src=/local/secret]`) |

docs/reference/buildx_dap_build.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Start a build
3333
| `--progress` | `string` | `auto` | Set type of progress output (`auto`, `none`, `plain`, `quiet`, `rawjson`, `tty`). Use plain to show container output |
3434
| `--provenance` | `string` | | Shorthand for `--attest=type=provenance` |
3535
| `--pull` | `bool` | | Always attempt to pull all referenced images |
36-
| `--push` | `bool` | | Shorthand for `--output=type=registry` |
36+
| `--push` | `bool` | | Shorthand for `--output=type=registry,unpack=false` |
3737
| `-q`, `--quiet` | `bool` | | Suppress the build output and print image ID on success |
3838
| `--sbom` | `string` | | Shorthand for `--attest=type=sbom` |
3939
| `--secret` | `stringArray` | | Secret to expose to the build (format: `id=mysecret[,src=/local/secret]`) |

docs/reference/buildx_debug_build.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Start a build
3737
| `--progress` | `string` | `auto` | Set type of progress output (`auto`, `none`, `plain`, `quiet`, `rawjson`, `tty`). Use plain to show container output |
3838
| `--provenance` | `string` | | Shorthand for `--attest=type=provenance` |
3939
| `--pull` | `bool` | | Always attempt to pull all referenced images |
40-
| `--push` | `bool` | | Shorthand for `--output=type=registry` |
40+
| `--push` | `bool` | | Shorthand for `--output=type=registry,unpack=false` |
4141
| `-q`, `--quiet` | `bool` | | Suppress the build output and print image ID on success |
4242
| `--sbom` | `string` | | Shorthand for `--attest=type=sbom` |
4343
| `--secret` | `stringArray` | | Secret to expose to the build (format: `id=mysecret[,src=/local/secret]`) |

0 commit comments

Comments
 (0)