Skip to content

Commit

Permalink
Add mutate --ports option to set the exposed ports (#1677)
Browse files Browse the repository at this point in the history
  • Loading branch information
josephglanville committed May 4, 2023
1 parent 691004b commit 69d1a19
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cmd/crane/cmd/mutate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

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.

0 comments on commit 69d1a19

Please sign in to comment.