Skip to content

Commit

Permalink
fix: retag multiarch images (#8493)
Browse files Browse the repository at this point in the history
  • Loading branch information
gsquared94 authored Mar 6, 2023
1 parent 05a2399 commit 5f0e525
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
14 changes: 7 additions & 7 deletions pkg/skaffold/build/cache/details.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ package cache
import (
"context"
"io"
"path/filepath"
"strings"

v1 "github.com/opencontainers/image-spec/specs-go/v1"

"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/docker"
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/platform"
Expand Down Expand Up @@ -78,9 +78,10 @@ func (d needsLocalTagging) Tag(ctx context.Context, c *cache, platforms platform

// Found remotely with wrong tag. Needs retagging
type needsRemoteTagging struct {
hash string
tag string
digest string
hash string
tag string
digest string
platforms []v1.Platform
}

func (d needsRemoteTagging) Hash() string {
Expand All @@ -89,8 +90,7 @@ func (d needsRemoteTagging) Hash() string {

func (d needsRemoteTagging) Tag(ctx context.Context, c *cache, platforms platform.Resolver) error {
fqn := d.tag + "@" + d.digest // Tag is not important. We just need the registry and the digest to locate the image.
matched := platforms.GetPlatforms(strings.Split(filepath.Base(d.tag), ":")[0])
return docker.AddRemoteTag(fqn, d.tag, c.cfg, matched.Platforms)
return docker.AddRemoteTag(fqn, d.tag, c.cfg, d.platforms)
}

// Found locally. Needs pushing
Expand Down
7 changes: 4 additions & 3 deletions pkg/skaffold/build/cache/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"sync"

v1 "github.com/google/go-containerregistry/pkg/v1"
specs "github.com/opencontainers/image-spec/specs-go/v1"

"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/docker"
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/instrumentation"
Expand Down Expand Up @@ -90,7 +91,7 @@ func (c *cache) lookup(ctx context.Context, a *latest.Artifact, tag string, plat
} else if isLocal {
return c.lookupLocal(ctx, hash, tag, entry)
}
return c.lookupRemote(ctx, hash, tag, entry)
return c.lookupRemote(ctx, hash, tag, pls.Platforms, entry)
}

func (c *cache) lookupLocal(ctx context.Context, hash, tag string, entry ImageDetails) cacheDetails {
Expand Down Expand Up @@ -118,7 +119,7 @@ func (c *cache) lookupLocal(ctx context.Context, hash, tag string, entry ImageDe
return needsBuilding{hash: hash}
}

func (c *cache) lookupRemote(ctx context.Context, hash, tag string, entry ImageDetails) cacheDetails {
func (c *cache) lookupRemote(ctx context.Context, hash, tag string, platforms []specs.Platform, entry ImageDetails) cacheDetails {
if remoteDigest, err := docker.RemoteDigest(tag, c.cfg, nil); err == nil {
// Image exists remotely with the same tag and digest
if remoteDigest == entry.Digest {
Expand All @@ -130,7 +131,7 @@ func (c *cache) lookupRemote(ctx context.Context, hash, tag string, entry ImageD
fqn := tag + "@" + entry.Digest // Actual tag will be ignored but we need the registry and the digest part of it.
if remoteDigest, err := docker.RemoteDigest(fqn, c.cfg, nil); err == nil {
if remoteDigest == entry.Digest {
return needsRemoteTagging{hash: hash, tag: tag, digest: entry.Digest}
return needsRemoteTagging{hash: hash, tag: tag, digest: entry.Digest, platforms: platforms}
}
}

Expand Down

0 comments on commit 5f0e525

Please sign in to comment.