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 mutate --ports option to set the exposed ports #1677

Merged
merged 1 commit into from
May 4, 2023
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
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.