Docker CI/CD #20970
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.3-cli-alpine | |
steps: | |
- uses: actions/checkout@v4 | |
- id: matrix | |
run: echo "matrix=$(php matrix.php)" >> $GITHUB_OUTPUT | |
production: | |
needs: [matrix] | |
runs-on: ubuntu-latest | |
continue-on-error: true | |
strategy: | |
fail-fast: false | |
matrix: ${{ fromJSON(needs.matrix.outputs.matrix) }} | |
steps: | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
with: | |
platforms: all | |
- name: Set up Docker Buildx | |
id: buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Inspect builder | |
run: | | |
echo "Name: ${{ steps.buildx.outputs.name }}" | |
echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}" | |
echo "Status: ${{ steps.buildx.outputs.status }}" | |
echo "Flags: ${{ steps.buildx.outputs.flags }}" | |
echo "Platforms: ${{ steps.buildx.outputs.platforms }}" | |
- name: Login to GitHub Packages Docker Registry | |
uses: docker/login-action@v3 | |
with: | |
password: ${{ secrets.GHT }} | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
- 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 }} | |
type=raw,value=latest,enable=${{ matrix.latest == matrix.version && matrix.variant == 'cli' }} | |
- name: Build and push PHP ${{ matrix.version }} | |
uses: docker/build-push-action@v6 | |
with: | |
cache-from: type=gha,scope=${{ matrix.version }}-${{ matrix.variant }} | |
cache-to: type=gha,scope=${{ matrix.version }}-${{ matrix.variant }},mode=max | |
file: ${{ matrix.variant }}.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 }} | |
development: | |
needs: production | |
runs-on: ubuntu-latest | |
continue-on-error: true | |
strategy: | |
fail-fast: false | |
matrix: ${{ fromJSON(needs.matrix.outputs.matrix)}} | |
steps: | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
with: | |
platforms: all | |
- name: Set up Docker Buildx | |
id: buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Inspect builder | |
run: | | |
echo "Name: ${{ steps.buildx.outputs.name }}" | |
echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}" | |
echo "Status: ${{ steps.buildx.outputs.status }}" | |
echo "Flags: ${{ steps.buildx.outputs.flags }}" | |
echo "Platforms: ${{ steps.buildx.outputs.platforms }}" | |
- name: Login to GitHub Packages Docker Registry | |
uses: docker/login-action@v3 | |
with: | |
password: ${{ secrets.GHT }} | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
- 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 | |
uses: docker/build-push-action@v6 | |
with: | |
cache-from: type=gha,scope=${{ matrix.version }} | |
cache-to: type=gha,scope=${{ matrix.version }},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 }} |