Skip to content

Commit 48cdd74

Browse files
committed
Fix source of OS, architecture and variant
This fixes getting of cpu variants for ARM64 Fixes the TestConformance/setuid-file-in-archive test on ARM64. Signed-off-by: Jan Rodák <[email protected]>
1 parent 7fea494 commit 48cdd74

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

config.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import (
66
"fmt"
77
"maps"
88
"os"
9-
"runtime"
109
"slices"
1110
"strings"
1211
"time"
1312

13+
"github.com/containerd/platforms"
1414
"github.com/containers/buildah/define"
1515
"github.com/containers/buildah/docker"
1616
internalUtil "github.com/containers/buildah/internal/util"
@@ -137,18 +137,19 @@ func (b *Builder) fixupConfig(sys *types.SystemContext) {
137137
if b.OCIv1.Created == nil || b.OCIv1.Created.IsZero() {
138138
b.OCIv1.Created = &now
139139
}
140+
currentPlatformSpecification := platforms.DefaultSpec()
140141
if b.OS() == "" {
141142
if sys != nil && sys.OSChoice != "" {
142143
b.SetOS(sys.OSChoice)
143144
} else {
144-
b.SetOS(runtime.GOOS)
145+
b.SetOS(currentPlatformSpecification.OS)
145146
}
146147
}
147148
if b.Architecture() == "" {
148149
if sys != nil && sys.ArchitectureChoice != "" {
149150
b.SetArchitecture(sys.ArchitectureChoice)
150151
} else {
151-
b.SetArchitecture(runtime.GOARCH)
152+
b.SetArchitecture(currentPlatformSpecification.Architecture)
152153
}
153154
// in case the arch string we started with was shorthand for a known arch+variant pair, normalize it
154155
ps := internalUtil.NormalizePlatform(ociv1.Platform{OS: b.OS(), Architecture: b.Architecture(), Variant: b.Variant()})
@@ -158,6 +159,8 @@ func (b *Builder) fixupConfig(sys *types.SystemContext) {
158159
if b.Variant() == "" {
159160
if sys != nil && sys.VariantChoice != "" {
160161
b.SetVariant(sys.VariantChoice)
162+
} else {
163+
b.SetVariant(currentPlatformSpecification.Variant)
161164
}
162165
// in case the arch string we started with was shorthand for a known arch+variant pair, normalize it
163166
ps := internalUtil.NormalizePlatform(ociv1.Platform{OS: b.OS(), Architecture: b.Architecture(), Variant: b.Variant()})

tests/conformance/conformance_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -2019,6 +2019,16 @@ var internalTestCases = []testCase{
20192019
compatScratchConfig: types.OptionalBoolTrue,
20202020
},
20212021

2022+
{
2023+
name: "from-scratch-simple-file", /* Fix On ARM64: fields missing from buildah version: variant */
2024+
dockerfileContents: strings.Join([]string{
2025+
"FROM scratch",
2026+
"COPY file-a.txt /",
2027+
}, "\n"),
2028+
contextDir: "dockerignore/populated",
2029+
compatScratchConfig: types.OptionalBoolTrue,
2030+
},
2031+
20222032
{
20232033
name: "setuid-file-in-archive",
20242034
dockerfileContents: strings.Join([]string{

0 commit comments

Comments
 (0)