Skip to content

Commit dc63f80

Browse files
fix
1 parent ba6a505 commit dc63f80

File tree

1 file changed

+50
-28
lines changed

1 file changed

+50
-28
lines changed
Lines changed: 50 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
name: Build and Push Intermediary Docker Image
22

33
on:
4-
push:
54
workflow_dispatch:
65

6+
concurrency:
7+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
8+
cancel-in-progress: true
9+
710
permissions:
8-
contents: write
11+
contents: read
912
packages: write
1013

1114
env:
@@ -22,31 +25,53 @@ jobs:
2225
- linux/amd64
2326
- linux/arm64
2427
outputs:
25-
IMAGE_NAME: ${{ steps.vars.outputs.IMAGE_NAME }}
26-
IMAGE_TAG: ${{ steps.vars.outputs.IMAGE_TAG }}
28+
IMAGE_NAME: ${{ steps.image_builder.outputs.IMAGE }}
29+
TAGS: ${{ steps.meta.outputs.tags }}
30+
VERSION: ${{ steps.meta.outputs.version }}
31+
2732
steps:
2833
- name: Checkout
2934
uses: actions/checkout@v4
3035

31-
- name: Set image tag
36+
- name: Prepare platform safe variable
37+
run: |
38+
platform=${{ matrix.platform }}
39+
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
40+
41+
- name: Set image tag components
3242
id: vars
3343
run: |
3444
BRANCH_NAME=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}
3545
BRANCH=$(echo "$BRANCH_NAME" | tr '/' '-')
3646
TIMESTAMP=$(date -u +'%d_%m_%Y_%H_%M')
3747
SHORT_SHA=$(git rev-parse --short HEAD)
3848
IMAGE_TAG="${BRANCH}_${TIMESTAMP}_${SHORT_SHA}"
39-
IMAGE_NAME="${{ env.REGISTRY_IMAGE }}:${IMAGE_TAG}"
49+
FULL_IMAGE="${{ env.REGISTRY_IMAGE }}:${IMAGE_TAG}"
4050
echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_OUTPUT
41-
echo "IMAGE_NAME=$IMAGE_NAME" >> $GITHUB_OUTPUT
51+
echo "FULL_IMAGE=$FULL_IMAGE" >> $GITHUB_OUTPUT
52+
53+
- name: Docker metadata
54+
id: meta
55+
uses: docker/metadata-action@v5
56+
with:
57+
images: ${{ env.REGISTRY_IMAGE }}
58+
tags: |
59+
${IMAGE_TAG}
60+
61+
- name: Image name builder
62+
id: image_builder
63+
run: |
64+
# We override default jq usage to pick our custom IMAGE_TAG
65+
IMAGE="${{ env.REGISTRY_IMAGE }}:${{ steps.vars.outputs.IMAGE_TAG }}"
66+
echo "IMAGE=$IMAGE" >> $GITHUB_OUTPUT
4267
4368
- name: Set up QEMU
4469
uses: docker/setup-qemu-action@v3
4570

4671
- name: Set up Docker Buildx
4772
uses: docker/setup-buildx-action@v3
4873

49-
- name: Login to GHCR
74+
- name: Login to GitHub Container Registry
5075
uses: docker/login-action@v3
5176
with:
5277
registry: ${{ env.REGISTRY }}
@@ -58,34 +83,26 @@ jobs:
5883
uses: docker/build-push-action@v6
5984
with:
6085
context: .
61-
push: false
6286
platforms: ${{ matrix.platform }}
87+
push: true
88+
labels: ${{ steps.meta.outputs.labels }}
6389
cache-from: type=gha
6490
cache-to: type=gha,mode=max
65-
outputs: type=image,name=${{ steps.vars.outputs.IMAGE_NAME }},push-by-digest=true,push=true
91+
outputs: type=image,name=${{ steps.image_builder.outputs.IMAGE }},push-by-digest=true
6692

6793
- name: Export digest
6894
run: |
6995
mkdir -p /tmp/digests
70-
digest="${{ steps.build.outputs.digest }}"
71-
touch "/tmp/digests/${digest#sha256:}"
72-
73-
- name: Set digest file name
74-
id: digest_vars
75-
run: |
76-
PLATFORM_SAFE=$(echo "${{ matrix.platform }}" | tr '/' '-')
77-
echo "PLATFORM_SAFE=$PLATFORM_SAFE" >> $GITHUB_OUTPUT
96+
echo "${{ steps.build.outputs.digest }}" > "/tmp/digests/${PLATFORM_PAIR}.txt"
7897
7998
- name: Upload digest
8099
uses: actions/upload-artifact@v4
81100
with:
82-
name: digests-${{ steps.digest_vars.outputs.PLATFORM_SAFE }}
101+
name: digests-${{ env.PLATFORM_PAIR }}
83102
path: /tmp/digests/*
84-
if-no-files-found: error
85-
retention-days: 1
86103

87104
merge:
88-
runs-on: arm-runner-2204
105+
runs-on: amd-runner-2204
89106
needs: build
90107
steps:
91108
- name: Download digests
@@ -98,19 +115,24 @@ jobs:
98115
- name: Set up Docker Buildx
99116
uses: docker/setup-buildx-action@v3
100117

101-
- name: Login to GHCR
118+
- name: Login to GitHub Container Registry
102119
uses: docker/login-action@v3
103120
with:
104121
registry: ${{ env.REGISTRY }}
105122
username: ${{ github.actor }}
106123
password: ${{ secrets.GITHUB_TOKEN }}
107124

108-
- name: Create and push manifest list
125+
- name: Create manifest list and push
109126
working-directory: /tmp/digests
110127
run: |
111-
IMAGE="${{ needs.build.outputs.IMAGE_NAME }}"
112-
docker buildx imagetools create -t "$IMAGE" $(printf "${IMAGE}@sha256:%s " *)
113-
114-
- name: Inspect image
128+
# Compose manifest create arguments from digest files
129+
DIGEST_ARGS=""
130+
for file in digests-*.txt; do
131+
digest=$(cat "$file")
132+
DIGEST_ARGS+=" ${{ needs.build.outputs.IMAGE_NAME }}@$digest"
133+
done
134+
docker buildx imagetools create -t ${{ needs.build.outputs.IMAGE_NAME }} $DIGEST_ARGS
135+
136+
- name: Inspect final image
115137
run: |
116138
docker buildx imagetools inspect ${{ needs.build.outputs.IMAGE_NAME }}

0 commit comments

Comments
 (0)