From 59e09c14de23515b953786c4d959551387d20d0f Mon Sep 17 00:00:00 2001 From: Shubham Agrawal Date: Wed, 1 Dec 2021 17:10:28 +0530 Subject: [PATCH] Add support for custom platform (#32) --- cmd/kaniko-docker/main.go | 6 ++++++ cmd/kaniko-ecr/main.go | 6 ++++++ cmd/kaniko-gcr/main.go | 6 ++++++ kaniko.go | 5 +++++ 4 files changed, 23 insertions(+) diff --git a/cmd/kaniko-docker/main.go b/cmd/kaniko-docker/main.go index b59cf05..6169075 100644 --- a/cmd/kaniko-docker/main.go +++ b/cmd/kaniko-docker/main.go @@ -145,6 +145,11 @@ func main() { Usage: "Set this flag with value as oneof to set the logging level for kaniko. Defaults to info.", EnvVar: "PLUGIN_VERBOSITY", }, + cli.StringFlag{ + Name: "platform", + Usage: "Allows to build with another default platform than the host, similarly to docker build --platform", + EnvVar: "PLUGIN_PLATFORM", + }, } if err := app.Run(os.Args); err != nil { @@ -181,6 +186,7 @@ func run(c *cli.Context) error { DigestFile: defaultDigestFile, NoPush: noPush, Verbosity: c.String("verbosity"), + Platform: c.String("platform"), }, Artifact: kaniko.Artifact{ Tags: c.StringSlice("tags"), diff --git a/cmd/kaniko-ecr/main.go b/cmd/kaniko-ecr/main.go index f6b57ff..48fea83 100644 --- a/cmd/kaniko-ecr/main.go +++ b/cmd/kaniko-ecr/main.go @@ -174,6 +174,11 @@ func main() { Usage: "Set this flag with value as oneof to set the logging level for kaniko. Defaults to info.", EnvVar: "PLUGIN_VERBOSITY", }, + cli.StringFlag{ + Name: "platform", + Usage: "Allows to build with another default platform than the host, similarly to docker build --platform", + EnvVar: "PLUGIN_PLATFORM", + }, } if err := app.Run(os.Args); err != nil { @@ -252,6 +257,7 @@ func run(c *cli.Context) error { DigestFile: defaultDigestFile, NoPush: noPush, Verbosity: c.String("verbosity"), + Platform: c.String("platform"), }, Artifact: kaniko.Artifact{ Tags: c.StringSlice("tags"), diff --git a/cmd/kaniko-gcr/main.go b/cmd/kaniko-gcr/main.go index f96060c..1492a7b 100644 --- a/cmd/kaniko-gcr/main.go +++ b/cmd/kaniko-gcr/main.go @@ -130,6 +130,11 @@ func main() { Usage: "Set this flag as --verbosity= to set the logging level for kaniko. Defaults to info.", EnvVar: "PLUGIN_VERBOSITY", }, + cli.StringFlag{ + Name: "platform", + Usage: "Allows to build with another default platform than the host, similarly to docker build --platform", + EnvVar: "PLUGIN_PLATFORM", + }, } if err := app.Run(os.Args); err != nil { @@ -167,6 +172,7 @@ func run(c *cli.Context) error { DigestFile: defaultDigestFile, NoPush: noPush, Verbosity: c.String("verbosity"), + Platform: c.String("platform"), }, Artifact: kaniko.Artifact{ Tags: c.StringSlice("tags"), diff --git a/kaniko.go b/kaniko.go index 7e7aa14..78d1f97 100644 --- a/kaniko.go +++ b/kaniko.go @@ -30,6 +30,7 @@ type ( DigestFile string // Digest file location NoPush bool // Set this flag if you only want to build the image, without pushing to a registry Verbosity string // Log level + Platform string // Allows to build with another default platform than the host, similarly to docker build --platform } // Artifact defines content of artifact file @@ -157,6 +158,10 @@ func (p Plugin) Exec() error { cmdArgs = append(cmdArgs, fmt.Sprintf("--verbosity=%s", p.Build.Verbosity)) } + if p.Build.Platform != "" { + cmdArgs = append(cmdArgs, fmt.Sprintf("--customPlatform=%s", p.Build.Platform)) + } + cmd := exec.Command("/kaniko/executor", cmdArgs...) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr