Skip to content

Docker CI/CD

Docker CI/CD #33472

name: Docker CI/CD
on:
workflow_dispatch:
push:
branches:
- "v*"
- main
schedule:
- cron: "0 * * * *" # Runs hourly updates for the latest PHP versions and images
permissions:
packages: write
concurrency:
group: ${{ github.head_ref || github.ref }}
cancel-in-progress: ${{ github.event_name != 'schedule' }}
env:
SUPPORTED_PLATFORMS: "linux/amd64,linux/arm64,linux/arm/v7"
DEFAULT_IMAGE: "ghcr.io/ghostwriter/php"
jobs:
matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.matrix.outputs.matrix }}
container:
image: php:8.5-cli-alpine
steps:
- uses: actions/checkout@v6
- id: matrix
run: echo "matrix=$(php script/matrix.php)" >> $GITHUB_OUTPUT
extensions:
needs: [ matrix ]
runs-on: ubuntu-latest
continue-on-error: true
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.matrix.outputs.matrix) }}
steps:
- name: Login to GitHub Packages Docker Registry
uses: docker/login-action@v3
with:
password: ${{ secrets.GHT }}
registry: ghcr.io
username: ${{ github.repository_owner }}
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
github-token: ${{ secrets.GHT }}
images: ${{ env.DEFAULT_IMAGE }}
tags: type=raw,value=${{ matrix.version }}-${{ matrix.variant }}
- name: Build and push PHP ${{ matrix.version }} image
uses: docker/build-push-action@v6
continue-on-error: ${{ matrix.version == matrix.dev }}
with:
cache-from: type=gha,scope=${{ matrix.version }}-${{ matrix.variant }}
cache-to: type=gha,scope=${{ matrix.version }}-${{ matrix.variant }},mode=max
file: Dockerfile
platforms: ${{ env.SUPPORTED_PLATFORMS }}
push: ${{ github.repository_owner == github.actor }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
PHP_VERSION=${{ matrix.version }}
PHP_VARIANT=${{ matrix.variant }}
coverage:
needs: [ matrix, extensions ]
runs-on: ubuntu-latest
continue-on-error: true
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.matrix.outputs.matrix) }}
steps:
- name: Login to GitHub Packages Docker Registry
uses: docker/login-action@v3
with:
password: ${{ secrets.GHT }}
registry: ghcr.io
username: ${{ github.repository_owner }}
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
github-token: ${{ secrets.GHT }}
images: ${{ env.DEFAULT_IMAGE }}
tags: type=raw,value=${{ matrix.version }}
- name: Build and push PHP ${{ matrix.version }} image with Code Coverage
uses: docker/build-push-action@v6
with:
cache-from: type=gha,scope=${{ matrix.version }}-${{ matrix.variant }}-dev
cache-to: type=gha,scope=${{ matrix.version }}-${{ matrix.variant }}-dev,mode=max
file: development.Dockerfile
platforms: ${{ env.SUPPORTED_PLATFORMS }}
push: ${{ github.repository_owner == github.actor }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
PHP_VERSION=${{ matrix.version }}
PHP_VARIANT=${{ matrix.variant }}
frankenphp:
needs: [ matrix ]
runs-on: ubuntu-latest
continue-on-error: true
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.matrix.outputs.matrix) }}
steps:
- name: Login to GitHub Packages Docker Registry
uses: docker/login-action@v3
with:
password: ${{ secrets.GHT }}
registry: ghcr.io
username: ${{ github.repository_owner }}
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
github-token: ${{ secrets.GHT }}
images: ${{ env.DEFAULT_IMAGE }}
tags: type=raw,value=${{ matrix.version }}-frankenphp
- name: Build and push PHP ${{ matrix.version }} image with Code Coverage
uses: docker/build-push-action@v6
with:
cache-from: type=gha,scope=${{ matrix.version }}-frankenphp
cache-to: type=gha,scope=${{ matrix.version }}-frankenphp,mode=max
file: frankenphp.Dockerfile
platforms: ${{ env.SUPPORTED_PLATFORMS }}
push: ${{ github.repository_owner == github.actor }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
PHP_VERSION=${{ matrix.version }}