Skip to content

Commit 4101b7f

Browse files
feat: docker multi-arch reusable workflow (#1348)
* docker-build-push-multiarch initial commit * Docs updates for docker-build-push-multiarch * update to point to new composite action branch * Convert merge-digest to run when push is false (handled in action) * remove delete-credentials-file input * Readme link updates * Update inputs to match downstream docker-build-push-image composite action * Update help text and platform mapping strategy for docker-build-push-multiarch * Update help text and platform mapping strategy for docker-build-push-multiarch * Update help text and platform mapping strategy for docker-build-push-multiarch * Update help text and platform mapping strategy for docker-build-push-multiarch * Update help text and platform mapping strategy for docker-build-push-multiarch * Update help text and platform mapping strategy for docker-build-push-multiarch * Update help text and platform mapping strategy for docker-build-push-multiarch * Update help text and platform mapping strategy for docker-build-push-multiarch * Update help text and platform mapping strategy for docker-build-push-multiarch * Fix missing metadata in docker-import-digests-push-manifest * apply recommended changes * add spellcheck disable * update docs * Fix composite action references * pin docker action shas * remove pre and post build steps
1 parent 39e279f commit 4101b7f

File tree

2 files changed

+423
-0
lines changed

2 files changed

+423
-0
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# docker-build-push-multiaarch
2+
3+
This is a reusable workflow that uses Grafana's hosted runners to natively build and push multi-architecture docker
4+
images.
5+
6+
Right now this supports pushing images to:
7+
8+
- Google Artifact Registry
9+
- DockerHub
10+
11+
And supports building the following image types:
12+
13+
- linux/arm64
14+
- linux/amd64
15+
16+
## How it works
17+
18+
This generates a matrix based off of the `platforms` input, then creates a job per platform that runs the composite
19+
actions [docker-build-push-image] and [docker-export-digest] to build and push docker images, and capture their digests.
20+
There is then a final job that runs the composite action [docker-import-digests-push-manifest] to push the docker
21+
manifest.
22+
23+
[docker/build-push-action]: https://github.com/docker/build-push-action
24+
[docker-build-push-image]: ../../docker-build-push-image/README.md
25+
[docker-export-digest]: ../../docker-export-digest/README.md
26+
[docker-import-digests-push-manifest]: ../../docker-import-digests-push-manifest/README.md
27+
28+
<!-- x-release-please-start-version -->
29+
30+
```yaml
31+
name: Build and Push and Push MultiArch
32+
33+
on: push
34+
35+
jobs:
36+
build-push-multiarch:
37+
uses: grafana/shared-workflows/.github/workflows/build-and-push-docker-multiarch.yml@rwhitaker/multi-arch-builds # TODO: Pin to version
38+
with:
39+
platforms: linux/arm64,linux/amd64
40+
tags: |
41+
${{ github.sha }}
42+
rickytest
43+
push: true
44+
registries: "gar,dockerhub"
45+
pre-build-script: scripts/ci-build.sh
46+
```
47+
48+
<!-- x-release-please-end-version -->
49+
50+
## Inputs
51+
52+
| Name | Type | Description |
53+
| ----------------------------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
54+
| `build-args` | string | List of arguments necessary for the Docker image to be built. Passed to `docker/build-push-action`. |
55+
| `build-contexts` | string | List of additional build contexts (e.g., name=path). Passed to `docker/build-push-action`. |
56+
| `buildkitd-config` | string | The buildkitd config file to use. Defaults to `/etc/buildkitd.toml` if you're using Grafana's self-hosted runners. Passed to `docker/setup-buildx-action`. |
57+
| `buildkitd-config-inline` | string | The buildkitd inline config to use. Passed to `docker/setup-buildx-action`. |
58+
| `cache-from` | string | Where cache should be fetched from. Passed to `docker/build-push-action`. |
59+
| `cache-to` | string | Where cache should be stored to. Passed to `docker/build-push-action`. |
60+
| `context` | string | Path to the Docker build context. Passed to `docker/build-push-action`. |
61+
| `docker-buildx-driver` | string | The driver to use for Docker Buildx. Passed to `docker/setup-buildx-action`. |
62+
| `dockerhub-registry` | string | DockerHub Registry to store docker images in. |
63+
| `dockerhub-repository` | string | DockerHub Repository to store docker images in. Default: github.repository |
64+
| `file` | string | The dockerfile to use. Passed to `docker/build-push-action`. |
65+
| `gar-delete-credentials-file` | string | Delete the Google credentials file after the action is finished. If you want to keep the credentials file for a later step, set this to false. |
66+
| `gar-environment` | string | Environment for pushing artifacts (can be either dev or prod). This sets the GAR Project (gar-project) to either `grafanalabs-dev` or `grafanalabs-global`. |
67+
| `gar-image` | string | Name of the image to build. Default: `${GitHub Repo Name}`. |
68+
| `gar-registry` | string | Google Artifact Registry to store docker images in. |
69+
| `gar-repository` | string | Override the 'repo_name' used to construct the GAR repository name. Only necessary when the GAR includes a repo name that doesn't match the GitHub repo name. Default: `docker-${GitHub Repo Name}-${gar-environment}` |
70+
| `include-tags-in-push` | string | Disables the pushing of tags, and instead includes just a list of images as docker tags. Used when pushing docker digests instead of docker tags. |
71+
| `labels` | string | List of custom labels to add to the image as metadata (passed to `docker/build-push-action`). Passed to `docker/build-push-action`. |
72+
| `load` | string | Whether to load the built image into the local docker daemon (passed to `docker/build-push-action`). Passed to `docker/build-push-action`. |
73+
| `outputs` | string | List of docker output destinations. Passed to `docker/build-push-action`. |
74+
| `platforms` | string | List of platforms to build the image for. Passed to `docker/build-push-action`. |
75+
| `push` | string | Whether to push the image to the configured registries. Passed to `docker/build-push-action`. |
76+
| `registries` | string | CSV list of registries to build images for. Accepted registries are "gar" and "dockerhub". |
77+
| `secrets` | string | Secrets to expose to the build. Only needed when authenticating to private repositories outside the repository in which the image is being built. Passed to `docker/build-push-action`. |
78+
| `server-size` | string | Size of the Grafana self-hosted runner |
79+
| `ssh` | string | List of SSH agent socket or keys to expose to the build Passed to `docker/build-push-action`. |
80+
| `tags` | string | List of Docker tags to be pushed. Passed to `docker/build-push-action`. |
81+
| `target` | string | Sets the target stage to build. Passed to `docker/build-push-action`. |
82+
83+
## Outputs
84+
85+
| Name | Type | Description |
86+
| --------------- | ------ | ------------------------------------------------------------------------ |
87+
| `annotations` | String | Generated annotations (from docker/metadata-action) |
88+
| `digest` | String | Image digest (from docker/build-push-action) |
89+
| `imageid` | String | Image ID (from docker/build-push-action) |
90+
| `images` | String | Comma separated list of the images that were built |
91+
| `json` | String | JSON output of tags and labels (from docker/metadata-action) |
92+
| `labels` | String | Generated Docker labels (from docker/metadata-action) |
93+
| `metadata` | String | Build result metadata (from docker/build-push-action) |
94+
| `runner_arches` | String | The list of OS used to build images (for mapping to self hosted runners) |
95+
| `tags` | String | Generated Docker tags (from docker/metadata-action) |
96+
| `version` | String | Generated Docker image version (from docker/metadata-action) |

0 commit comments

Comments
 (0)