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

fix: missing digests on manifests #3602

Merged
merged 2 commits into from Nov 29, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/pipe/docker/api.go
Expand Up @@ -40,7 +40,7 @@ type imager interface {
// manifester is something that can create and push docker manifests.
type manifester interface {
Create(ctx *context.Context, manifest string, images, flags []string) error
Push(ctx *context.Context, manifest string, flags []string) error
Push(ctx *context.Context, manifest string, flags []string) (digest string, err error)
}

// nolint: unparam
Expand Down
24 changes: 13 additions & 11 deletions internal/pipe/docker/api_docker.go
Expand Up @@ -31,13 +31,18 @@ func (m dockerManifester) Create(ctx *context.Context, manifest string, images,
return nil
}

func (m dockerManifester) Push(ctx *context.Context, manifest string, flags []string) error {
func (m dockerManifester) Push(ctx *context.Context, manifest string, flags []string) (string, error) {
args := []string{"manifest", "push", manifest}
args = append(args, flags...)
if err := runCommand(ctx, ".", "docker", args...); err != nil {
return fmt.Errorf("failed to push %s: %w", manifest, err)
bts, err := runCommandWithOutput(ctx, ".", "docker", args...)
if err != nil {
return "", fmt.Errorf("failed to push %s: %w", manifest, err)
}
return nil
digest := dockerDigestPattern.FindString(string(bts))
if digest == "" {
return "", fmt.Errorf("failed to find docker digest in docker push output: %s", string(bts))
}
return digest, nil
}

type dockerImager struct {
Expand All @@ -46,18 +51,15 @@ type dockerImager struct {

var dockerDigestPattern = regexp.MustCompile("sha256:[a-z0-9]{64}")

func (i dockerImager) Push(ctx *context.Context, image string, flags []string) (digest string, err error) {
outBytes, err := runCommandWithOutput(ctx, ".", "docker", "push", image)
func (i dockerImager) Push(ctx *context.Context, image string, flags []string) (string, error) {
bts, err := runCommandWithOutput(ctx, ".", "docker", "push", image)
if err != nil {
return "", fmt.Errorf("failed to push %s: %w", image, err)
}

out := string(outBytes)
digest = dockerDigestPattern.FindString(out)
digest := dockerDigestPattern.FindString(string(bts))
if digest == "" {
return "", fmt.Errorf("failed to find docker digest in docker push output: %v", out)
return "", fmt.Errorf("failed to find docker digest in docker push output: %s", string(bts))
}

return digest, nil
}

Expand Down
9 changes: 7 additions & 2 deletions internal/pipe/docker/docker_test.go
Expand Up @@ -1093,10 +1093,15 @@ func TestRunPipe(t *testing.T) {
require.NoError(t, rmi(img), "could not delete image %s", img)
}

_ = ctx.Artifacts.Filter(artifact.ByType(artifact.DockerImage)).Visit(func(a *artifact.Artifact) error {
_ = ctx.Artifacts.Filter(
artifact.Or(
artifact.ByType(artifact.DockerImage),
artifact.ByType(artifact.DockerManifest),
),
).Visit(func(a *artifact.Artifact) error {
digest, err := artifact.Extra[string](*a, artifact.ExtraDigest)
require.NoError(t, err)
require.NotEmpty(t, digest)
require.NotEmpty(t, digest, "missing digest for "+a.Name)
return nil
})
})
Expand Down
9 changes: 7 additions & 2 deletions internal/pipe/docker/manifest.go
Expand Up @@ -81,10 +81,15 @@ func (ManifestPipe) Publish(ctx *context.Context) error {
if manifest.ID != "" {
art.Extra[artifact.ExtraID] = manifest.ID
}
ctx.Artifacts.Add(art)

log.WithField("manifest", name).Info("pushing")
return manifester.Push(ctx, name, manifest.PushFlags)
digest, err := manifester.Push(ctx, name, manifest.PushFlags)
if err != nil {
return err
}
art.Extra[artifact.ExtraDigest] = digest
ctx.Artifacts.Add(art)
return nil
})
}
return g.Wait()
Expand Down