Skip to content

Commit 8395371

Browse files
adding recommendations
1 parent 6009ebe commit 8395371

File tree

5 files changed

+60
-82
lines changed

5 files changed

+60
-82
lines changed

actions/docker-build-push-image/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
contents: read
3737
id-token: write
3838
steps:
39-
- uses: grafana/shared-workflows/actions/docker-build-push-image@main # TODO: Fix version once released
39+
- uses: grafana/shared-workflows/actions/docker-build-push-image@docker-build-push-image/v0.0.0
4040
with:
4141
platforms: linux/arm64,linux/amd64
4242
tags: |
@@ -109,8 +109,6 @@ The full DockerHub image is constructed as follows:
109109

110110
## Adding New Registries
111111

112-
This is currently configured to push to:
113-
114112
Each registry is setup as follows:
115113

116114
- All inputs for a registry share the same prefix (ex: `gar-image`, `gar-repository`).

actions/docker-build-push-image/action.yaml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ runs:
218218
PUSH: ${{ inputs.push }}
219219
run: |
220220
#############################################################
221-
# This constructs as CSV list of images from the previous
221+
# This constructs a CSV list of images from the previous
222222
# setup steps, and outputs that list
223223
#
224224
# If there are no images then we set images="dry-run-image"
@@ -276,13 +276,6 @@ runs:
276276
DEFAULT_BUILDKITD_CONFIG: /etc/buildkitd.toml
277277
RUNNER_ENVIRONMENT: ${{ runner.environment }}
278278
run: |
279-
#############################################################
280-
# This step does the following:
281-
# if buildkitd-config-inline != "", use that
282-
# elif buildkitd-config != "", use that
283-
# else, use buildkitd-config default config if on self hosted runners
284-
#############################################################
285-
286279
buildkitd_config=""
287280
buildkitd_config_inline=""
288281
@@ -361,7 +354,7 @@ runs:
361354
rm -rf _shared-workflows-docker-build-push-image
362355
363356
- name: Delete Google Application Credentials file
364-
if: ${{ inputs.gar-delete-credentials-file == 'true' && env.GOOGLE_APPLICATION_CREDENTIALS != '' }}
357+
if: ${{ always() && inputs.gar-delete-credentials-file == 'true' && env.GOOGLE_APPLICATION_CREDENTIALS != '' }}
365358
shell: sh
366359
run: |
367360
if [ -f "${GOOGLE_APPLICATION_CREDENTIALS}" ]; then

actions/docker-export-digest/README.md

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# docker-export-digest
22

3-
This is a composite GitHub Action used to export a docker digest as a workflow artifact, so it can be merged and pushed
4-
as part of a manifest.
3+
This is a composite GitHub Action used to export a docker digest as a workflow artifact.
54

6-
This is meant to work in conjunction with [docker-build-push-image] and [docker-import-digests-push-manifest].
5+
This can be used in conjunction with [docker-build-push-image] and [docker-import-digests-push-manifest] to build
6+
native multi-arch Docker images.
77

88
[docker/build-push-action]: https://github.com/docker/build-push-action
99
[docker-build-push-image]: ../docker-build-push-image/README.md
@@ -21,45 +21,16 @@ on:
2121
- main
2222

