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

Output entire sha in quiet mode #1035

Merged
merged 2 commits into from
Jan 26, 2021
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 acceptance/assertions/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (o OutputAssertionManager) ReportSuccessfulQuietBuild(name string) {
o.testObject.Helper()
o.testObject.Log("quiet mode")

o.assert.Matches(strings.TrimSpace(o.output), regexp.MustCompile(name+`@sha256:[\w]{12}`))
o.assert.Matches(strings.TrimSpace(o.output), regexp.MustCompile(name+`@sha256:[\w]{12,64}`))
}

func (o OutputAssertionManager) ReportsSuccessfulRebase(name string) {
Expand Down
18 changes: 7 additions & 11 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -888,26 +888,22 @@ func (c *Client) logImageNameAndSha(ctx context.Context, publish bool, imageRef

// Remove tag, if it exists, from the image name
imgName := strings.TrimSuffix(imageRef.String(), imageRef.Identifier())
imgNameAndSha := fmt.Sprintf("%s@%s\n", imgName, parseShortDigestFromImageID(id))
imgNameAndSha := fmt.Sprintf("%s@%s\n", imgName, parseDigestFromImageID(id))

// Access the logger's Writer directly to bypass ReportSuccessfulQuietBuild mode
_, err = c.logger.Writer().Write([]byte(imgNameAndSha))
return err
}

func parseShortDigestFromImageID(id imgutil.Identifier) string {
var shortID string
func parseDigestFromImageID(id imgutil.Identifier) string {
var digest string
switch v := id.(type) {
case local.IDIdentifier:
shortID = v.String()
digest = v.String()
case remote.DigestIdentifier:
shortID = v.Digest.DigestStr()
digest = v.Digest.DigestStr()
}

shortID = strings.TrimPrefix(shortID, "sha256:")
if len(shortID) > 12 {
shortID = shortID[0:12]
}

return fmt.Sprintf("sha256:%s", shortID)
digest = strings.TrimPrefix(digest, "sha256:")
return fmt.Sprintf("sha256:%s", digest)
}
4 changes: 2 additions & 2 deletions build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func testBuild(t *testing.T, when spec.G, it spec.S) {
Publish: true,
}))

h.AssertEq(t, strings.TrimSpace(outBuf.String()), "example.io/some/app@sha256:363c754893f0")
h.AssertEq(t, strings.TrimSpace(outBuf.String()), "example.io/some/app@sha256:363c754893f0efe22480b4359a5956cf3bd3ce22742fc576973c61348308c2e4")
})
})

Expand All @@ -255,7 +255,7 @@ func testBuild(t *testing.T, when spec.G, it spec.S) {
AppPath: filepath.Join("testdata", "some-app"),
}))

h.AssertEq(t, strings.TrimSpace(outBuf.String()), "some/app@sha256:363c754893f0")
h.AssertEq(t, strings.TrimSpace(outBuf.String()), "some/app@sha256:363c754893f0efe22480b4359a5956cf3bd3ce22742fc576973c61348308c2e4")
})
})
})
Expand Down