Skip to content

Commit

Permalink
feat: docker build platform flag
Browse files Browse the repository at this point in the history
  • Loading branch information
andrejpetras committed Feb 2, 2024
1 parent aef76e6 commit cc09bd8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions cmd/docker_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type dockerBuildFlags struct {
File string `mapstructure:"docker-file"`
Profile string `mapstructure:"docker-profile"`
Context string `mapstructure:"docker-context"`
Platform string `mapstructure:"docker-platform"`
SkipDevBuild bool `mapstructure:"docker-skip-dev"`
SkipPull bool `mapstructure:"docker-skip-pull"`
BuildPush bool `mapstructure:"docker-build-push"`
Expand All @@ -35,6 +36,7 @@ func createDockerBuildCmd() *cobra.Command {
addStringFlag(cmd, "docker-file", "d", "src/main/docker/Dockerfile", "path of the project Dockerfile")
addStringFlag(cmd, "docker-profile", "", "", "profile of the Dockerfile.<profile>")
addStringFlag(cmd, "docker-context", "", ".", "the docker build context")
addStringFlag(cmd, "docker-platform", "", "", "the docker build platform")
addBoolFlag(cmd, "docker-skip-pull", "", false, "skip docker pull new images for the build")
addBoolFlag(cmd, "docker-build-push", "", false, "push docker image after build")
addBoolFlag(cmd, "docker-skip-dev", "", false, "skip build image {{ .Name }}:latest")
Expand Down Expand Up @@ -77,6 +79,9 @@ func dockerBuild(project *Project, flags dockerBuildFlags) {
command = append(command, "--rm")
}

if len(flags.Platform) > 0 {
command = append(command, "--platform", flags.Platform)
}
// create labels
labels := dockerLabels(project, flags.Docker.Project.SkipLabels, flags.Docker.SkipOpenContainersLabels, flags.Docker.Project.LabelTemplate)
for key, value := range labels {
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/lorislab/samo

go 1.19
go 1.21

toolchain go1.21.4

require (
github.com/Masterminds/semver/v3 v3.2.1
Expand Down

0 comments on commit cc09bd8

Please sign in to comment.