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: 6 additions & 34 deletions local/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@ 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 @@ -29,7 +26,7 @@ func NewImage(repoName string, dockerClient DockerClient, ops ...imgutil.ImageOp
return nil, err
}

previousImage, err := processImageOption(options.PreviousImageRepoName, options.Platform, dockerClient, true)
previousImage, err := processImageOption(options.PreviousImageRepoName, dockerClient, true)
if err != nil {
return nil, err
}
Expand All @@ -41,7 +38,7 @@ func NewImage(repoName string, dockerClient DockerClient, ops ...imgutil.ImageOp
baseIdentifier string
store *Store
)
baseImage, err := processImageOption(options.BaseImageRepoName, options.Platform, dockerClient, false)
baseImage, err := processImageOption(options.BaseImageRepoName, dockerClient, false)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -72,14 +69,6 @@ func defaultPlatform(dockerClient DockerClient) (imgutil.Platform, error) {
if err != nil {
return imgutil.Platform{}, err
}
if daemonInfo.Os == "linux" {
// 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 @@ -107,11 +96,11 @@ type imageResult struct {
layerStore *Store
}

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

func getInspectAndHistory(repoName string, platform imgutil.Platform, dockerClient DockerClient) (*image.InspectResponse, []image.HistoryResponseItem, error) {
platformOpt := client.ImageInspectWithPlatform(&ocispec.Platform{
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 {
// ...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)
}
}
func getInspectAndHistory(repoName string, dockerClient DockerClient) (*image.InspectResponse, []image.HistoryResponseItem, error) {
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,
Architecture: dockerInspect.Architecture, // FIXME: this should come from options.Platform
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,
Variant: dockerInspect.Variant,
OSVersion: dockerInspect.OsVersion, // FIXME: this should come from options.Platform
Variant: dockerInspect.Variant, // FIXME: this should come from options.Platform
}
layersToSet := newEmptyLayerListFrom(configFile, downloadLayersOnAccess, withStore, dockerInspect.ID)
return imageFrom(layersToSet, configFile, imgutil.DockerTypes) // FIXME: this should be configurable with options.MediaTypes
Expand Down