Skip to content

Commit 8fe3028

Browse files
author
ami3466
committed
release: mirror the published image to Docker Hub
ghcr.io/ami3466/agentqs can never be a short name - the registry host is always part of the ref. Docker Hub is where a one-line pull reads like a product, so copy the index there too. It copies, never rebuilds: the mirror pulls the exact index merge just annotated and smoke-tested, so both registries carry identical digests rather than a second build that could drift from the bits actually tested. GHCR stays the artifact of record - continue-on-error keeps a Hub outage or a stale token from failing a release that already shipped - and the job no-ops cleanly until DOCKERHUB_TOKEN exists. The credential gate is a step output because the secrets context reads as empty in a job-level if, which would skip the job with no explanation.
1 parent fc938a7 commit 8fe3028

1 file changed

Lines changed: 95 additions & 0 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ jobs:
137137
permissions:
138138
contents: read
139139
packages: write
140+
outputs:
141+
# Every tag in this list was just pointed at the same index by the single
142+
# `imagetools create` call below and passed the smoke test at the bottom of
143+
# this job - so the mirror job can copy from any one of them instead of
144+
# recomputing tags itself and risking a different answer.
145+
published_tags: ${{ steps.meta.outputs.tags }}
140146
steps:
141147
- uses: actions/download-artifact@v4
142148
with:
@@ -234,3 +240,92 @@ jobs:
234240
docker logs qs
235241
docker rm -f qs
236242
exit 1
243+
244+
# `ghcr.io/ami3466/agentqs:latest` can never be a short name; this copies the
245+
# exact index `merge` just built, annotated, and smoke-tested onto Docker Hub so
246+
# `docker run flowenginecloud/agentqs` works too. It must never rebuild - a
247+
# second build could produce different digests and ship bits the smoke test
248+
# above never ran - so every step below is a registry-to-registry copy, not a
249+
# `docker build`.
250+
#
251+
# continue-on-error: true because this is a convenience mirror, not the release.
252+
# GHCR is the artifact of record; if Docker Hub is down or the token is wrong,
253+
# the release that already shipped above must not be marked failed for it.
254+
mirror-dockerhub:
255+
needs: merge
256+
runs-on: ubuntu-latest
257+
continue-on-error: true
258+
steps:
259+
# The `secrets` context can't be read in a job-level `if:` (it silently
260+
# evaluates to false there, which would skip this whole job with no
261+
# explanation) - only `run:`/`with:` can see it. So the gate is a step output
262+
# instead, checked on every step after it. Do NOT collapse this back into a
263+
# job-level `if: secrets.DOCKERHUB_TOKEN != ''` - that was the first draft,
264+
# and it just silently never runs.
265+
- name: Check Docker Hub credentials are configured
266+
id: creds
267+
run: echo "enabled=${{ secrets.DOCKERHUB_TOKEN != '' }}" >> "$GITHUB_OUTPUT"
268+
269+
- uses: docker/setup-buildx-action@v3
270+
if: steps.creds.outputs.enabled == 'true'
271+
272+
# Username and target are deliberately different accounts: this logs in as
273+
# the personal account that holds the token (same identity FlowEngine's
274+
# build-n8n-image.yml uses), then the copy step below pushes INTO an org
275+
# that account owns. Do not "fix" DOCKERHUB_REPO to match this username -
276+
# flowenginecloud is the org namespace on purpose, not a typo of ami3466.
277+
- uses: docker/login-action@v3
278+
if: steps.creds.outputs.enabled == 'true'
279+
with:
280+
username: ${{ vars.DOCKERHUB_USERNAME || 'ami3466' }}
281+
password: ${{ secrets.DOCKERHUB_TOKEN }}
282+
283+
- name: Resolve names
284+
if: steps.creds.outputs.enabled == 'true'
285+
run: |
286+
echo "HUB_REF=${{ vars.DOCKERHUB_REPO || 'flowenginecloud/agentqs' }}" >> $GITHUB_ENV
287+
# Any tag `merge` published points at the identical index it just
288+
# verified and smoke-tested - the first one is a fine copy source.
289+
echo "SOURCE=$(head -1 <<< '${{ needs.merge.outputs.published_tags }}')" >> $GITHUB_ENV
290+
291+
# SAME tags: block as `merge`'s meta step, aimed at the Hub ref instead of
292+
# GHCR, so Hub gets 0.3.0 / 0.3 / latest / sha-* on exactly the same rules.
293+
# metadata-action can't take two `images:` in one call, which is the only
294+
# reason this block is typed twice - if you change one, change both.
295+
- id: meta
296+
if: steps.creds.outputs.enabled == 'true'
297+
uses: docker/metadata-action@v5
298+
with:
299+
images: ${{ env.HUB_REF }}
300+
tags: |
301+
type=semver,pattern={{version}}
302+
type=semver,pattern={{major}}.{{minor}}
303+
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') }}
304+
type=sha,prefix=sha-,enable=${{ github.ref == 'refs/heads/main' }}
305+
type=raw,value=${{ inputs.tag }},enable=${{ github.event_name == 'workflow_dispatch' }}
306+
307+
# imagetools copies blobs cross-registry from the GHCR tag `merge` published -
308+
# it never touches a Dockerfile, so Hub ends up with the exact digests GHCR
309+
# has, not a rebuild that could drift from what the smoke test ran.
310+
- name: Copy the published index to Docker Hub
311+
if: steps.creds.outputs.enabled == 'true'
312+
run: |
313+
docker buildx imagetools create \
314+
$(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
315+
"$SOURCE"
316+
317+
# Same check `merge` runs on the GHCR side - a mirror that silently drops an
318+
# architecture is the exact bug this repo already spent a session fixing.
319+
# `continue-on-error` on the job (not this step) is what keeps a real miss
320+
# here from failing the workflow; it still fails the JOB, which shows up red
321+
# in the run instead of pretending the mirror is healthy.
322+
- name: Check Docker Hub has both architectures
323+
if: steps.creds.outputs.enabled == 'true'
324+
run: |
325+
TAG=$(jq -cr '.tags[0]' <<< "$DOCKER_METADATA_OUTPUT_JSON")
326+
docker buildx imagetools inspect "$TAG" --format '{{json .Manifest}}' > /tmp/hub-idx.json
327+
for arch in amd64 arm64; do
328+
jq -e --arg a "$arch" '.manifests[] | select(.platform.architecture == $a and .platform.os == "linux")' /tmp/hub-idx.json > /dev/null \
329+
|| { echo "$TAG has no linux/$arch - Hub silently missed an architecture GHCR has"; jq . /tmp/hub-idx.json; exit 1; }
330+
echo "linux/$arch present on Hub"
331+
done

0 commit comments

Comments
 (0)