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

feat(mutate): adding empty-oci-base functionality #2051

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
13 changes: 12 additions & 1 deletion cmd/crane/cmd/mutate.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import (
"github.com/google/go-containerregistry/pkg/crane"
"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"
"github.com/google/go-containerregistry/pkg/v1/types"
"github.com/spf13/cobra"
)

Expand All @@ -40,6 +42,7 @@ func NewCmdMutate(options *[]crane.Option) *cobra.Command {
var workdir string
var ports []string
var newPlatform string
var ociEmptyBase bool

mutateCmd := &cobra.Command{
Use: "mutate",
Expand All @@ -65,7 +68,14 @@ func NewCmdMutate(options *[]crane.Option) *cobra.Command {

img, err := crane.Pull(ref, *options...)
if err != nil {
return fmt.Errorf("pulling %s: %w", ref, err)
if ociEmptyBase {
fmt.Println("base unspecified, using empty image")
img = empty.Image
img = mutate.MediaType(img, types.OCIManifestSchema1)
img = mutate.ConfigMediaType(img, types.OCIConfigJSON)
} else {
return fmt.Errorf("pulling %s: %w", ref, err)
}
}
if len(newLayers) != 0 {
img, err = crane.Append(img, newLayers...)
Expand Down Expand Up @@ -198,6 +208,7 @@ func NewCmdMutate(options *[]crane.Option) *cobra.Command {
mutateCmd.Flags().StringSliceVar(&ports, "exposed-ports", nil, "New ports to expose")
// Using "set-platform" to avoid clobbering "platform" persistent flag.
mutateCmd.Flags().StringVar(&newPlatform, "set-platform", "", "New platform to set in the form os/arch[/variant][:osversion] (e.g. linux/amd64)")
mutateCmd.Flags().BoolVar(&ociEmptyBase, "oci-empty-base", false, "If true, use an empty OCI image when the base image is not found")
return mutateCmd
}

Expand Down
1 change: 1 addition & 0 deletions cmd/crane/doc/crane_mutate.md

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