Skip to content

Commit 68cd4ec

Browse files
committed
docs: update native multiarch example
1 parent d50cfe0 commit 68cd4ec

File tree

1 file changed

+23
-37
lines changed

1 file changed

+23
-37
lines changed

docs/multi-platform-builds.md

Lines changed: 23 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -107,59 +107,49 @@ name: Build Multi-Platform Images
107107
108108
on:
109109
push:
110-
branches: [ main ]
110+
branches:
111+
- main
111112
pull_request:
112-
branches: [ main ]
113+
branches:
114+
- main
113115
114116
env:
115-
REGISTRY: ghcr.io
116-
IMAGE_NAME: ${{ github.repository }}
117+
IMAGE_NAME: ghcr.io/${{ github.repository }}
118+
IMAGE_TAGS: ${{ github.sha }}${{ github.ref_name == github.event.repository.default_branch && ',latest' || '' }}
117119
118120
jobs:
119121
# Build images on parallel native runners
120122
build:
121123
runs-on: ubuntu-latest
122124
strategy:
125+
fail-fast: false
123126
matrix:
124127
platform:
125128
- linux/amd64
126129
- linux/arm64
127-
fail-fast: false
128130
outputs:
129-
IMAGE_DIGEST_linux_amd64: ${{ steps.build.outputs.IMAGE_DIGEST_linux_amd64 }}
130-
IMAGE_DIGEST_linux_arm64: ${{ steps.build.outputs.IMAGE_DIGEST_linux_arm64 }}
131+
IMAGE_DIGEST_linux_amd64: ${{ steps.matrix-outputs.outputs.IMAGE_DIGEST_linux_amd64 }}
132+
IMAGE_DIGEST_linux_arm64: ${{ steps.matrix-outputs.outputs.IMAGE_DIGEST_linux_arm64 }}
131133
steps:
132134
- name: Checkout repository
133135
uses: actions/checkout@v4
134-
135136
- name: Set up Docker Buildx
136137
uses: docker/setup-buildx-action@v3
137-
138-
- name: Login to Container Registry
139-
uses: docker/login-action@v3
140-
with:
141-
registry: ${{ env.REGISTRY }}
142-
username: ${{ github.actor }}
143-
password: ${{ secrets.GITHUB_TOKEN }}
144-
145138
- name: Build and push
146139
id: build
147140
uses: devcontainers/[email protected]
148141
with:
149-
imageName: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
150-
platform: ${{ matrix.platform }}
151142
push: always
152-
153-
# Combine all digests from the matrix into a single output
143+
platform: ${{ matrix.platform }}
144+
imageName: ${{ env.IMAGE_NAME }}
145+
imageTag: ${{ env.IMAGE_TAGS }}
154146
- name: Set matrix outputs
155147
if: always()
148+
id: matrix-outputs
156149
run: |
157-
# Extract the digest for this platform from the JSON output
158150
DIGESTS_JSON='${{ steps.build.outputs.imageDigests }}'
159-
PLATFORM="${{ matrix.platform }}"
160-
DIGEST=$(echo $DIGESTS_JSON | jq -r --arg platform "$PLATFORM" '.[$platform]')
161-
echo "IMAGE_DIGEST_${PLATFORM//\//_}=${DIGEST}" >> $GITHUB_OUTPUT
162-
151+
echo $DIGESTS_JSON | jq -r 'to_entries[] | "echo \"IMAGE_DIGEST_\(.key | gsub("/"; "_"))=\(.value)\" >> $GITHUB_OUTPUT"' | bash
152+
163153
164154
# Create a manifest list from all platform images
165155
manifest:
@@ -168,18 +158,14 @@ jobs:
168158
steps:
169159
- name: Set up Docker Buildx
170160
uses: docker/setup-buildx-action@v3
171-
172161
- name: Create and push manifest list
173162
run: |
174-
IMAGE=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
175-
176-
# Create manifest list from each platform's digest
177-
docker buildx imagetools create \
178-
-t ${IMAGE}:latest \
179-
${IMAGE}@${{ needs.build.outputs.IMAGE_DIGEST_linux_amd64 }} \
180-
${IMAGE}@${{ needs.build.outputs.IMAGE_DIGEST_linux_arm64 }}
181-
182-
- name: Inspect manifest
183-
run: |
184-
docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
163+
IFS=',' read -ra TAGS <<< "${{ env.IMAGE_TAGS }}"
164+
for tag in "${TAGS[@]}"; do
165+
docker buildx imagetools create \
166+
-t ${{ env.IMAGE_NAME }}:${tag} \
167+
${{ env.IMAGE_NAME }}@${{ needs.build.outputs.IMAGE_DIGEST_linux_amd64 }} \
168+
${{ env.IMAGE_NAME }}@${{ needs.build.outputs.IMAGE_DIGEST_linux_arm64 }}
169+
docker buildx imagetools inspect ${{ env.IMAGE_NAME }}:${tag}
170+
done
185171
```

0 commit comments

Comments
 (0)