1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-06 03:13:48 +02:00

fix: missing digests on manifests (#3602)

it was missing the digest parsing for the manifest, and there were no
tests covering it.

now the tests are there, and so is the fix.

refs #3599
This commit is contained in:
Carlos Alexandro Becker 2022-11-28 21:30:16 -03:00 committed by Carlos A Becker
parent b76b65875d
commit d3cdd96c39
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940
4 changed files with 28 additions and 16 deletions

View File

@ -40,7 +40,7 @@ type imager interface {
// manifester is something that can create and push docker manifests. // manifester is something that can create and push docker manifests.
type manifester interface { type manifester interface {
Create(ctx *context.Context, manifest string, images, flags []string) error 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 // nolint: unparam

View File

@ -31,13 +31,18 @@ func (m dockerManifester) Create(ctx *context.Context, manifest string, images,
return nil 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 := []string{"manifest", "push", manifest}
args = append(args, flags...) args = append(args, flags...)
if err := runCommand(ctx, ".", "docker", args...); err != nil { bts, err := runCommandWithOutput(ctx, ".", "docker", args...)
return fmt.Errorf("failed to push %s: %w", manifest, err) 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 { type dockerImager struct {
@ -46,18 +51,15 @@ type dockerImager struct {
var dockerDigestPattern = regexp.MustCompile("sha256:[a-z0-9]{64}") var dockerDigestPattern = regexp.MustCompile("sha256:[a-z0-9]{64}")
func (i dockerImager) Push(ctx *context.Context, image string, flags []string) (digest string, err error) { func (i dockerImager) Push(ctx *context.Context, image string, flags []string) (string, error) {
outBytes, err := runCommandWithOutput(ctx, ".", "docker", "push", image) bts, err := runCommandWithOutput(ctx, ".", "docker", "push", image)
if err != nil { if err != nil {
return "", fmt.Errorf("failed to push %s: %w", image, err) return "", fmt.Errorf("failed to push %s: %w", image, err)
} }
digest := dockerDigestPattern.FindString(string(bts))
out := string(outBytes)
digest = dockerDigestPattern.FindString(out)
if digest == "" { 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 return digest, nil
} }

View File

@ -1093,10 +1093,15 @@ func TestRunPipe(t *testing.T) {
require.NoError(t, rmi(img), "could not delete image %s", img) 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) digest, err := artifact.Extra[string](*a, artifact.ExtraDigest)
require.NoError(t, err) require.NoError(t, err)
require.NotEmpty(t, digest) require.NotEmpty(t, digest, "missing digest for "+a.Name)
return nil return nil
}) })
}) })

View File

@ -81,10 +81,15 @@ func (ManifestPipe) Publish(ctx *context.Context) error {
if manifest.ID != "" { if manifest.ID != "" {
art.Extra[artifact.ExtraID] = manifest.ID art.Extra[artifact.ExtraID] = manifest.ID
} }
ctx.Artifacts.Add(art)
log.WithField("manifest", name).Info("pushing") 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() return g.Wait()