Skip to content

Commit ab8321c

Browse files
committed
Enhance build-fpm.yml and build-cli.yml workflows:
- Add support for Docker Hub alongside GHCR for multi-arch builds and manifests. - Refactor tag generation to handle registry-specific tags (`GHCR_IMAGE` and `DOCKERHUB_IMAGE`). - Update cache configurations for multi-registry setup. - Organize steps for improved clarity and maintainability.
1 parent 068ecf1 commit ab8321c

2 files changed

Lines changed: 212 additions & 69 deletions

File tree

.github/workflows/build-cli.yml

Lines changed: 107 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@ on:
1010
- cron: '0 2 * * 1'
1111
workflow_dispatch:
1212

13+
permissions:
14+
contents: read
15+
packages: write # needed for GHCR
16+
1317
env:
14-
IMAGE: ghcr.io/liquidrazor/php
18+
GHCR_IMAGE: ghcr.io/liquidrazor/php
19+
DOCKERHUB_IMAGE: docker.io/liquidrazor/php
1520

1621
concurrency:
1722
group: ${{ github.workflow }}-${{ github.ref }}
@@ -30,42 +35,69 @@ jobs:
3035
is_latest: false
3136
env:
3237
ARCH_SUFFIX: amd64
33-
PHP_VERSION: ${{ vars[matrix.var] }} # <-- fix
34-
IS_LATEST: ${{ matrix.is_latest }} # <-- new
38+
PHP_VERSION: ${{ vars[matrix.var] }}
39+
IS_LATEST: ${{ matrix.is_latest }}
3540
steps:
3641
- uses: actions/checkout@v4
3742
- uses: docker/setup-buildx-action@v3
3843
with: { driver: docker-container }
44+
45+
# Log in to GHCR
3946
- uses: docker/login-action@v3
4047
with:
4148
registry: ghcr.io
4249
username: ${{ github.actor }}
4350
password: ${{ secrets.GITHUB_TOKEN }}
4451

52+
# Log in to Docker Hub
53+
- uses: docker/login-action@v3
54+
with:
55+
username: ${{ secrets.DOCKERHUB_USERNAME }}
56+
password: ${{ secrets.DOCKERHUB_TOKEN }}
57+
4558
- name: Compute tags (CLI)
4659
id: tags
4760
shell: bash
4861
run: |
4962
set -euo pipefail
5063
PHP_VERSION="${PHP_VERSION:?missing}"
5164
LINE_VERSION="$(cut -d. -f1,2 <<<"$PHP_VERSION")"
65+
5266
TAGS=("php-${LINE_VERSION}-cli" "php-${PHP_VERSION}-cli")
5367
if [[ "${IS_LATEST}" == "true" ]]; then
5468
TAGS=("php-cli" "${TAGS[@]}")
5569
fi
70+
5671
ARCH="${ARCH_SUFFIX}"
57-
mapfile -t TAGS_WITH_ARCH < <(for t in "${TAGS[@]}"; do printf "%s:%s-%s\n" "${IMAGE}" "$t" "${ARCH}"; done)
58-
{
59-
echo "tags_no_arch<<__NOARCH__"
60-
printf '%s\n' "${TAGS[@]}"
61-
echo "__NOARCH__"
62-
} >> "$GITHUB_OUTPUT"
72+
73+
# Registry-qualified tags with arch suffix
74+
mapfile -t TAGS_WITH_ARCH < <(
75+
for t in "${TAGS[@]}"; do
76+
printf "%s:%s-%s\n" "${GHCR_IMAGE}" "$t" "${ARCH}"
77+
printf "%s:%s-%s\n" "${DOCKERHUB_IMAGE}" "$t" "${ARCH}"
78+
done
79+
)
80+
81+
# No-arch tags (for manifest creation)
82+
mapfile -t TAGS_NO_ARCH < <(
83+
for t in "${TAGS[@]}"; do
84+
printf "%s:%s\n" "${GHCR_IMAGE}" "$t"
85+
printf "%s:%s\n" "${DOCKERHUB_IMAGE}" "$t"
86+
done
87+
)
88+
6389
{
6490
echo "tags_with_arch<<__ARCH__"
6591
printf '%s\n' "${TAGS_WITH_ARCH[@]}"
6692
echo "__ARCH__"
6793
} >> "$GITHUB_OUTPUT"
6894
95+
{
96+
echo "tags_no_arch<<__NOARCH__"
97+
printf '%s\n' "${TAGS_NO_ARCH[@]}"
98+
echo "__NOARCH__"
99+
} >> "$GITHUB_OUTPUT"
100+
69101
- uses: docker/build-push-action@v6
70102
with:
71103
context: docker/php/cli/base
@@ -76,10 +108,10 @@ jobs:
76108
PHP_VERSION=${{ env.PHP_VERSION }}
77109
tags: ${{ steps.tags.outputs.tags_with_arch }}
78110
cache-from: |
79-
type=registry,ref=${{ env.IMAGE }}:buildcache-cli-${{ env.PHP_VERSION }}-amd64
111+
type=registry,ref=${{ env.GHCR_IMAGE }}:buildcache-cli-${{ env.PHP_VERSION }}-amd64
80112
type=gha,scope=cli-${{ env.PHP_VERSION }}-amd64
81113
cache-to: |
82-
type=registry,ref=${{ env.IMAGE }}:buildcache-cli-${{ env.PHP_VERSION }}-amd64,mode=max
114+
type=registry,ref=${{ env.GHCR_IMAGE }}:buildcache-cli-${{ env.PHP_VERSION }}-amd64,mode=max
83115
type=gha,scope=cli-${{ env.PHP_VERSION }}-amd64,mode=max
84116
sbom: false
85117
provenance: false
@@ -96,43 +128,63 @@ jobs:
96128
is_latest: false
97129
env:
98130
ARCH_SUFFIX: arm64
99-
PHP_VERSION: ${{ vars[matrix.var] }} # <-- fix
100-
IS_LATEST: ${{ matrix.is_latest }} # <-- new
131+
PHP_VERSION: ${{ vars[matrix.var] }}
132+
IS_LATEST: ${{ matrix.is_latest }}
101133
steps:
102134
- uses: actions/checkout@v4
103135
- uses: docker/setup-buildx-action@v3
104136
with: { driver: docker-container }
137+
105138
- uses: docker/login-action@v3
106139
with:
107140
registry: ghcr.io
108141
username: ${{ github.actor }}
109142
password: ${{ secrets.GITHUB_TOKEN }}
110143

