Skip to content
Draft
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
6 changes: 6 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,9 @@ require (
sigs.k8s.io/yaml v1.6.0 // indirect
tags.cncf.io/container-device-interface/specs-go v1.1.0 // indirect
)

replace go.podman.io/common => github.com/TrevorBurnham/container-libs/common v0.0.0-20260225192346-ebad6b016844

replace go.podman.io/image/v5 => github.com/TrevorBurnham/container-libs/image/v5 v5.0.0-20260225192346-ebad6b016844

replace go.podman.io/storage => github.com/TrevorBurnham/container-libs/storage v0.0.0-20260225192346-ebad6b016844
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ github.com/Masterminds/semver/v3 v3.4.0 h1:Zog+i5UMtVoCU8oKka5P7i9q9HgrJeGzI9SA1
github.com/Masterminds/semver/v3 v3.4.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
github.com/TrevorBurnham/container-libs/common v0.0.0-20260225192346-ebad6b016844 h1:QmZVSHJsbBqCfkPoW1yVQ2tWCb3MEGXPGaBBaGqGNmM=
github.com/TrevorBurnham/container-libs/common v0.0.0-20260225192346-ebad6b016844/go.mod h1:0DeDsVv70xdub5XMurYkseMEwQQ2NdwtG1+Es24VzX4=
github.com/TrevorBurnham/container-libs/image/v5 v5.0.0-20260225192346-ebad6b016844 h1:wTuMtjFpbFLFhkxsrzLrfhvagYPcIssZFWJN3+LRGic=
github.com/TrevorBurnham/container-libs/image/v5 v5.0.0-20260225192346-ebad6b016844/go.mod h1:aOKcsA9y3xfvAW5jGk8evBoQyJGJzhOIrXjwc4iRXcw=
github.com/TrevorBurnham/container-libs/storage v0.0.0-20260225192346-ebad6b016844 h1:bYgfHmfH4oQ3K/jKtbLeicAQBASMhEyjRBPFJRXVZV0=
github.com/TrevorBurnham/container-libs/storage v0.0.0-20260225192346-ebad6b016844/go.mod h1:B83Ad8mtO0GZs7rEwb66f0Ed5G57NyKI/iJZHoJrpUE=
github.com/VividCortex/ewma v1.2.0 h1:f58SaIzcDXrSy3kWaHNvuJgJ3Nmz59Zji6XoJR/q1ow=
github.com/VividCortex/ewma v1.2.0/go.mod h1:nz4BbCtbLyFDeC9SUHbtcT5644juEuWfUAUnGx7j5l4=
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d h1:licZJFw2RwpHMqeKTCYkitsPqHNxTmd4SNR5r94FGM8=
Expand Down
35 changes: 35 additions & 0 deletions pkg/parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,20 @@ func SystemContextFromFlagSet(flags *pflag.FlagSet, findFlagFunc func(name strin
ctx.VariantChoice = variant
}

// If no platform-related flags were explicitly set, fall back to the
// default platform from containers.conf [engine] platform.
if ctx.OSChoice == "" && ctx.ArchitectureChoice == "" && ctx.VariantChoice == "" {
if defaultPlatform, err := defaultPlatformFromConfig(); err == nil && defaultPlatform != "" {
os, arch, variant, err := Platform(defaultPlatform)
if err != nil {
return nil, fmt.Errorf("parsing containers.conf platform %q: %w", defaultPlatform, err)
}
ctx.OSChoice = os
ctx.ArchitectureChoice = arch
ctx.VariantChoice = variant
}
}

ctx.BigFilesTemporaryDir = GetTempDir()
return ctx, nil
}
Expand Down Expand Up @@ -671,6 +685,17 @@ func PlatformsFromOptions(c *cobra.Command) (platforms []struct{ OS, Arch, Varia
platforms = append(platforms, struct{ OS, Arch, Variant string }{os, arch, variant})
}
}
// If no platform-related flags were explicitly set, fall back to the
// default platform from containers.conf [engine] platform.
if len(platforms) == 1 && platforms[0].OS == "" && platforms[0].Arch == "" && platforms[0].Variant == "" {
if defaultPlatform, err := defaultPlatformFromConfig(); err == nil && defaultPlatform != "" {
os, arch, variant, err := Platform(defaultPlatform)
if err != nil {
return nil, fmt.Errorf("parsing containers.conf platform %q: %w", defaultPlatform, err)
}
platforms = []struct{ OS, Arch, Variant string }{{os, arch, variant}}
}
}
return platforms, nil
}

Expand All @@ -679,6 +704,16 @@ func DefaultPlatform() string {
return platforms.DefaultString()
}

// defaultPlatformFromConfig returns the default platform from
// containers.conf [engine] platform, if set.
func defaultPlatformFromConfig() (string, error) {
cfg, err := config.Default()
if err != nil {
return "", err
}
return cfg.Engine.Platform, nil
}

