Skip to content

Commit

Permalink
Fix a panic due to missing repo digests (#915)
Browse files Browse the repository at this point in the history
Users are unlikely to encounter this situation but I ran into it during
some testing.

I've confirmed the fix locally. A regression test will be included in
the upcoming buildx examples, since building the same dockerfile with
`Image` and `buildx.Image` also reproduced the issue.

Fixes #914
  • Loading branch information
blampe authored Dec 21, 2023
1 parent a68b9e4 commit 1b8ef34
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions provider/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,11 +403,17 @@ func (p *dockerNativeProvider) dockerBuild(ctx context.Context,
return img.Name, pbstruct, err
}

// nodigest mimics Docker's placeholder for situations where no digests are found.
type nodigest struct{}

func (nodigest) String() string { return "<none>@<none>" }

// getRepoDigest returns the repoDigest for the given image ID that matches the target image name.
// If the image is not found in the local store, it returns an error.
func (p *dockerNativeProvider) getRepoDigest(
ctx context.Context, docker *client.Client, imageID string,
img Image, urn resource.URN) (reference.Reference, error) {
img Image, urn resource.URN,
) (reference.Reference, error) {
dist, _, err := docker.ImageInspectWithRaw(ctx, imageID)
if err != nil {
return nil, err
Expand All @@ -418,10 +424,9 @@ func (p *dockerNativeProvider) getRepoDigest(
return nil, err
}

var repoDigest reference.Reference
var repoDigest reference.Reference = nodigest{}
for _, d := range dist.RepoDigests {
ref, err := reference.ParseNormalizedNamed(d)

if err != nil {
_ = p.host.Log(ctx, "warning", urn, fmt.Sprintf("Error parsing digest %q: %v", d, err))
continue
Expand Down

0 comments on commit 1b8ef34

Please sign in to comment.