144+
- uses: docker/login-action@v3
145+
with:
146+
username: ${{ secrets.DOCKERHUB_USERNAME }}
147+
password: ${{ secrets.DOCKERHUB_TOKEN }}
148+
111149
- name: Compute tags (CLI)
112150
id: tags
113151
shell: bash
114152
run: |
115153
set -euo pipefail
116154
PHP_VERSION="${PHP_VERSION:?missing}"
117155
LINE_VERSION="$(cut -d. -f1,2 <<<"$PHP_VERSION")"
156+
118157
TAGS=("php-${LINE_VERSION}-cli" "php-${PHP_VERSION}-cli")
119158
if [[ "${IS_LATEST}" == "true" ]]; then
120159
TAGS=("php-cli" "${TAGS[@]}")
121160
fi
161+
122162
ARCH="${ARCH_SUFFIX}"
123-
mapfile -t TAGS_WITH_ARCH < <(for t in "${TAGS[@]}"; do printf "%s:%s-%s\n" "${IMAGE}" "$t" "${ARCH}"; done)
124-
# write simple (no-arch) tags
125-
{
126-
echo "tags_no_arch<<__NOARCH__"
127-
printf '%s\n' "${TAGS[@]}"
128-
echo "__NOARCH__"
129-
} >> "$GITHUB_OUTPUT"
130-
131-
# write arch-suffixed tags
163+
164+
mapfile -t TAGS_WITH_ARCH < <(
165+
for t in "${TAGS[@]}"; do
166+
printf "%s:%s-%s\n" "${GHCR_IMAGE}" "$t" "${ARCH}"
167+
printf "%s:%s-%s\n" "${DOCKERHUB_IMAGE}" "$t" "${ARCH}"
168+
done
169+
)
170+
171+
mapfile -t TAGS_NO_ARCH < <(
172+
for t in "${TAGS[@]}"; do
173+
printf "%s:%s\n" "${GHCR_IMAGE}" "$t"
174+
printf "%s:%s\n" "${DOCKERHUB_IMAGE}" "$t"
175+
done
176+
)
177+
132178
{
133179
echo "tags_with_arch<<__ARCH__"
134180
printf '%s\n' "${TAGS_WITH_ARCH[@]}"
135-
echo "__ARCH__"
181+
echo "__ARCH__"
182+
} >> "$GITHUB_OUTPUT"
183+
184+
{
185+
echo "tags_no_arch<<__NOARCH__"
186+
printf '%s\n' "${TAGS_NO_ARCH[@]}"
187+
echo "__NOARCH__"
136188
} >> "$GITHUB_OUTPUT"
137189
138190
- uses: docker/build-push-action@v6
@@ -145,17 +197,17 @@ jobs:
145197
PHP_VERSION=${{ env.PHP_VERSION }}
146198
tags: ${{ steps.tags.outputs.tags_with_arch }}
147199
cache-from: |
148-
type=registry,ref=${{ env.IMAGE }}:buildcache-cli-${{ env.PHP_VERSION }}-arm64
200+
type=registry,ref=${{ env.GHCR_IMAGE }}:buildcache-cli-${{ env.PHP_VERSION }}-arm64
149201
type=gha,scope=cli-${{ env.PHP_VERSION }}-arm64
150202
cache-to: |
151-
type=registry,ref=${{ env.IMAGE }}:buildcache-cli-${{ env.PHP_VERSION }}-arm64,mode=max
203+
type=registry,ref=${{ env.GHCR_IMAGE }}:buildcache-cli-${{ env.PHP_VERSION }}-arm64,mode=max
152204
type=gha,scope=cli-${{ env.PHP_VERSION }}-arm64,mode=max
153205
sbom: false
154206
provenance: false
155207

