Skip to content

Fix image pull unpacking all platforms by default - #2378

Closed
CHE3MZ wants to merge 1 commit into
apple:mainfrom
CHE3MZ:fix/pull-host-only-unpack
Closed

CHE3MZ wants to merge 1 commit into
apple:mainfrom
CHE3MZ:fix/pull-host-only-unpack

Conversation

@CHE3MZ

@CHE3MZ CHE3MZ commented Oct 11, 2026 •

Copy link
Copy Markdown

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Motivation and Context

container image pull without --platform unpacks a snapshot for every architecture in the image index, while run unpacks only the requested platform via getCreateSnapshot (related: #784, #2165). Each snapshot is much smaller since containerization#924, but a multi-arch image still pays the per-architecture multiplier: alpine:latest creates a snapshot and repeats the unpack work for every platform in the index, although only one will run.

This change unpacks only the resolved platform. If --platform, --os, --arch, or CONTAINER_DEFAULT_PLATFORM is provided, that platform is used; otherwise the host platform is used. Blob fetching is unchanged, so images remain usable offline. --platform all restores the previous unpack-every-platform behavior, and other platforms are still unpacked on demand by run --platform.

Using the existing --platform option instead of a separate --all-platforms flag keeps one way to select platforms. --platform all is mutually exclusive with --os and --arch.

Testing

  • Added/updated tests (Tests/ContainerCommandsTests/ImagePullPlatformTests.swift): default host, explicit platform, environment default, all, case-insensitive all, and conflicting flags.
  • Added/updated docs (docs/command-reference.md).
  • Tested locally on macOS with the full runtime (not yet run by the author)
  • Community verification on an M-series Mac (macOS 27, main 31e3a98 + this PR): alpine:latest and postgres:18 each unpacked a single linux/arm64 snapshot, and containers started and ran normally.

Functional testing compares snapshot counts, since containerization#924 already reduced allocated bytes per snapshot. The remaining win is one snapshot and one unpack pass instead of one per architecture.

@lucasbrito-wdt

Copy link
Copy Markdown
Contributor

Tested ef55fd7 on an M-series Mac (macOS 27), built from main 31e3a98 with this PR merged (plus #2380, which doesn't touch pull), using a fresh --app-root and without CONTAINER_DEFAULT_PLATFORM set.

For anyone measuring disk usage while testing this: on main the snapshots are also much smaller (alpine 41 MB allocated vs 1.09 GB on 1.5.0). That comes from the journal fix in containerization#924, not from this PR.

@CHE3MZ
CHE3MZ force-pushed the fix/pull-host-only-unpack branch from ef55fd7 to e0d3787 Compare October 19, 2026 19:48
@CHE3MZ

CHE3MZ commented Oct 19, 2026

Copy link
Copy Markdown
Author

Thanks for testing this on current main — that's the confirmation the PR needed, and the note about containerization#924 is important. I've rebased on 31e3a98 and reworked the flag: instead of a separate --all-platforms (which quietly did the wrong thing when CONTAINER_DEFAULT_PLATFORM was set), the existing --platform option now accepts �ll. Default pulls unpack only the resolved platform; all blobs are still fetched, and other platforms unpack on demand. I also corrected the PR's disk figures, since #924 makes per-snapshot allocation much smaller than the 1.5.0 numbers originally quoted.

Pulling a multi-arch image unpacked a snapshot for every platform in the index, even though run only needs the requested platform. Unpack only the resolved platform and fall back to the host platform when none is specified, so a default pull creates one snapshot. Blobs for every platform are still fetched, preserving offline use.

Add --platform all to restore unpacking every platform. This replaces the earlier --all-platforms flag, which did not work when CONTAINER_DEFAULT_PLATFORM was set.
@SVilgelm

Copy link
Copy Markdown

Tested on an M5 Max (macOS 27.2.1), release build of main + this PR (+ #2485, #1740). A plain pull of ghcr.io/containerd/busybox:1.36 (10 platforms) made 1 snapshot / 40 MB vs 10 / 408 MB with --platform all; quay.io/libpod/alpine 1 / 43 MB vs 7 / 300 MB. run --platform linux/amd64 still unpacks on demand. Not covered: every platform's blobs are still downloaded, and image load still unpacks every platform (5 images → 40 snapshots).

@SVilgelm

Copy link
Copy Markdown

@CHE3MZ two follow-ups from testing 6b62684 (same M5 build as above).

1. A default pull fails when the image has no host platform. container image pull docker.io/amd64/alpine:3.20 (no --platform) fails after the fetch:

Error: unsupported platform Platform(osVersion: nil, osFeatures: nil, variant: Optional("v8"), _rawOS: "linux", _rawArch: "arm64")

and the image is left in image ls. --platform all, the same path as main's default, unpacks linux/amd64 fine. The default unpack is resolved ?? .current, and Image.descriptor(for:) throws when the index has no entry for it. The host default needs to know what the image has, so it would be checked after the fetch, e.g.:

extension ClientImage {
    /// The host platform if the image has it; otherwise nil, which unpacks every platform it has
    /// (an amd64-only image on Apple silicon, as on main).
    func hostPlatformIfPresent() async throws -> Platform? {
        let host = Platform.current
        return try await index().manifests.contains { $0.platform == host } ? host : nil
    }
}

used when no platform was requested. A test with an amd64-only index would cover it.

2. Could image load get the same default (#913)? ImageLoad.load still calls image.unpack(platform: nil), so loading a multi-platform archive unpacks every platform, the problem this PR fixes for pull. With the helper it's image.unpack(platform: try await image.hostPlatformIfPresent(), ...), plus optionally --platform (including all) via resolvePlatforms. If you'd rather keep this PR to pull, I can open a follow-up once it merges.

The snippets are sketches; I haven't built them.

reviewed by Claude (Opus 5.5)

@CHE3MZ

CHE3MZ commented Nov 19, 2026 •

Copy link
Copy Markdown
Author

@SVilgelm Thanks for the reviews, i'm closing this PR for now because I am not actively looking into it and because it is pretty outdated at this point; I will come back to this later but until then I am closing it to discourage any further reviews since I will not be maintaining it for the time being, thanks for the reviews tho (:

@CHE3MZ CHE3MZ closed this Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants