Skip to content

Commit 0a551bf

Browse files
committed
fix: simplify multi-registry push by using GHCR as primary
Push by digest only to GHCR (primary registry), then use imagetools to create manifests with tags for both GHCR and Docker Hub in a single operation. Docker BuildKit will handle copying the layers to Docker Hub. This is the recommended approach for multi-registry multi-arch builds: 1. Build each platform and push by digest to primary registry 2. Create manifest list referencing those digests 3. Apply all tags (from all registries) in one imagetools create command 4. BuildKit automatically copies layers to secondary registries
1 parent fede0f9 commit 0a551bf

File tree

1 file changed

+15
-27
lines changed

1 file changed

+15
-27
lines changed

.github/workflows/build-cli-docker.yml

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ jobs:
8080
maintainer=techprimate GmbH <[email protected]>
8181
cache-from: type=registry,ref=ghcr.io/${{ github.repository }}:buildcache-${{ matrix.platform.tag }}
8282
cache-to: type=registry,ref=ghcr.io/${{ github.repository }}:buildcache-${{ matrix.platform.tag }},mode=max
83-
outputs: type=image,name=docker.io/${{ github.repository }},name=ghcr.io/${{ github.repository }},push-by-digest=true,name-canonical=true,push=${{ github.event_name != 'pull_request' }}
83+
outputs: type=image,name=ghcr.io/${{ github.repository }},push-by-digest=true,name-canonical=true,push=${{ github.event_name != 'pull_request' }}
8484

8585
- name: Export digest
8686
if: github.event_name != 'pull_request'
@@ -157,33 +157,21 @@ jobs:
157157
- name: Create manifest list and push
158158
working-directory: /tmp/digests
159159
run: |
160-
# Extract all tags
161-
image_tags=$(printf '%s' "$DOCKER_METADATA_OUTPUT_JSON" | jq -cr '.tags | map("-t " + .) | join(" ")')
162-
echo "Creating manifest list with tags: $image_tags"
163-
164-
# We need to create separate manifests for each registry
165-
# because the digests are registry-specific
166-
167-
# For each registry, create manifest with its digests
168-
for registry in "docker.io/${{ github.repository }}" "ghcr.io/${{ github.repository }}"; do
169-
echo "Processing registry: $registry"
170-
171-
# Get tags for this registry
172-
registry_tags=$(printf '%s' "$DOCKER_METADATA_OUTPUT_JSON" | jq -cr --arg registry "$registry" '.tags | map(select(startswith($registry))) | map("-t " + .) | join(" ")')
173-
174-
# Build digest references for this registry
175-
digest_refs=""
176-
for digest_file in *; do
177-
digest_refs="$digest_refs ${registry}@sha256:${digest_file}"
178-
done
179-
180-
echo "Tags for $registry: $registry_tags"
181-
echo "Digest refs: $digest_refs"
182-
183-
# Create and push manifest for this registry
184-
docker buildx imagetools create $registry_tags $digest_refs
160+
# Build digest references from GHCR (where images were pushed)
161+
digest_refs=""
162+
for digest_file in *; do
163+
digest_refs="$digest_refs ghcr.io/${{ github.repository }}@sha256:${digest_file}"
185164
done
186-
165+
echo "Digest references: $digest_refs"
166+
167+
# Get all tags (both GHCR and Docker Hub)
168+
all_tags=$(printf '%s' "$DOCKER_METADATA_OUTPUT_JSON" | jq -cr '.tags | map("-t " + .) | join(" ")')
169+
echo "Creating manifest list with tags: $all_tags"
170+
171+
# Create manifest list with all tags (GHCR and Docker Hub)
172+
# This will create the manifest in GHCR and simultaneously tag/push to Docker Hub
173+
docker buildx imagetools create $all_tags $digest_refs
174+
187175
# Inspect the first tag for verification
188176
first_tag=$(printf '%s' "$DOCKER_METADATA_OUTPUT_JSON" | jq -cr '.tags[0]')
189177
docker buildx imagetools inspect "$first_tag"

0 commit comments

Comments
 (0)