156208
manifest:
157209
runs-on: ubuntu-latest
158-
needs: [ build-amd64, build-arm64 ]
210+
needs: [build-amd64, build-arm64]
159211
strategy:
160212
fail-fast: false
161213
matrix:
@@ -165,15 +217,19 @@ jobs:
165217
- var: PHP_PREVIOUS
166218
is_latest: false
167219
env:
168-
PHP_VERSION: ${{ vars[matrix.var] }} # <-- fix
169-
IS_LATEST: ${{ matrix.is_latest }} # <-- new
220+
PHP_VERSION: ${{ vars[matrix.var] }}
221+
IS_LATEST: ${{ matrix.is_latest }}
170222
steps:
171-
- uses: docker/setup-buildx-action@v3 # ensure imagetools is available
223+
- uses: docker/setup-buildx-action@v3
172224
- uses: docker/login-action@v3
173225
with:
174226
registry: ghcr.io
175227
username: ${{ github.actor }}
176228
password: ${{ secrets.GITHUB_TOKEN }}
229+
- uses: docker/login-action@v3
230+
with:
231+
username: ${{ secrets.DOCKERHUB_USERNAME }}
232+
password: ${{ secrets.DOCKERHUB_TOKEN }}
177233

178234
- name: Recompute final tags (CLI)
179235
id: tags
@@ -182,22 +238,36 @@ jobs:
182238
set -euo pipefail
183239
PHP_VERSION="${PHP_VERSION:?missing}"
184240
LINE_VERSION="$(cut -d. -f1,2 <<<"$PHP_VERSION")"
241+
185242
TAGS=("php-${LINE_VERSION}-cli" "php-${PHP_VERSION}-cli")
186243
if [[ "${IS_LATEST}" == "true" ]]; then
187244
TAGS=("php-cli" "${TAGS[@]}")
188245
fi
189-
printf "tags_no_arch<<'EOF'\n%s\nEOF\n" "$(printf "%s\n" "${TAGS[@]}")" >> "$GITHUB_OUTPUT"
246+
247+
# Fully-qualified (no-arch) targets for manifest creation, both registries
248+
mapfile -t TAGS_NO_ARCH < <(
249+
for t in "${TAGS[@]}"; do
250+
printf "%s:%s\n" "${GHCR_IMAGE}" "$t"
251+
printf "%s:%s\n" "${DOCKERHUB_IMAGE}" "$t"
252+
done
253+
)
254+
255+
{
256+
echo "tags_no_arch<<__NOARCH__"
257+
printf '%s\n' "${TAGS_NO_ARCH[@]}"
258+
echo "__NOARCH__"
259+
} >> "$GITHUB_OUTPUT"
190260
191261
- name: Publish multi-arch manifests (CLI)
192262
shell: bash
193-
env:
194-
IMAGE: ${{ env.IMAGE }}
195263
run: |
196264
set -euo pipefail
197-
while IFS= read -r TAG; do
198-
echo "Creating manifest for ${IMAGE}:${TAG}"
265+
while IFS= read -r TARGET; do
266+
base="${TARGET%:*}"
267+
tag="${TARGET##*:}"
268+
echo "Creating manifest for ${base}:${tag}"
199269
docker buildx imagetools create \
200-
-t "${IMAGE}:${TAG}" \
201-
"${IMAGE}:${TAG}-amd64" \
202-
"${IMAGE}:${TAG}-arm64"
270+
-t "${base}:${tag}" \
271+
"${base}:${tag}-amd64" \
272+
"${base}:${tag}-arm64"
203273
done <<< "${{ steps.tags.outputs.tags_no_arch }}"

0 commit comments

Comments
 (0)