Skip to content

Commit 69d1a19

Browse files
Add mutate --ports option to set the exposed ports (#1677)
1 parent 691004b commit 69d1a19

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

Diff for: cmd/crane/cmd/mutate.go

+11
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func NewCmdMutate(options *[]crane.Option) *cobra.Command {
3838
var newRepo string
3939
var user string
4040
var workdir string
41+
var ports []string
4142

4243
mutateCmd := &cobra.Command{
4344
Use: "mutate",
@@ -120,6 +121,15 @@ func NewCmdMutate(options *[]crane.Option) *cobra.Command {
120121
cfg.Config.WorkingDir = workdir
121122
}
122123

124+
// Set ports
125+
if len(ports) > 0 {
126+
portMap := make(map[string]struct{})
127+
for _, port := range ports {
128+
portMap[port] = struct{}{}
129+
}
130+
cfg.Config.ExposedPorts = portMap
131+
}
132+
123133
// Mutate and write image.
124134
img, err = mutate.Config(img, cfg.Config)
125135
if err != nil {
@@ -172,6 +182,7 @@ func NewCmdMutate(options *[]crane.Option) *cobra.Command {
172182
mutateCmd.Flags().StringSliceVar(&newLayers, "append", []string{}, "Path to tarball to append to image")
173183
mutateCmd.Flags().StringVarP(&user, "user", "u", "", "New user to set")
174184
mutateCmd.Flags().StringVarP(&workdir, "workdir", "w", "", "New working dir to set")
185+
mutateCmd.Flags().StringSliceVar(&ports, "exposed-ports", nil, "New ports to expose")
175186
return mutateCmd
176187
}
177188

Diff for: cmd/crane/doc/crane_mutate.md

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)