Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect arch when getting image for prebuild #1499

Merged
merged 1 commit into from
Dec 19, 2024
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
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
Loading