Skip to content

Commit 51a14ab

Browse files
authored
Use shared Bash image CI from kool-dev/action (#141)
* Reduce registry reads and recover publication from tested artifacts * Remove publication recovery and retain request reductions only * Use shared Bash native-image CI from kool * Pin shared image tooling from kool-dev/action * Call the publisher action directly and trim repeated documentation
1 parent 6de6cb9 commit 51a14ab

6 files changed

Lines changed: 65 additions & 530 deletions

File tree

‎.github/workflows/ci-cd.yml‎

Lines changed: 60 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,36 @@
11
name: CI/CD
2-
32
on:
43
push:
54
branches: [master]
65
pull_request:
76
workflow_dispatch:
87
schedule:
98
- cron: "0 0 * * 0"
10-
119
permissions:
1210
contents: read
13-
1411
concurrency:
1512
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
16-
# Never interrupt a release between publishing base and derived images.
1713
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
18-
1914
jobs:
2015
checks:
21-
runs-on: ubuntu-latest
16+
runs-on: ubuntu-24.04
17+
outputs:
18+
tags: ${{ steps.tags.outputs.tags }}
2219
steps:
2320
- uses: actions/checkout@v7
24-
- name: Test publication contracts
25-
run: python3 -m unittest discover -s scripts -p 'test_*.py' -v
26-
- name: Lint workflows
27-
run: |
28-
docker run --rm -v "$PWD:/repo" -w /repo rhysd/actionlint:1.7.11
29-
- name: Test promotion against an ephemeral local registry
30-
run: python3 scripts/registry_roundtrip.py
31-
- name: Verify generated images match templates
32-
# fwd's packaged Blade cache is not writable by arbitrary user IDs.
21+
- name: Check generated contexts
3322
run: |
3423
docker run --rm -v "$PWD:/app" fireworkweb/fwd:v1.0 fwd template
3524
git diff --exit-code
36-
37-
build-test:
25+
- id: tags
26+
run: echo "tags=$(jq -c '[.builds[].name]' fwd-template.json)" >> "$GITHUB_OUTPUT"
27+
build:
3828
needs: checks
39-
runs-on: ${{ matrix.native.runner }}
29+
runs-on: ${{ matrix.platform.runner }}
4030
strategy:
4131
fail-fast: false
4232
matrix:
43-
native:
33+
platform:
4434
- {arch: amd64, runner: ubuntu-24.04}
4535
- {arch: arm64, runner: ubuntu-24.04-arm}
4636
version: ["8.2", "8.3", "8.4", "8.5"]
@@ -53,20 +43,13 @@ jobs:
5343
BASE: ${{ matrix.version }}${{ matrix.distro }}${{ matrix.type }}
5444
NGINX: ${{ matrix.version }}${{ matrix.distro }}-nginx${{ matrix.type }}
5545
NODE: ${{ matrix.version }}-node
56-
ARCH: ${{ matrix.native.arch }}
46+
ARCH: ${{ matrix.platform.arch }}
5747
steps:
5848
- uses: actions/checkout@v7
59-
# The docker driver resolves derived FROMs to the fresh same-job base.
60-
- uses: docker/setup-buildx-action@v4
49+
- uses: kool-dev/action/image-build@6a6d04e8d1e1c66afc178e32c7d77d76169c7717
6150
with:
62-
driver: docker
63-
- name: Verify native architecture
64-
run: |
65-
case "$ARCH:$(uname -m)" in
66-
amd64:x86_64|arm64:aarch64) ;;
67-
*) echo "::error::Not a native $ARCH runner"; exit 1 ;;
68-
esac
69-
- name: Build base image
51+
arch: ${{ env.ARCH }}
52+
- name: Build fresh base
7053
id: base
7154
uses: docker/build-push-action@v7
7255
with:
@@ -76,11 +59,11 @@ jobs:
7659
provenance: false
7760
load: true
7861
tags: kooldev/php:${{ env.BASE }}
79-
- name: Test base image
62+
- name: Test base
8063
env:
8164
IMAGE_ID: ${{ steps.base.outputs.imageid }}
8265
run: bash scripts/test-image.sh "$BASE" "$IMAGE_ID"
83-
- name: Build nginx image
66+
- name: Build nginx from same-job base (never force-pull)
8467
id: nginx
8568
uses: docker/build-push-action@v7
8669
with:
@@ -89,14 +72,16 @@ jobs:
8972
provenance: false
9073
load: true
9174
tags: kooldev/php:${{ env.NGINX }}
92-
- name: Test nginx image
75+
- uses: kool-dev/action/image-parent@6a6d04e8d1e1c66afc178e32c7d77d76169c7717
76+
with:
77+
base-ref: kooldev/php:${{ env.BASE }}
78+
base-id: ${{ steps.base.outputs.imageid }}
79+
image-id: ${{ steps.nginx.outputs.imageid }}
80+
- name: Test nginx
9381
env:
9482
IMAGE_ID: ${{ steps.nginx.outputs.imageid }}
95-
BASE_ID: ${{ steps.base.outputs.imageid }}
96-
run: |
97-
python3 scripts/check_parent.py "$BASE" "$BASE_ID" "$IMAGE_ID"
98-
bash scripts/test-image.sh "$NGINX" "$IMAGE_ID"
99-
- name: Build node image
83+
run: bash scripts/test-image.sh "$NGINX" "$IMAGE_ID"
84+
- name: Build node from same-job base (never force-pull)
10085
id: node
10186
if: matrix.distro == '' && matrix.type == ''
10287
uses: docker/build-push-action@v7
@@ -106,77 +91,56 @@ jobs:
10691
provenance: false
10792
load: true
10893
tags: kooldev/php:${{ env.NODE }}
109-
- name: Test node image
94+
- uses: kool-dev/action/image-parent@6a6d04e8d1e1c66afc178e32c7d77d76169c7717
95+
if: matrix.distro == '' && matrix.type == ''
96+
with:
97+
base-ref: kooldev/php:${{ env.BASE }}
98+
base-id: ${{ steps.base.outputs.imageid }}
99+
image-id: ${{ steps.node.outputs.imageid }}
100+
- name: Test node
110101
if: matrix.distro == '' && matrix.type == ''
111102
env:
112103
IMAGE_ID: ${{ steps.node.outputs.imageid }}
113-
BASE_ID: ${{ steps.base.outputs.imageid }}
114-
run: |
115-
python3 scripts/check_parent.py "$BASE" "$BASE_ID" "$IMAGE_ID"
116-
bash scripts/test-image.sh "$NODE" "$IMAGE_ID"
117-
# No registry credentials, staging pushes or release artifacts on PRs,
118-
# forks or manually dispatched feature branches.
119-
- uses: docker/login-action@v4
120-
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/master' && github.repository == 'kool-dev/docker-php'
121-
with:
122-
username: ${{ secrets.DOCKER_USERNAME }}
123-
password: ${{ secrets.DOCKER_PASSWORD }}
124-
- name: Stage tested images by immutable image ID
125-
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/master' && github.repository == 'kool-dev/docker-php'
104+
run: bash scripts/test-image.sh "$NODE" "$IMAGE_ID"
105+
- name: Collect tested IDs
106+
id: images
126107
env:
127108
BASE_ID: ${{ steps.base.outputs.imageid }}
128109
NGINX_ID: ${{ steps.nginx.outputs.imageid }}
129110
NODE_ID: ${{ steps.node.outputs.imageid }}
130111
run: |
131-
python3 scripts/promote.py stage "$BASE" "$ARCH" "$BASE_ID"
132-
python3 scripts/promote.py stage "$NGINX" "$ARCH" "$NGINX_ID"
133-
if [ -n "$NODE_ID" ]; then
134-
python3 scripts/promote.py stage "$NODE" "$ARCH" "$NODE_ID"
135-
fi
136-
- uses: actions/upload-artifact@v7.0.2
137-
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/master' && github.repository == 'kool-dev/docker-php'
138-
with:
139-
name: php-${{ github.run_id }}-${{ github.run_attempt }}-${{ env.BASE }}-${{ env.ARCH }}
140-
path: release-metadata/${{ env.BASE }}-${{ env.ARCH }}.json
141-
if-no-files-found: error
142-
- uses: actions/upload-artifact@v7.0.2
112+
images=$(jq -cn --arg base "$BASE" --arg nginx "$NGINX" --arg node "$NODE" \
113+
--arg bid "$BASE_ID" --arg nid "$NGINX_ID" --arg oid "$NODE_ID" \
114+
'[{tag:$base,id:$bid},{tag:$nginx,id:$nid}] + if $oid == "" then [] else [{tag:$node,id:$oid}] end')
115+
echo "images=$images" >> "$GITHUB_OUTPUT"
116+
- uses: kool-dev/action/image-stage@6a6d04e8d1e1c66afc178e32c7d77d76169c7717
143117
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/master' && github.repository == 'kool-dev/docker-php'
144118
with:
145-
name: php-${{ github.run_id }}-${{ github.run_attempt }}-${{ env.NGINX }}-${{ env.ARCH }}
146-
path: release-metadata/${{ env.NGINX }}-${{ env.ARCH }}.json
147-
if-no-files-found: error
148-
- uses: actions/upload-artifact@v7.0.2
149-
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/master' && github.repository == 'kool-dev/docker-php' && matrix.distro == '' && matrix.type == ''
150-
with:
151-
name: php-${{ github.run_id }}-${{ github.run_attempt }}-${{ env.NODE }}-${{ env.ARCH }}
152-
path: release-metadata/${{ env.NODE }}-${{ env.ARCH }}.json
153-
if-no-files-found: error
154-
119+
canonical-repository: kool-dev/docker-php
120+
default-branch: master
121+
repository: kooldev/php
122+
arch: ${{ env.ARCH }}
123+
group: ${{ env.BASE }}
124+
images: ${{ steps.images.outputs.images }}
125+
username: ${{ secrets.DOCKER_USERNAME }}
126+
password: ${{ secrets.DOCKER_PASSWORD }}
155127
publish:
156-
needs: build-test
128+
needs: [checks, build]
157129
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/master' && github.repository == 'kool-dev/docker-php'
158130
runs-on: ubuntu-24.04
159131
steps:
160-
- uses: actions/checkout@v7
161-
- uses: actions/download-artifact@v8.0.2
162-
with:
163-
pattern: php-${{ github.run_id }}-${{ github.run_attempt }}-*
164-
path: release-metadata
165-
# Validate the entire release before even logging into the registry.
166-
- name: Validate all 28 tags and both architectures
167-
run: python3 scripts/promote.py validate
168-
- uses: docker/setup-buildx-action@v4
169-
- uses: docker/login-action@v4
132+
- uses: kool-dev/action/image-publish@6a6d04e8d1e1c66afc178e32c7d77d76169c7717
170133
with:
134+
canonical-repository: kool-dev/docker-php
135+
default-branch: master
136+
repository: kooldev/php
137+
tags: ${{ needs.checks.outputs.tags }}
171138
username: ${{ secrets.DOCKER_USERNAME }}
172139
password: ${{ secrets.DOCKER_PASSWORD }}
173-
- name: Publish manifests only (no rebuild)
174-
run: python3 scripts/promote.py publish
175-
176140
trigger-downstream:
177141
needs: publish
178142
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/master' && github.repository == 'kool-dev/docker-php'
179-
runs-on: ubuntu-latest
143+
runs-on: ubuntu-24.04
180144
strategy:
181145
fail-fast: false
182146
matrix:
@@ -185,25 +149,14 @@ jobs:
185149
- kool-dev/docker-php-sqlsrv
186150
- kool-dev/docker-php-swoole
187151
steps:
188-
- name: Check downstream credentials
152+
- name: Notify downstream after complete publication
189153
env:
190-
DISPATCH_TOKEN: ${{ secrets.DISPATCH_TOKEN || secrets.WORKFLOW_TOKEN }}
154+
GH_TOKEN: ${{ secrets.DISPATCH_TOKEN || secrets.WORKFLOW_TOKEN }}
155+
REPOSITORY: ${{ matrix.repo }}
191156
run: |
192-
if [ -z "$DISPATCH_TOKEN" ]; then
193-
echo "::error::Downstream builds cannot be triggered: configure DISPATCH_TOKEN or WORKFLOW_TOKEN with access to the downstream repositories."
157+
if [[ -z "$GH_TOKEN" ]]; then
158+
echo "::error::Configure DISPATCH_TOKEN or WORKFLOW_TOKEN for downstream dispatch."
194159
exit 1
195160
fi
196-
- name: Trigger ${{ matrix.repo }}
197-
id: dispatch
198-
uses: peter-evans/repository-dispatch@v4
199-
with:
200-
token: ${{ secrets.DISPATCH_TOKEN || secrets.WORKFLOW_TOKEN }}
201-
repository: ${{ matrix.repo }}
202-
event-type: docker-php-updated
203-
- name: Record dispatch outcome
204-
if: always()
205-
env:
206-
REPOSITORY: ${{ matrix.repo }}
207-
OUTCOME: ${{ steps.dispatch.outcome }}
208-
run: |
209-
echo "- \`$REPOSITORY\`: docker-php-updated dispatch **$OUTCOME** (delivery is not downstream build completion)." >> "$GITHUB_STEP_SUMMARY"
161+
gh api --method POST "repos/$REPOSITORY/dispatches" -f event_type=docker-php-updated
162+
echo "- $REPOSITORY: dispatch accepted (not downstream completion)." >> "$GITHUB_STEP_SUMMARY"