2323
jobs:
24-
build-push-image:
25-
outputs:
26-
images: ${{ steps.build.outputs.images }}
24+
upload-digest-as-artifact:
2725
permissions:
2826
contents: read
2927
id-token: write
3028
steps:
31-
- name: Build Docker Image
32-
id: build
33-
uses: grafana/shared-workflows/actions/docker-build-push-image@main # TODO: Fix version once released
34-
with:
35-
platforms: linux/arm64
36-
tags: |
37-
${{ github.sha }}
38-
main
39-
push: true
40-
registries: "gar,dockerhub"
41-
include-tags-in-push: false
42-
outputs: "type=image,push-by-digest=true,name-canonical=true,push=true"
4329
- name: Export and upload digest
44-
uses: grafana/shared-workflows/actions/docker-export-digest@rwhitaker/multi-arch-builds # TODO: Fix version once released
30+
uses: grafana/shared-workflows/actions/docker-export-digest@docker-export-digest/v0.0.0
4531
with:
46-
digest: ${{ steps.build.outputs.digest }}
32+
digest: ${{ steps.docker-build-push-image.outputs.digest }}
4733
platform: linux/arm64
48-
merge-digest:
49-
if: ${{ inputs.push == 'true' }}
50-
runs-on: ubuntu-arm64-small
51-
needs: build-and-push
52-
permissions:
53-
contents: read
54-
id-token: write
55-
steps:
56-
- name: Download Multi-Arch Digests, Construct and Upload Manifest
57-
uses: grafana/shared-workflows/actions/docker-import-digests-push-manifest@main # TODO: Pin sha
58-
with:
59-
images: ${{ needs.build-push-image.outputs.images }}
60-
gar-environment: "dev"
61-
registries: "gar,dockerhub"
62-
docker-metadata-json: ${{ needs.build-and-push.outputs.metadatajson }}
6334
```
6435
6536
<!-- x-release-please-end-version -->

actions/docker-import-digests-push-manifest/README.md

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
This is a composite GitHub Action used to import Docker digests from a shared workflow artifact and merge them into a
44
tagged manifest.
55

6-
This is meant to work in conjunction with [docker-build-push-image] and [docker-export-digest].
6+
This can be used in conjunction with [docker-build-push-image] and [docker-export-digest] to build
7+
native multi-arch Docker images.
78

89
[docker/build-push-action]: https://github.com/docker/build-push-action
910
[docker-build-push-image]: ../docker-build-push-image/README.md
@@ -21,45 +22,18 @@ on:
2122
- main
2223

2324
jobs:
24-
build-push-image:
25-
outputs:
26-
images: ${{ steps.build.outputs.images }}
27-
permissions:
28-
contents: read
29-
id-token: write
30-
steps:
31-
- name: Build Docker Image
32-
id: build
33-
uses: grafana/shared-workflows/actions/docker-build-push-image@main # TODO: Fix version once released
34-
with:
35-
platforms: linux/arm64
36-
tags: |
37-
${{ github.sha }}
38-
main
39-
push: true
40-
registries: "gar,dockerhub"
41-
include-tags-in-push: false
42-
outputs: "type=image,push-by-digest=true,name-canonical=true,push=true"
43-
- name: Export and upload digest
44-
uses: grafana/shared-workflows/actions/docker-export-digest@rwhitaker/multi-arch-builds # TODO: Fix version once released
45-
with:
46-
digest: ${{ steps.build.outputs.digest }}
47-
platform: linux/arm64
48-
merge-digest:
49-
if: ${{ inputs.push == 'true' }}
50-
runs-on: ubuntu-arm64-small
51-
needs: build-and-push
25+
import-and-merge-digest:
5226
permissions:
5327
contents: read
5428
id-token: write
5529
steps:
5630
- name: Download Multi-Arch Digests, Construct and Upload Manifest
57-
uses: grafana/shared-workflows/actions/docker-import-digests-push-manifest@main # TODO: Pin sha
31+
uses: grafana/shared-workflows/actions/docker-import-digests-push-manifest@docker-import-digests-push-manifest/v0.0.0
5832
with:
59-
images: ${{ needs.build-push-image.outputs.images }}
33+
docker-metadata-json: ${{ needs.docker-build-push-image.outputs.metadatajson }}
6034
gar-environment: "dev"
61-
registries: "gar,dockerhub"
62-
docker-metadata-json: ${{ needs.build-and-push.outputs.metadatajson }}
35+
images: ${{ needs.docker-build-push-image.outputs.images }}
36+
push: true
6337
```
6438
6539
<!-- x-release-please-end-version -->

actions/docker-import-digests-push-manifest/action.yaml

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,54 @@ runs:
4848
driver: docker-container
4949
version: latest # see https://github.com/docker/build-push-action/issues/1345#issuecomment-2770572479
5050

51-
- name: Login to GAR
51+
- name: Prepare vars
52+
id: prepare-vars
5253
if: ${{ inputs.push == 'true' }}
54+
env:
55+
IMAGES: ${{ inputs.images }}
56+
shell: bash
57+
run: |
58+
set -euo pipefail
59+
60+
DOCKERHUB_IMAGE=false
61+
GAR_IMAGE=false
62+
63+
IFS=',' read -ra IMAGE_LIST <<< "${IMAGES}"
64+
65+
for image in "${IMAGE_LIST[@]}"; do
66+
image="$(echo "$image" | xargs)" # trim spaces
67+
registry="${image%%/*}" # everything before first slash
68+
echo "Verifying image: $image"
69+
echo "Verifying registry: $registry"
70+
71+
# Default if there's no dot or colon (Docker Hub shorthand)
72+
if [[ "$registry" != *.* && "$registry" != *:* ]]; then
73+
DOCKERHUB_IMAGE=true
74+
fi
75+
76+
if [[ "$registry" == *".pkg.dev" ]] || [[ "$registry" == *"gcr.io" ]]; then
77+
echo "$image → Google Artifact Registry"
78+
GAR_IMAGE=true
79+
elif [[ "$registry" == "docker.io" ]] || [[ "$registry" == "index.docker.io" ]]; then
80+
echo "$image → DockerHub"
81+
DOCKERHUB_IMAGE=true
82+
else
83+
echo "$image → Other registry ($registry)"
84+
fi
85+
done
86+
87+
if [[ "$DOCKERHUB_IMAGE" == "true" ]]; then
88+
echo "include-dockerhub=true" | tee -a "${GITHUB_OUTPUT}"
89+
elif [[ "$GAR_IMAGE" == "true" ]]; then
90+
echo "include-gar=true" | tee -a "${GITHUB_OUTPUT}"
91+
fi
92+
93+
- name: Login to GAR
94+
if: ${{ steps.prepare-vars.outputs.include-gar == 'true' }}
5395
uses: ./_shared-workflows-docker-import-digests-push-manifest/actions/login-to-gar
5496

5597
- name: Login to DockerHub
56-
if: ${{ inputs.push == 'true' }}
98+
if: ${{ steps.prepare-vars.outputs.include-dockerhub == 'true' }}
5799
uses: ./_shared-workflows-docker-import-digests-push-manifest/actions/dockerhub-login
58100

59101
- name: Create manifest list and push

0 commit comments

Comments
 (0)