Skip to content

Commit

Permalink
feat: mutate platform (#1919)
Browse files Browse the repository at this point in the history
Signed-off-by: Josh W Lewis <[email protected]>
  • Loading branch information
joshwlewis authored May 5, 2024
1 parent 98dd3e9 commit ff385a9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
17 changes: 16 additions & 1 deletion cmd/crane/cmd/mutate.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func NewCmdMutate(options *[]crane.Option) *cobra.Command {
var user string
var workdir string
var ports []string
var newPlatform string

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

// Set platform
if len(newPlatform) > 0 {
platform, err := parsePlatform(newPlatform)
if err != nil {
return err
}
cfg.OS = platform.OS
cfg.Architecture = platform.Architecture
cfg.Variant = platform.Variant
cfg.OSVersion = platform.OSVersion
}

// Mutate and write image.
img, err = mutate.Config(img, cfg.Config)
img, err = mutate.ConfigFile(img, cfg)
if err != nil {
return fmt.Errorf("mutating config: %w", err)
}
Expand Down Expand Up @@ -183,6 +196,8 @@ func NewCmdMutate(options *[]crane.Option) *cobra.Command {
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")
// Using "set-platform" to avoid clobbering "platform" persistent flag.
mutateCmd.Flags().StringVar(&newPlatform, "set-platform", "", "New platform to set in the form os/arch[/variant][:osversion] (e.g. linux/amd64)")
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 ff385a9

Please sign in to comment.