Docker CI/CD #18875
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: | |
- main | |
schedule: | |
- cron: "* */4 * * *" # Runs every 4 hours. | |
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/${{ github.repository_owner }}/php" | |
jobs: | |
cli: | |
runs-on: ubuntu-latest | |
continue-on-error: true | |
strategy: | |
fail-fast: false | |
matrix: | |
version: | |
- "7.3" | |
- "7.4" | |
- "8.0" | |
- "8.1" | |
- "8.2" | |
- "8.3" | |
- "8.4" | |
latest: | |
- "8.3" | |
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 }}-cli | |
type=raw,value=${{ matrix.version }} | |
type=raw,value=latest,enable=${{ matrix.latest == matrix.version }} | |
- name: Build and push PHP ${{ matrix.version }} | |
uses: docker/build-push-action@v5 | |
with: | |
cache-from: type=gha,scope=${{ matrix.version }}-cli | |
cache-to: type=gha,scope=${{ matrix.version }}-cli,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 }} | |
fpm: | |
runs-on: ubuntu-latest | |
continue-on-error: true | |
strategy: | |
fail-fast: false | |
matrix: | |
version: | |
- "7.3" | |
- "7.4" | |
- "8.0" | |
- "8.1" | |
- "8.2" | |
- "8.3" | |
- "8.4" | |
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 }}-fpm | |
- name: Build and push PHP ${{ matrix.version }} | |
uses: docker/build-push-action@v5 | |
with: | |
cache-from: type=gha,scope=${{ matrix.version }}-fpm | |
cache-to: type=gha,scope=${{ matrix.version }}-fpm,mode=max | |
file: ./fpm.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 }} | |
composer: | |
needs: cli | |
runs-on: ubuntu-latest | |
continue-on-error: true | |
strategy: | |
fail-fast: false | |
matrix: | |
version: | |
- "7.3" | |
- "7.4" | |
- "8.0" | |
- "8.1" | |
- "8.2" | |
- "8.3" | |
- "8.4" | |
type: | |
- composer | |
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.type }} | |
- name: Build and push PHP ${{ matrix.version }}-${{ matrix.type }} image | |
uses: docker/build-push-action@v5 | |
with: | |
cache-from: type=gha,scope=${{ matrix.version }}-${{ matrix.type }} | |
cache-to: type=gha,scope=${{ matrix.version }}-${{ matrix.type }},mode=max | |
file: ./composer.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 }} | |
extensions: | |
needs: composer | |
runs-on: ubuntu-latest | |
continue-on-error: true | |
strategy: | |
fail-fast: false | |
matrix: | |
version: | |
- "7.3" | |
- "7.4" | |
- "8.0" | |
- "8.1" | |
- "8.2" | |
- "8.3" | |
- "8.4" | |
type: | |
- pcov | |
- pgsql | |
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.type }} | |
- name: Build and push PHP ${{ matrix.version }}-${{ matrix.type }} | |
uses: docker/build-push-action@v5 | |
with: | |
cache-from: type=gha,scope=${{ matrix.version }}-${{ matrix.type }} | |
cache-to: type=gha,scope=${{ matrix.version }}-${{ matrix.type }},mode=max | |
file: ./extension.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_EXTENSION=${{ matrix.type }} |