‎README.md‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,15 @@ Run `bash scripts/test-image.sh 8.5` to test a locally built image (replace the
142142

143143
CI builds and tests all 28 variants once per architecture on native `ubuntu-24.04` (amd64) and `ubuntu-24.04-arm` (arm64) runners: 24 build/test groups. Only base builds pull their upstream PHP image fresh. Derived builds do not force-pull `kooldev/php`; the Docker driver keeps the fresh local base available to nginx/node builds. Before derived runtime tests, CI verifies that the local base still has its tested image ID and that its entire layer chain prefixes the derived image's layers. Tests use the build's immutable local image ID.
144144

145-
Pull requests, forks, and manual feature-branch runs never log in, stage images on Docker Hub, upload release metadata, publish stable images, or dispatch. Only trusted `master` runs (push, weekly schedule, or manual) stage the tested IDs as `kooldev/php:ci-php-RUN_ID-RUN_ATTEMPT-VARIANT-ARCH`. These temporary tags do not overwrite stable architecture tags. Staging tags remain in the registry; cleanup is not part of this workflow.
145+
Pull requests, forks, and manual feature-branch runs never log in, stage images on Docker Hub, upload release metadata, publish stable images, or dispatch. Only trusted `master` runs (push, weekly schedule, or manual) stage the tested IDs under run/attempt-scoped tags. These temporary tags do not overwrite stable architecture tags. Staging tags remain in the registry; cleanup is not part of this workflow.
146146

147-
Each tested tag uploads its registry digest in a `php-RUN_ID-RUN_ATTEMPT-VARIANT-ARCH` artifact. The final publication job requires every build/test group to succeed and downloads only the current attempt's metadata. It validates all 28 tags, exactly amd64 and arm64 per tag, repository, run scope, and digest format before changing any stable tag. Stable manifests reference those recorded digests; publication does not rebuild images or use QEMU. Dispatch starts only after every stable manifest succeeds.
147+
CI uses [shared Bash/`jq` actions](https://github.com/kool-dev/action/blob/master/image-ci.md), pinned in the workflow. PHP builds and runtime tests stay here.
148+
149+
Each native group uploads tested IDs/platforms and push digests in an `images-RUN_ID-RUN_ATTEMPT-GROUP-ARCH` artifact. The final publication job requires every group to succeed and downloads only the current attempt's metadata. It validates all 28 tags, exactly amd64 and arm64 per tag, repository, scope and digest format before changing any stable tag. Stable manifests reference those recorded digests; publication never rebuilds or uses QEMU. Dispatch starts only after every stable manifest succeeds.
148150

149151
**Rerun the entire workflow**, not just failed jobs: a new attempt cannot reuse metadata from an earlier attempt. Missing metadata fails closed before publication. Stable-tag updates across 28 tags are not a registry transaction: a registry failure during publication can leave a partially promoted release, but never triggers downstream dispatch. Investigate and rerun the whole workflow to recover.
150152

151-
Run `python3 -m unittest discover -s scripts -p 'test_*.py' -v` for the mocked publication and workflow contracts. `python3 scripts/registry_roundtrip.py` exercises real staging and manifest publication against an ephemeral loopback registry with tiny synthetic images for both platforms; it verifies the registry config digests against the original local image exports. It never pushes to Docker Hub and is not a PHP runtime test. CI also runs this registry test, actionlint, and the real template generator before native builds.
153+
Shared release contract and real loopback-registry tests run in the tooling repository using Bash. This repository runs the actual template generator before native builds and executes the runtime tests against immutable local image IDs. Synthetic registry tests are not substitutes for native runtime coverage.
152154

153155
PHP owns the rebuild schedule. After publication it notifies WordPress, SQL Server, and Swoole via `docker-php-updated`. Swoole notifies OCI8 only after all its images are published, so OCI8 does not race its Swoole parents or rebuild twice for the same PHP refresh. PHPQA is discontinued and no longer receives rebuild notifications. Downstream repositories have no separate cron schedules. Failed notifications must be investigated and retried manually; an accepted dispatch is not confirmation of downstream publication.
154156

‎scripts/check_parent.py‎

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)