Skip to content

Commit 1c851ba

Browse files
committed
ci: fix multi-arch images push
1 parent 409d823 commit 1c851ba

File tree

3 files changed

+43
-11
lines changed

3 files changed

+43
-11
lines changed

.github/actions/docker-tags-merge/action.yml

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,28 @@ inputs:
1313
platform_arm64:
1414
description: Target image platform for AMD64 architecture
1515
required: true
16+
outputs:
17+
short_image_name:
18+
description: "The image name without tag"
19+
value: ${{ steps.prepare-image.outputs.short_image_name }}
20+
image_tags:
21+
description: "List of computed image tags"
22+
value: ${{ steps.fetch-tags.outputs.image_tags }}
1623

1724
runs:
1825
using: "composite"
1926
steps:
2027

2128
- name: Prepare image push 📦
29+
id: prepare-image
2230
run: |
23-
# The short image name (without tag) is necessary to push to the registry
24-
echo "SHORT_IMAGE_NAME=${{ inputs.image }}" | awk -F: '{print $1}' >> $GITHUB_ENV
31+
short_name=$(echo "${{ inputs.image }}" | awk -F: '{print $1}')
32+
echo "Short image name: $short_name"
33+
echo "short_image_name=$short_name" >> $GITHUB_OUTPUT
2534
shell: bash
2635

27-
# Pull the images locally for the two platforms: amd64 and arm64
36+
# Pull the images locally for the two architectures: amd64 and arm64
37+
# These images are already built and pushed separately by the appropriate github runners (amd64 and arm64)
2838
- name: Pull ${{ inputs.image }} image for ${{ inputs.platform_amd64 }} platform ⬇️
2939
run: |
3040
docker pull --platform=linux/${{ inputs.platform_amd64 }} ${{ inputs.registry }}/$OWNER/${{ inputs.image }}-${{ inputs.platform_amd64 }}
@@ -35,7 +45,7 @@ runs:
3545
docker pull --platform=linux/${{ inputs.platform_arm64 }} ${{ inputs.registry }}/$OWNER/${{ inputs.image }}-${{ inputs.platform_arm64 }}
3646
shell: bash
3747

38-
# Apply tags
48+
# Apply okdp tags to the AMD64 image.
3949
- name: Apply tags to ${{ inputs.image }} image and platform ${{ inputs.platform_amd64 }} 🏷
4050
run: |
4151
python3 -m okdp.extension.tagging.apply_tags --image-name ${{ inputs.image }} \
@@ -44,21 +54,33 @@ runs:
4454
--platform ${{ inputs.platform_amd64 }}
4555
shell: bash
4656

57+
# Extract the list of base image tags (without the architecture suffix) from the locally pulled AMD64 images.
4758
- name: Fetch all tags for ${{ inputs.image }} image and platform ${{ inputs.platform_amd64 }} 🏷
59+
id: fetch-tags
4860
run: |
49-
tags=$(docker images ${{ inputs.registry }}/$OWNER/$SHORT_IMAGE_NAME \
61+
tags=$(docker images ${{ inputs.registry }}/$OWNER/${{ steps.prepare-image.outputs.short_image_name }} \
5062
--format "{{.Repository}}:{{.Tag}}" \
5163
| grep -v -- "-${{ inputs.platform_arm64 }}$" \
5264
| sed "s/-${{ inputs.platform_amd64 }}$//" \
5365
| tr '\n' ' ')
54-
echo "IMAGE_TAGS=$tags" >> $GITHUB_ENV
66+
echo "Found image tags: $tags"
67+
echo "image_tags=$tags" >> $GITHUB_OUTPUT
5568
shell: bash
5669

70+
# Apply the previously extracted base tags to the ARM64 image by adding the correct architecture suffix.
71+
# This ensures that every ARM64 image receives the same tag set as the AMD64 images.
5772
- name: Apply tags to ${{ inputs.image }} image and platform ${{ inputs.platform_arm64 }} 🏷
5873
run: |
59-
for tag in $IMAGE_TAGS
74+
for tag in ${{ steps.fetch-tags.outputs.image_tags }}
6075
do
6176
docker tag ${{ inputs.registry }}/$OWNER/${{ inputs.image }}-${{ inputs.platform_arm64 }} ${tag}-${{ inputs.platform_arm64 }}
6277
done
6378
shell: bash
6479

80+
# Display all tags for the image to verify uniform tagging across architectures.
81+
# Provide a final overview of every generated tag after the tagging process.
82+
- name: Show all the image tags for the two architectures (AMD64 and ARM64) 📋
83+
run: |
84+
docker images --all
85+
shell: bash
86+

.github/workflows/build-image-template.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,9 @@ jobs:
160160

161161
- name: Build image 🛠
162162
run: |
163-
docker build --rm --force-rm --tag $REGISTRY/$OWNER/${{ inputs.image }}-${{ inputs.platform }} \
163+
docker buildx build --platform=linux/${{ inputs.platform }} --rm --force-rm --tag $REGISTRY/$OWNER/${{ inputs.image }}-${{ inputs.platform }} \
164164
--tag $REGISTRY/$OWNER/$SHORT_IMAGE_NAME:latest images/$SHORT_IMAGE_NAME/ \
165+
--output=type=docker --sbom=false --provenance=false \
165166
--build-arg REGISTRY=$REGISTRY \
166167
--build-arg OWNER=$OWNER $BUILD_ARGS \
167168
--label "org.opencontainers.image.source=https://github.com/${{ github.repository }}" \

.github/workflows/push-image-template.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ jobs:
113113
shell: bash
114114

115115
- name: Merge ${{ inputs.platform_amd64 }} and ${{ inputs.platform_arm64 }} image tags
116+
id: merge-tags
116117
uses: ./.github/actions/docker-tags-merge
117118
with:
118119
image: ${{ inputs.image }}
@@ -123,19 +124,27 @@ jobs:
123124
- name: Push to ci registry (${{ inputs.ci_registry }}) 📤
124125
if: inputs.publish_to_registry == 'false'
125126
run: |
126-
docker push --all-tags $REGISTRY/$OWNER/$SHORT_IMAGE_NAME
127+
for tag in ${{ steps.merge-tags.outputs.image_tags }}
128+
do
129+
docker push ${tag}-${{ inputs.platform_amd64 }}
130+
docker push ${tag}-${{ inputs.platform_arm64 }}
131+
done
127132
shell: bash
128133

129134
- name: Push to public registry (${{ inputs.registry }}) 📤
130135
if: inputs.publish_to_registry == 'true'
131136
run: |
132-
docker push --all-tags $REGISTRY/$OWNER/$SHORT_IMAGE_NAME
137+
for tag in ${{ steps.merge-tags.outputs.image_tags }}
138+
do
139+
docker push ${tag}-${{ inputs.platform_amd64 }}
140+
docker push ${tag}-${{ inputs.platform_arm64 }}
141+
done
133142
shell: bash
134143

135144
- name: Create multi-arch (${{ inputs.platform_amd64 }}/${{ inputs.platform_arm64 }}) image for ${{ inputs.image }} 📤
136145
run: |
137146
# The tags are already in the form: $REGISTRY/$OWNER/${{ inputs.image }}
138-
for tag in $IMAGE_TAGS
147+
for tag in ${{ steps.merge-tags.outputs.image_tags }}
139148
do
140149
echo "Creating multi-arch manifest for $tag ..."
141150
docker manifest create $tag $tag-${{ inputs.platform_amd64 }} $tag-${{ inputs.platform_arm64 }}

0 commit comments

Comments
 (0)