4444 - name : Set up Docker Buildx
4545 uses : docker/setup-buildx-action@v3
4646
47- # Build JSON arrays of tags for each service
48- - name : Compute tags (JSON arrays)
47+ # Build *lines* of overrides like:
48+ # userapi.tags=ghcr.io/...:edge
49+ # userapi.tags=ghcr.io/...:latest
50+ - name : Compute tag override lines
4951 id : tags
5052 shell : bash
5153 run : |
5456 REPO_SLUG="${REPO_SLUG}"
5557 REF="${GITHUB_REF}"
5658
59+ add_tags_lines() {
60+ local svc="$1"; shift
61+ local -a tags=( "$@" )
62+ for t in "${tags[@]}"; do
63+ printf '%s.tags=%s\n' "$svc" "$t"
64+ done
65+ }
66+
5767 user_tags=( "ghcr.io/${OWNER_LC}/${REPO_SLUG}/userapi:edge" )
5868 api_tags=( "ghcr.io/${OWNER_LC}/${REPO_SLUG}/api:edge" )
5969 web_tags=( "ghcr.io/${OWNER_LC}/${REPO_SLUG}/web:edge" )
@@ -73,19 +83,19 @@ jobs:
7383 web_tags+=( "ghcr.io/${OWNER_LC}/${REPO_SLUG}/web:${ver}" "ghcr.io/${OWNER_LC}/${REPO_SLUG}/web:${minor}" )
7484 fi
7585
76- user_json ="$(printf '%s\n' "${user_tags[@]}" | jq -R . | jq -s . )"
77- api_json ="$(printf '%s\n' "${api_tags[@]}" | jq -R . | jq -s . )"
78- web_json ="$(printf '%s\n' "${web_tags[@]}" | jq -R . | jq -s . )"
86+ user_lines ="$(add_tags_lines userapi "${user_tags[@]}")"
87+ api_lines ="$(add_tags_lines api "${api_tags[@]}")"
88+ web_lines ="$(add_tags_lines web "${web_tags[@]}")"
7989
8090 {
81- echo "user_tags_json <<EOF"
82- echo "${user_json }"
91+ echo "user_set <<EOF"
92+ echo "${user_lines }"
8393 echo "EOF"
84- echo "api_tags_json <<EOF"
85- echo "${api_json }"
94+ echo "api_set <<EOF"
95+ echo "${api_lines }"
8696 echo "EOF"
87- echo "web_tags_json <<EOF"
88- echo "${web_json }"
97+ echo "web_set <<EOF"
98+ echo "${web_lines }"
8999 echo "EOF"
90100 } >> "$GITHUB_OUTPUT"
91101
@@ -121,9 +131,9 @@ jobs:
121131 *.cache-from=type=local,src=/tmp/.buildx-cache
122132 *.cache-to=type=local,dest=/tmp/.buildx-cache-new,mode=max
123133 *.labels.org.opencontainers.image.revision=${{ github.sha }}
124- userapi.tags= ${{ steps.tags.outputs.user_tags_json }}
125- api.tags= ${{ steps.tags.outputs.api_tags_json }}
126- web.tags= ${{ steps.tags.outputs.web_tags_json }}
134+ ${{ steps.tags.outputs.user_set }}
135+ ${{ steps.tags.outputs.api_set }}
136+ ${{ steps.tags.outputs.web_set }}
127137
128138 - name : Save build cache
129139 if : always()
@@ -135,17 +145,16 @@ jobs:
135145 if : ${{ env.DOCKERHUB_NAMESPACE != '' && env.DOCKERHUB_USERNAME != '' && env.DOCKERHUB_TOKEN != '' }}
136146 run : |
137147 set -euo pipefail
138- mirror() { local svc="$1"; local json="$2"; \
139- mapfile -t arr < <(jq -r '.[]' <<<"$json"); \
140- for img in "${arr[@]}"; do
148+ mirror() { local svc="$1"; shift; while read -r line; do
149+ img="${line#*=}" # take rhs after '='
141150 tag="${img##*:}"
142151 hub="${DOCKERHUB_NAMESPACE}/${REPO_SLUG}-${svc}:${tag}"
143152 echo "Mirroring $img -> $hub"
144153 docker pull "$img"
145154 docker tag "$img" "$hub"
146155 docker push "$hub"
147- done
148- }
149- mirror userapi ' ${{ steps.tags.outputs.user_tags_json }}'
150- mirror api ' ${{ steps.tags.outputs.api_tags_json }}'
151- mirror web ' ${{ steps.tags.outputs.web_tags_json }}'
156+ done; }
157+ # reuse the same lines we fed to bake
158+ awk -F= '/^userapi\.tags=/{print}' <<<" ${{ steps.tags.outputs.user_set }}" | mirror userapi
159+ awk -F= '/^ api\.tags=/{print}' <<<" ${{ steps.tags.outputs.api_set }}" | mirror api
160+ awk -F= '/^ web\.tags=/{print}' <<<" ${{ steps.tags.outputs.web_set }}" | mirror web
0 commit comments