build: Don't unpack by default when pushing

Automatically set `unpack=false` for registry exports unless explicitly
overridden by the user.

This applies to:

- `registry` exporter type (converted to `image` exporter with `push=true`)
- `--push` flag usage with image exporters

Users can still explicitly set `unpack=true` if they need local image
storage alongside registry push.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
Paweł Gronowski
2026-01-14 16:04:45 +01:00
parent e33272c855
commit 41a1782b35
6 changed files with 89 additions and 4 deletions
+75
View File
@@ -81,3 +81,78 @@ func TestParseOCILayoutPath(t *testing.T) {
assert.Equal(t, tt.tag, tag, "comparing tag: %s", tt.s)
}
}
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"])
})
}
}