Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 68 additions & 33 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
@@ -1,59 +1,94 @@
name: CI/CD

on:
push:
branches: [main]
pull_request:
workflow_dispatch:
repository_dispatch:
types: [docker-php-updated]

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

env:
DOCKER_BUILDKIT: 1

jobs:
checks:
runs-on: ubuntu-24.04
outputs:
tags: ${{ steps.tags.outputs.tags }}
steps:
- uses: actions/checkout@v7
- name: Check generated contexts
run: |
docker run --rm -v "$PWD:/app" fireworkweb/fwd:v1.0 fwd template
git diff --exit-code
- id: tags
run: echo "tags=$(jq -c '[.builds[].name]' fwd-template.json)" >> "$GITHUB_OUTPUT"
build:
name: Build
runs-on: ubuntu-latest

needs: checks
runs-on: ${{ matrix.platform.runner }}
strategy:
fail-fast: false
matrix:
version: ['8.1', '8.2', '8.3', '8.4']
type: ['', '-prod']

platform:
- {arch: amd64, runner: ubuntu-24.04}
env:
VARIANT: ${{ matrix.version }}-nginx-sqlsrv${{ matrix.type }}
steps:
- name: Checkout code
uses: actions/checkout@v3.2.0

- name: Check generated Dockerfiles
run: |
docker run --rm -v "$PWD:/app" fireworkweb/fwd:v1.0 fwd template
git diff --exit-code

- name: Build
run: |
docker build --pull -t kooldev/php:${{ matrix.version }}-nginx-sqlsrv${{ matrix.type }} ${{ matrix.version }}-nginx-sqlsrv${{ matrix.type }}

- name: Tests
- uses: actions/checkout@v7
- uses: kool-dev/action/image-build@6a6d04e8d1e1c66afc178e32c7d77d76169c7717
with:
arch: ${{ matrix.platform.arch }}
- name: Pull parent once and retain its ID for ancestry/runtime tests
id: parent
run: |
bash tests/test-image.sh kooldev/php:${{ matrix.version }}-nginx-sqlsrv${{ matrix.type }} ${{ matrix.version }}-nginx-sqlsrv${{ matrix.type }}/Dockerfile

- name: Login to DockerHub
uses: docker/login-action@v2.1.0
parent=$(awk '$1 == "FROM" {print $2; exit}' "$VARIANT/Dockerfile")
docker pull --platform linux/amd64 "$parent"
echo "ref=$parent" >> "$GITHUB_OUTPUT"
echo "id=$(docker image inspect "$parent" --format '{{.Id}}')" >> "$GITHUB_OUTPUT"
- name: Build from this job's fresh parent (never force-pull)
id: image
uses: docker/build-push-action@v7
with:
context: ${{ env.VARIANT }}
platforms: linux/${{ matrix.platform.arch }}
load: true
provenance: false
tags: kooldev/php:${{ env.VARIANT }}
- uses: kool-dev/action/image-parent@6a6d04e8d1e1c66afc178e32c7d77d76169c7717
with:
base-ref: ${{ steps.parent.outputs.ref }}
base-id: ${{ steps.parent.outputs.id }}
image-id: ${{ steps.image.outputs.imageid }}
- name: Test exact image and parent IDs
env:
IMAGE: ${{ steps.image.outputs.imageid }}
PARENT: ${{ steps.parent.outputs.id }}
run: bash tests/test-image.sh "$IMAGE" "$VARIANT/Dockerfile" "$PARENT"
- uses: kool-dev/action/image-stage@6a6d04e8d1e1c66afc178e32c7d77d76169c7717
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main' && github.repository == 'kool-dev/docker-php-sqlsrv'
with:
canonical-repository: kool-dev/docker-php-sqlsrv
default-branch: main
repository: kooldev/php
arch: ${{ matrix.platform.arch }}
group: ${{ env.VARIANT }}
images: '[{"tag":"${{ env.VARIANT }}","id":"${{ steps.image.outputs.imageid }}"}]'
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
publish:
needs: [checks, build]
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main' && github.repository == 'kool-dev/docker-php-sqlsrv'
runs-on: ubuntu-24.04
steps:
- uses: kool-dev/action/image-publish@6a6d04e8d1e1c66afc178e32c7d77d76169c7717
with:
canonical-repository: kool-dev/docker-php-sqlsrv
default-branch: main
repository: kooldev/php
tags: ${{ needs.checks.outputs.tags }}
architectures: '["amd64"]'
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Push to DockerHub
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main' && github.repository == 'kool-dev/docker-php-sqlsrv'
run: |
docker push kooldev/php:${{ matrix.version }}-nginx-sqlsrv${{ matrix.type }}
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,19 @@ The MIT License (MIT). Please see [License File](LICENSE.md) for more informatio
## Rebuilds and validation

CI rebuilds on `docker-php-updated` repository dispatches, using
`docker build --pull` to refresh the parent image. The upstream PHP repository's
an explicit parent pull once per build, retaining its ID for build ancestry and
runtime checks instead of pulling again during tests. The upstream PHP repository's
scheduled parent rebuilds propagate here after successful publication; this
repository has no separate rebuild cron. Dispatch delivery requires the upstream
PHP repository's dispatch credentials and recipient configuration. If delivery
fails, recover with this workflow's manual `workflow_dispatch` on `main`.
Only builds on this repository's `main` branch publish images; PRs do not.

CI uses [shared Bash/`jq` actions](https://github.com/kool-dev/action/blob/master/image-ci.md),
pinned in the workflow. Eight native amd64 jobs build/test once; one publisher
validates and promotes their tested digests. See the shared release rules for
publication guards and retry behavior.

To validate a local build:

```sh
Expand Down
7 changes: 5 additions & 2 deletions tests/test-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ set -euo pipefail

image="${1:?image required}"
dockerfile="${2:?Dockerfile required}"
parent="$(awk '$1 == "FROM" { print $2; exit }' "$dockerfile")"
docker pull "$parent"
parent="${3:-}"
if [[ -z "$parent" ]]; then
parent="$(awk '$1 == "FROM" { print $2; exit }' "$dockerfile")"
docker pull "$parent"
fi
expected="$(docker run --rm --network none --entrypoint php "$parent" -r 'echo PHP_VERSION;')"

docker run --rm -i --network none --entrypoint php \
Expand Down