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

Add --set-base-image-annotations flag to crane append #1098

Merged
merged 5 commits into from
Aug 4, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
20 changes: 20 additions & 0 deletions cmd/crane/cmd/append.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ import (
"github.com/google/go-containerregistry/pkg/name"
v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/google/go-containerregistry/pkg/v1/empty"
"github.com/google/go-containerregistry/pkg/v1/mutate"
specsv1 "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/spf13/cobra"
)

// NewCmdAppend creates a new cobra.Command for the append subcommand.
func NewCmdAppend(options *[]crane.Option) *cobra.Command {
var baseRef, newTag, outFile string
var newLayers []string
var annotate bool

appendCmd := &cobra.Command{
Use: "append",
Expand All @@ -53,6 +56,22 @@ func NewCmdAppend(options *[]crane.Option) *cobra.Command {
return fmt.Errorf("appending %v: %v", newLayers, err)
}

if baseRef != "" && annotate {
ref, err := name.ParseReference(baseRef)
if err != nil {
return fmt.Errorf("parsing ref %q: %v", baseRef, err)
}

baseDigest, err := base.Digest()
if err != nil {
return err
}
img = mutate.Annotations(img, map[string]string{
specsv1.AnnotationBaseImageName: ref.String(),
imjasonh marked this conversation as resolved.
Show resolved Hide resolved
specsv1.AnnotationBaseImageDigest: baseDigest.String(),
}).(v1.Image)
}

if outFile != "" {
if err := crane.Save(img, newTag, outFile); err != nil {
return fmt.Errorf("writing output %q: %v", outFile, err)
Expand All @@ -78,6 +97,7 @@ func NewCmdAppend(options *[]crane.Option) *cobra.Command {
appendCmd.Flags().StringVarP(&newTag, "new_tag", "t", "", "Tag to apply to resulting image")
appendCmd.Flags().StringSliceVarP(&newLayers, "new_layer", "f", []string{}, "Path to tarball to append to image")
appendCmd.Flags().StringVarP(&outFile, "output", "o", "", "Path to new tarball of resulting image")
appendCmd.Flags().BoolVar(&annotate, "annotate", false, "If true, annotate the resulting image as being based on the base image")
imjasonh marked this conversation as resolved.
Show resolved Hide resolved

appendCmd.MarkFlagRequired("new_tag")
appendCmd.MarkFlagRequired("new_layer")
Expand Down
1 change: 1 addition & 0 deletions cmd/crane/doc/crane_append.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
github.com/kr/text v0.2.0 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/opencontainers/image-spec v1.0.1
github.com/opencontainers/image-spec v1.0.2-0.20210730191737-8e42a01fb1b7
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/spf13/cobra v1.2.1
Expand Down
3 changes: 2 additions & 1 deletion go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ github.com/klauspost/compress/zstd/internal/xxhash
## explicit
# github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/go-digest
# github.com/opencontainers/image-spec v1.0.1
# github.com/opencontainers/image-spec v1.0.2-0.20210730191737-8e42a01fb1b7
## explicit
github.com/opencontainers/image-spec/specs-go
github.com/opencontainers/image-spec/specs-go/v1
Expand Down