diff --git a/cmd/crane/cmd/mutate.go b/cmd/crane/cmd/mutate.go index 2eb207423..9f7a3eaf1 100644 --- a/cmd/crane/cmd/mutate.go +++ b/cmd/crane/cmd/mutate.go @@ -38,6 +38,7 @@ func NewCmdMutate(options *[]crane.Option) *cobra.Command { var newRepo string var user string var workdir string + var ports []string mutateCmd := &cobra.Command{ Use: "mutate", @@ -120,6 +121,15 @@ func NewCmdMutate(options *[]crane.Option) *cobra.Command { cfg.Config.WorkingDir = workdir } + // Set ports + if len(ports) > 0 { + portMap := make(map[string]struct{}) + for _, port := range ports { + portMap[port] = struct{}{} + } + cfg.Config.ExposedPorts = portMap + } + // Mutate and write image. img, err = mutate.Config(img, cfg.Config) if err != nil { @@ -172,6 +182,7 @@ func NewCmdMutate(options *[]crane.Option) *cobra.Command { mutateCmd.Flags().StringSliceVar(&newLayers, "append", []string{}, "Path to tarball to append to image") mutateCmd.Flags().StringVarP(&user, "user", "u", "", "New user to set") mutateCmd.Flags().StringVarP(&workdir, "workdir", "w", "", "New working dir to set") + mutateCmd.Flags().StringSliceVar(&ports, "exposed-ports", nil, "New ports to expose") return mutateCmd } diff --git a/cmd/crane/doc/crane_mutate.md b/cmd/crane/doc/crane_mutate.md index 6c484279b..367410450 100644 --- a/cmd/crane/doc/crane_mutate.md +++ b/cmd/crane/doc/crane_mutate.md @@ -14,6 +14,7 @@ crane mutate [flags] --cmd strings New cmd to set --entrypoint strings New entrypoint to set -e, --env keyToValue New envvar to add + --exposed-ports strings New ports to expose -h, --help help for mutate -l, --label stringToString New labels to add (default []) -o, --output string Path to new tarball of resulting image