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

feat: crane mutate platform #1919

Merged
merged 1 commit into from May 5, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 16 additions & 1 deletion cmd/crane/cmd/mutate.go
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.