Skip to content

Commit

Permalink
Detect arch when getting image for prebuild
Browse files Browse the repository at this point in the history
  • Loading branch information
bkneis authored and pascalbreuninger committed Dec 19, 2024
1 parent bcbe87c commit 6a1c487
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/devcontainer/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func (r *runner) buildImage(
r.Log.Debugf("Try to find prebuild image %s in repositories %s", prebuildHash, strings.Join(options.PrebuildRepositories, ","))
for _, prebuildRepo := range options.PrebuildRepositories {
prebuildImage := prebuildRepo + ":" + prebuildHash
img, err := image.GetImage(ctx, prebuildImage)
img, err := image.GetImageForArch(ctx, prebuildImage, targetArch)
if err == nil && img != nil {
// prebuild image found
r.Log.Infof("Found existing prebuilt image %s", prebuildImage)
Expand Down
24 changes: 24 additions & 0 deletions pkg/image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,30 @@ func GetImage(ctx context.Context, image string) (v1.Image, error) {
return img, err
}

func GetImageForArch(ctx context.Context, image, arch string) (v1.Image, error) {
ref, err := name.ParseReference(image)
if err != nil {
return nil, err
}

keychain, err := getKeychain(ctx)
if err != nil {
return nil, fmt.Errorf("create authentication keychain: %w", err)
}

remoteOptions := []remote.Option{
remote.WithAuthFromKeychain(keychain),
remote.WithPlatform(v1.Platform{Architecture: arch, OS: "linux"}),
}

img, err := remote.Image(ref, remoteOptions...)
if err != nil {
return nil, errors.Wrapf(err, "retrieve image %s", image)
}

return img, err
}

func CheckPushPermissions(image string) error {
ref, err := name.ParseReference(image)
if err != nil {
Expand Down

0 comments on commit 6a1c487

Please sign in to comment.