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
6 changes: 6 additions & 0 deletions extractor/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ func init() {
func NewDockerExtractor(ctx context.Context, imageName string, option types.DockerOption) (Extractor, func(), error) {
ref := image.Reference{Name: imageName, IsFile: false}
transports := []string{"docker-daemon:", "docker://"}
if option.Platform != "" {
// When platform is specified, prioritize registry lookup so the manifest list
// can be filtered by OS/arch and fail fast if unsupported, instead of silently
// using a pre-existing local image from the daemon.
transports = []string{"docker://"}
}
return newDockerExtractor(ctx, ref, transports, option)
}

Expand Down
36 changes: 34 additions & 2 deletions extractor/image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package image
import (
"context"
"io"
"strings"

"github.com/containers/image/v5/image"
"github.com/containers/image/v5/pkg/blobinfocache"
Expand Down Expand Up @@ -53,6 +54,11 @@ func NewImage(ctx context.Context, image Reference, transports []string, option
var domain string
var auth *imageTypes.DockerAuthConfig

osChoice, archChoice, variantChoice, err := parsePlatform(option.Platform)
if err != nil {
return RealImage{}, err
}

originalName := image.Name
if !image.IsFile {
named, err := reference.ParseNormalizedNamed(image.Name)
Expand All @@ -70,8 +76,9 @@ func NewImage(ctx context.Context, image Reference, transports []string, option
}

sys := &imageTypes.SystemContext{
// TODO: make OSChoice configurable
OSChoice: "linux",
OSChoice: osChoice,
ArchitectureChoice: archChoice,
VariantChoice: variantChoice,
DockerAuthConfig: auth,
DockerDisableV1Ping: option.SkipPing,
DockerInsecureSkipTLSVerify: imageTypes.NewOptionalBool(option.InsecureSkipTLSVerify),
Expand All @@ -94,6 +101,31 @@ func NewImage(ctx context.Context, image Reference, transports []string, option
}, nil
}

func parsePlatform(p string) (osChoice, archChoice, variantChoice string, err error) {
osChoice = "linux"
if p == "" {
return osChoice, "", "", nil
}
parts := strings.Split(p, "/")
switch len(parts) {
case 1:
archChoice = parts[0]
case 2:
osChoice = parts[0]
archChoice = parts[1]
case 3:
osChoice = parts[0]
archChoice = parts[1]
variantChoice = parts[2]
default:
return "", "", "", xerrors.Errorf("invalid platform %q", p)
}
if osChoice == "" || archChoice == "" {
return "", "", "", xerrors.Errorf("invalid platform %q", p)
}
return osChoice, archChoice, variantChoice, nil
}

func newSource(ctx context.Context, imageName string, transports []string, sys *imageTypes.SystemContext) (
ImageSource, ImageCloser, error) {
err := xerrors.New("no valid transport")
Expand Down
3 changes: 3 additions & 0 deletions types/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ type DockerOption struct {
UserName string
Password string

// Platform (e.g. linux/amd64, linux/arm64/v8)
Platform string

// ECR
AwsAccessKey string
AwsSecretKey string
Expand Down