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

Tag and omit references to the refs file #295

Merged
merged 1 commit into from
Jul 16, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions internal/cli/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"

"github.com/google/go-containerregistry/pkg/name"
coci "github.com/sigstore/cosign/pkg/oci"
Expand Down Expand Up @@ -147,6 +148,9 @@ func PublishCmd(ctx context.Context, outputRefs string, archs []types.Architectu
var finalDigest name.Digest
var idx coci.SignedImageIndex

// References, collect'em all!
builtReferences := []string{}

for _, arch := range bc.ImageConfiguration.Archs {
arch := arch
bc := *bc
Expand All @@ -172,6 +176,7 @@ func PublishCmd(ctx context.Context, outputRefs string, archs []types.Architectu
return fmt.Errorf("publishing %s image: %w", arch, err)
}

builtReferences = append(builtReferences, finalDigest.String())
imgs[arch] = img
return nil
})
Expand All @@ -186,6 +191,7 @@ func PublishCmd(ctx context.Context, outputRefs string, archs []types.Architectu
if err != nil {
return fmt.Errorf("publishing image index: %w", err)
}
builtReferences = append(builtReferences, finalDigest.String())
}

bc.Options.SBOMFormats = formats
Expand Down Expand Up @@ -229,7 +235,7 @@ func PublishCmd(ctx context.Context, outputRefs string, archs []types.Architectu
// If provided, this is the name of the file to write digest referenced into
if outputRefs != "" {
//nolint:gosec // Make image ref file readable by non-root
if err := os.WriteFile(outputRefs, []byte(finalDigest.String()), 0666); err != nil {
if err := os.WriteFile(outputRefs, []byte(strings.Join(builtReferences, "\n")+"\n"), 0666); err != nil {
return fmt.Errorf("failed to write digest: %w", err)
}
}
Expand All @@ -243,23 +249,18 @@ func PublishCmd(ctx context.Context, outputRefs string, archs []types.Architectu

// publishImage publishes a specific architecture image
func publishImage(bc *build.Context, layerTarGZ string, arch types.Architecture) (imgDigest name.Digest, img coci.SignedImage, err error) {
// We only tag the images if we're building a single one
imageTags := []string{}
if len(bc.ImageConfiguration.Archs) == 1 {
Comment on lines -246 to -248
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious why we need this part of the change, or whether it regresses something 🤔

Copy link
Contributor Author

@puerco puerco Jul 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it's better if I dont pass it to the tagging function and build the reference by hand? I did it because it was returning an empty string .

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have enough context here, so I'd defer to @kaniini

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I thought you had a specific problem in mind. I think we're fine, tests are ok and I've been using this branch today ok.

imageTags = bc.Options.Tags
}
if bc.Options.UseDockerMediaTypes {
imgDigest, img, err = oci.PublishDockerImageFromLayer(
layerTarGZ, bc.ImageConfiguration, bc.Options.SourceDateEpoch, arch, bc.Logger(),
bc.Options.SBOMPath, bc.Options.SBOMFormats, imageTags...,
bc.Options.SBOMPath, bc.Options.SBOMFormats, bc.Options.Tags...,
)
if err != nil {
return name.Digest{}, nil, fmt.Errorf("failed to build Docker image for %q: %w", arch, err)
}
} else {
imgDigest, img, err = oci.PublishImageFromLayer(
layerTarGZ, bc.ImageConfiguration, bc.Options.SourceDateEpoch, arch, bc.Logger(),
bc.Options.SBOMPath, bc.Options.SBOMFormats, imageTags...,
bc.Options.SBOMPath, bc.Options.SBOMFormats, bc.Options.Tags...,
)
if err != nil {
return name.Digest{}, nil, fmt.Errorf("failed to build OCI image for %q: %w", arch, err)
Expand Down
4 changes: 2 additions & 2 deletions pkg/build/oci/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ func publishImageFromLayerWithMediaType(mediaType ggcrtypes.MediaType, layerTarG

digest := name.Digest{}
for _, tag := range tags {
logger.Printf("publishing tag %v", tag)
logger.Printf("publishing image tag %v", tag)
digest, err = publishTagFromImage(v1Image, tag, h, logger)
if err != nil {
return name.Digest{}, nil, err
Expand Down Expand Up @@ -392,7 +392,7 @@ func publishIndexWithMediaType(mediaType ggcrtypes.MediaType, imgs map[types.Arc

digest := name.Digest{}
for _, tag := range tags {
logger.Printf("publishing tag %v", tag)
logger.Printf("publishing index tag %v", tag)
digest, err = publishTagFromIndex(idx, tag, h, logger)
if err != nil {
return name.Digest{}, nil, err
Expand Down