Skip to content

Commit ff385a9

Browse files
authored
feat: mutate platform (#1919)
Signed-off-by: Josh W Lewis <[email protected]>
1 parent 98dd3e9 commit ff385a9

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

cmd/crane/cmd/mutate.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func NewCmdMutate(options *[]crane.Option) *cobra.Command {
3939
var user string
4040
var workdir string
4141
var ports []string
42+
var newPlatform string
4243

4344
mutateCmd := &cobra.Command{
4445
Use: "mutate",
@@ -130,8 +131,20 @@ func NewCmdMutate(options *[]crane.Option) *cobra.Command {
130131
cfg.Config.ExposedPorts = portMap
131132
}
132133

134+
// Set platform
135+
if len(newPlatform) > 0 {
136+
platform, err := parsePlatform(newPlatform)
137+
if err != nil {
138+
return err
139+
}
140+
cfg.OS = platform.OS
141+
cfg.Architecture = platform.Architecture
142+
cfg.Variant = platform.Variant
143+
cfg.OSVersion = platform.OSVersion
144+
}
145+
133146
// Mutate and write image.
134-
img, err = mutate.Config(img, cfg.Config)
147+
img, err = mutate.ConfigFile(img, cfg)
135148
if err != nil {
136149
return fmt.Errorf("mutating config: %w", err)
137150
}
@@ -183,6 +196,8 @@ func NewCmdMutate(options *[]crane.Option) *cobra.Command {
183196
mutateCmd.Flags().StringVarP(&user, "user", "u", "", "New user to set")
184197
mutateCmd.Flags().StringVarP(&workdir, "workdir", "w", "", "New working dir to set")
185198
mutateCmd.Flags().StringSliceVar(&ports, "exposed-ports", nil, "New ports to expose")
199+
// Using "set-platform" to avoid clobbering "platform" persistent flag.
200+
mutateCmd.Flags().StringVar(&newPlatform, "set-platform", "", "New platform to set in the form os/arch[/variant][:osversion] (e.g. linux/amd64)")
186201
return mutateCmd
187202
}
188203

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)