// Platform separates the platform string into os, arch and variant,
// accepting any of $arch, $os/$arch, or $os/$arch/$variant.
func Platform(platform string) (os, arch, variant string, err error) {
Expand Down
28 changes: 28 additions & 0 deletions tests/containers_conf.bats
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,31 @@ EOF
expect_output --substring "retry.*\(default 10\)"
expect_output --substring "retry-delay.*\(default \"5s\"\)"
}


@test "containers.conf engine.platform" {
cat >${TEST_SCRATCH_DIR}/containers.conf << EOF
[engine]
platform = "linux/arm64"
EOF
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of our tests run on amd64, so I'm not sure that this ensures that we're using the value from the configuration file.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. I've switched to linux/arm64 so the test actually verifies that the config is being used.

local context="$TEST_SCRATCH_DIR"/context
mkdir -p "$context"
cat > "$context"/Containerfile << _EOF
FROM scratch
COPY . .
_EOF

# Build with the custom containers.conf and push to an OCI layout
CONTAINERS_CONF=${TEST_SCRATCH_DIR}/containers.conf run_buildah build \
$WITH_POLICY_JSON -t localhost/testplatform \
-f "$context"/Containerfile "$context"
CONTAINERS_CONF=${TEST_SCRATCH_DIR}/containers.conf run_buildah push \
$WITH_POLICY_JSON localhost/testplatform oci:"$TEST_SCRATCH_DIR"/output

# Verify the image platform matches what we set in containers.conf
local config="$TEST_SCRATCH_DIR"/output/$(oci_image_config "$TEST_SCRATCH_DIR"/output)
run jq -r '.os' "$config"
assert "$output" = "linux" "os should be linux"
run jq -r '.architecture' "$config"
assert "$output" = "arm64" "architecture should be arm64"
}
6 changes: 6 additions & 0 deletions vendor/go.podman.io/common/pkg/config/config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions vendor/go.podman.io/common/pkg/config/containers.conf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions vendor/go.podman.io/common/pkg/config/containers.conf-freebsd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 9 additions & 6 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,8 @@ go.opentelemetry.io/otel/trace
go.opentelemetry.io/otel/trace/embedded
go.opentelemetry.io/otel/trace/internal/telemetry
go.opentelemetry.io/otel/trace/noop
# go.podman.io/common v0.67.1-0.20260325203629-8af78737e8bb
## explicit; go 1.25.6
# go.podman.io/common v0.67.1-0.20260325203629-8af78737e8bb => github.com/TrevorBurnham/container-libs/common v0.0.0-20260225192346-ebad6b016844
## explicit; go 1.24.6
go.podman.io/common/internal
go.podman.io/common/libimage
go.podman.io/common/libimage/define
Expand Down Expand Up @@ -505,8 +505,8 @@ go.podman.io/common/pkg/umask
go.podman.io/common/pkg/util
go.podman.io/common/pkg/version
go.podman.io/common/version
# go.podman.io/image/v5 v5.39.2-0.20260325203629-8af78737e8bb
## explicit; go 1.25.6
# go.podman.io/image/v5 v5.39.2-0.20260325203629-8af78737e8bb => github.com/TrevorBurnham/container-libs/image/v5 v5.0.0-20260225192346-ebad6b016844
## explicit; go 1.24.6
go.podman.io/image/v5/copy
go.podman.io/image/v5/directory
go.podman.io/image/v5/directory/explicitfilepath
Expand Down Expand Up @@ -574,8 +574,8 @@ go.podman.io/image/v5/transports
go.podman.io/image/v5/transports/alltransports
go.podman.io/image/v5/types
go.podman.io/image/v5/version
# go.podman.io/storage v1.62.1-0.20260325203629-8af78737e8bb
## explicit; go 1.25.0
# go.podman.io/storage v1.62.1-0.20260325203629-8af78737e8bb => github.com/TrevorBurnham/container-libs/storage v0.0.0-20260225192346-ebad6b016844
## explicit; go 1.24.0
go.podman.io/storage
go.podman.io/storage/drivers
go.podman.io/storage/drivers/btrfs
Expand Down Expand Up @@ -821,3 +821,6 @@ tags.cncf.io/container-device-interface/pkg/parser
# tags.cncf.io/container-device-interface/specs-go v1.1.0
## explicit; go 1.19
tags.cncf.io/container-device-interface/specs-go
# go.podman.io/common => github.com/TrevorBurnham/container-libs/common v0.0.0-20260225192346-ebad6b016844
# go.podman.io/image/v5 => github.com/TrevorBurnham/container-libs/image/v5 v5.0.0-20260225192346-ebad6b016844
# go.podman.io/storage => github.com/TrevorBurnham/container-libs/storage v0.0.0-20260225192346-ebad6b016844