Skip to content
Merged
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
40 changes: 34 additions & 6 deletions local/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ package local
import (
"context"
"fmt"
"runtime"
"strings"

cerrdefs "github.com/containerd/errdefs"
v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/moby/moby/api/types/image"
"github.com/moby/moby/client"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"

"github.com/buildpacks/imgutil"
)
Expand All @@ -26,7 +29,7 @@ func NewImage(repoName string, dockerClient DockerClient, ops ...imgutil.ImageOp
return nil, err
}

previousImage, err := processImageOption(options.PreviousImageRepoName, dockerClient, true)
previousImage, err := processImageOption(options.PreviousImageRepoName, options.Platform, dockerClient, true)
if err != nil {
return nil, err
}
Expand All @@ -38,7 +41,7 @@ func NewImage(repoName string, dockerClient DockerClient, ops ...imgutil.ImageOp
baseIdentifier string
store *Store
)
baseImage, err := processImageOption(options.BaseImageRepoName, dockerClient, false)
baseImage, err := processImageOption(options.BaseImageRepoName, options.Platform, dockerClient, false)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -69,6 +72,14 @@ func defaultPlatform(dockerClient DockerClient) (imgutil.Platform, error) {
if err != nil {
return imgutil.Platform{}, err
}
if daemonInfo.Os == "linux" {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We have some tests here around not having a platform defined. I was surprised there weren't any correlated test changes. Should there be a test to capture this new behavior?

@bojidar-bg bojidar-bg Feb 10, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If I'm reading #283 correctly, in the test environment, both the Docker daemon and the imgutil tests run on the same architecture, amd64, hence this ends up causing no change.

A new test would be nice, but I'm not very sure how to introduce it.

Comment thread
bojidar-bg marked this conversation as resolved.
// When running on a different architecture than the daemon, we still want to use images matching our own architecture
// https://github.com/buildpacks/lifecycle/issues/1599
return imgutil.Platform{
OS: "linux",
Architecture: runtime.GOARCH,
}, nil
}
return imgutil.Platform{
OS: daemonInfo.Os,
Architecture: daemonInfo.Arch,
Expand Down Expand Up @@ -96,11 +107,11 @@ type imageResult struct {
layerStore *Store
}

func processImageOption(repoName string, dockerClient DockerClient, downloadLayersOnAccess bool) (imageResult, error) {
func processImageOption(repoName string, platform imgutil.Platform, dockerClient DockerClient, downloadLayersOnAccess bool) (imageResult, error) {
if repoName == "" {
return imageResult{}, nil
}
inspect, history, err := getInspectAndHistory(repoName, dockerClient)
inspect, history, err := getInspectAndHistory(repoName, platform, dockerClient)
if err != nil {
return imageResult{}, err
}
Expand All @@ -119,8 +130,25 @@ func processImageOption(repoName string, dockerClient DockerClient, downloadLaye
}, nil
}

func getInspectAndHistory(repoName string, dockerClient DockerClient) (*image.InspectResponse, []image.HistoryResponseItem, error) {
inspect, err := dockerClient.ImageInspect(context.Background(), repoName)
func getInspectAndHistory(repoName string, platform imgutil.Platform, dockerClient DockerClient) (*image.InspectResponse, []image.HistoryResponseItem, error) {
platformOpt := client.ImageInspectWithPlatform(&ocispec.Platform{
Comment thread
bojidar-bg marked this conversation as resolved.
Architecture: platform.Architecture,
OS: platform.OS,
OSVersion: platform.OSVersion,
Variant: platform.Variant,
})
// Try to inspect the image with the default platform/arch
inspect, err := dockerClient.ImageInspect(context.Background(), repoName, platformOpt)
if err != nil {
Comment thread
bojidar-bg marked this conversation as resolved.
// ...and if that fails, inspect without the platform
if cerrdefs.IsNotImplemented(err) || strings.Contains(err.Error(), "requires API version") {
fmt.Printf("Docker API Version < 1.49. Platform defaulting to daemon platform\n")
inspect, err = dockerClient.ImageInspect(context.Background(), repoName)
} else if cerrdefs.IsNotFound(err) {
fmt.Printf("Docker did not find image %s with platform %s/%s; retrying without specifying a platform\n", repoName, platform.OS, platform.Architecture)
inspect, err = dockerClient.ImageInspect(context.Background(), repoName)
}
}
if err != nil {
if cerrdefs.IsNotFound(err) {
return nil, nil, nil
Expand Down
6 changes: 3 additions & 3 deletions local/v1_facade.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ func newV1ImageFacadeFromInspect(dockerInspect image.InspectResponse, history []
return nil, err
}
configFile := &v1.ConfigFile{
Architecture: dockerInspect.Architecture, // FIXME: this should come from options.Platform
Architecture: dockerInspect.Architecture,
Author: dockerInspect.Author,
Created: toV1Time(dockerInspect.Created),
History: imgutil.NormalizedHistory(toV1History(history), len(dockerInspect.RootFS.Layers)),
OS: dockerInspect.Os,
RootFS: rootFS,
Config: toV1Config(dockerInspect.Config),
OSVersion: dockerInspect.OsVersion, // FIXME: this should come from options.Platform
Variant: dockerInspect.Variant, // FIXME: this should come from options.Platform
OSVersion: dockerInspect.OsVersion,
Variant: dockerInspect.Variant,
}
layersToSet := newEmptyLayerListFrom(configFile, downloadLayersOnAccess, withStore, dockerInspect.ID)
return imageFrom(layersToSet, configFile, imgutil.DockerTypes) // FIXME: this should be configurable with options.MediaTypes
Expand Down