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
17 changes: 17 additions & 0 deletions extractor/image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type ImageCloser interface {
LayerInfos() (layerInfos []imageTypes.BlobInfo)
ConfigInfo() imageTypes.BlobInfo
ConfigBlob(context.Context) ([]byte, error)
Inspect(context.Context) (*imageTypes.ImageInspectInfo, error)
Close() error
}

Expand Down Expand Up @@ -93,6 +94,22 @@ func NewImage(ctx context.Context, image Reference, transports []string, option
return RealImage{}, xerrors.Errorf("failed to initialize source: %w", err)
}

// Validate platform if variant was requested
if variantChoice != "" {
inspectInfo, err := src.Inspect(ctx)
if err != nil {
return RealImage{}, xerrors.Errorf("failed to inspect image: %w", err)
}

// Check if the actual platform matches the requested one
if inspectInfo.Architecture != archChoice || inspectInfo.Variant != variantChoice {
return RealImage{}, xerrors.Errorf(
"requested platform %s/%s/%s not available",
osChoice, archChoice, variantChoice,
)
}
}

return RealImage{
name: originalName,
blobInfoCache: blobinfocache.DefaultCache(sys),
Expand Down
14 changes: 14 additions & 0 deletions extractor/image/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,20 @@ func TestNewImage(t *testing.T) {
},
wantErr: `failed to initialize: invalid character`,
},
{
name: "sad path: invalid platform variant",
args: args{
image: Reference{
Name: "testdata/alpine-310.tar.gz",
IsFile: true,
},
transports: []string{"docker-archive:"},
option: types.DockerOption{
Platform: "linux/amd64/v99",
},
},
wantErr: `requested platform linux/amd64/v99 not available`,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down