Skip to content

Commit

Permalink
Merge pull request #129 from sorenisanerd/docker-platforms
Browse files Browse the repository at this point in the history
Allow specifying Docker build platforms
  • Loading branch information
SuperSandro2000 authored Nov 14, 2023
2 parents b53c870 + 3030cae commit 8e787a8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,12 @@ sheet][ref-pattern-cheat-sheet]. This option is not defined by default.

If `enabled` is set to true, the generated `Dockerfile` is build and pushed to repository path under `ghcr.io`.

To build for more or other platforms than the default (linux/amd64), you can set the `platforms` field to a list of platforms to build for. The format is the same as for the `--platform` flag of `docker buildx build`.

```yaml
pushContainerToGhcr:
enabled: true
platforms: linux/amd64,linux/arm64
```

### `githubWorkflow.release`
Expand Down
3 changes: 2 additions & 1 deletion internal/core/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ type LicenseWorkflowConfig struct {
}

type PushContainerToGhcrConfig struct {
Enabled bool `yaml:"enabled"`
Enabled bool `yaml:"enabled"`
Platforms string `yaml:"platforms"`
}

type ReleaseWorkflowConfig struct {
Expand Down
2 changes: 2 additions & 0 deletions internal/core/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const (

DockerLoginAction = "docker/login-action@v3"
DockerMetadataAction = "docker/metadata-action@v5"
DockerBuildxAction = "docker/setup-buildx-action@v3"
DockerQemuAction = "docker/setup-qemu-action@v3"
DockerBuildPushAction = "docker/build-push-action@v5"

CodeqlInitAction = "github/codeql-action/init@v2"
Expand Down
27 changes: 21 additions & 6 deletions internal/ghworkflow/workflow_ghcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,30 @@ type=semver,pattern=v{{major}}.{{minor}}
type=semver,pattern=v{{major}}`,
},
})

buildPushWith := map[string]any{
"context": ".",
"push": true,
"tags": "${{ steps.meta.outputs.tags }}",
"labels": "${{ steps.meta.outputs.labels }}",
}

if cfg.PushContainerToGhcr.Platforms != "" {
j.addStep(jobStep{
Name: "Set up QEMU",
Uses: core.DockerQemuAction,
})
j.addStep(jobStep{
Name: "Set up Docker Buildx",
Uses: core.DockerBuildxAction,
})
buildPushWith["platforms"] = cfg.PushContainerToGhcr.Platforms
}

j.addStep(jobStep{
Name: "Build and push Docker image",
Uses: core.DockerBuildPushAction,
With: map[string]any{
"context": ".",
"push": true,
"tags": "${{ steps.meta.outputs.tags }}",
"labels": "${{ steps.meta.outputs.labels }}",
},
With: buildPushWith,
})
w.Jobs = map[string]job{"build-and-push-image": j}

Expand Down

0 comments on commit 8e787a8

Please sign in to comment.