Skip to content

Revamp GitHub Actions workflows for PHP-FPM and CLI: #5

Revamp GitHub Actions workflows for PHP-FPM and CLI:

Revamp GitHub Actions workflows for PHP-FPM and CLI: #5

Workflow file for this run

name: PHP-CLI
on:
push:
branches: [ main ]
paths:
- 'docker/php/cli/**'
- '.github/workflows/build-cli.yml'
schedule:
- cron: '0 2 * * 1' # weekly rebuild
workflow_dispatch:
env:
IMAGE: ghcr.io/liquidrazor/php
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
jobs:
# =========================
# Build (CLI) per-arch
# =========================
build-amd64:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- var: PHP_LATEST
- var: PHP_PREVIOUS
env:
ARCH_SUFFIX: amd64
PHP_VERSION: ${{ vars[matrix.version.var] }}
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
with:
driver: docker-container
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Compute tags (CLI)
id: tags
shell: bash
run: |
set -euo pipefail
PHP_VERSION="${PHP_VERSION:?missing}"
LINE_VERSION="$(cut -d. -f1,2 <<<"$PHP_VERSION")"
IS_LATEST="${{ matrix.version.is_latest }}"
TAGS=("php-${LINE_VERSION}-cli" "php-${PHP_VERSION}-cli")
if [[ "$IS_LATEST" == "true" ]]; then
TAGS=("php-cli" "${TAGS[@]}")
fi
ARCH="${ARCH_SUFFIX}"
mapfile -t TAGS_WITH_ARCH < <(for t in "${TAGS[@]}"; do printf "%s:%s-%s\n" "${IMAGE}" "$t" "${ARCH}"; done)
printf "tags_no_arch<<'EOF'\n%s\nEOF\n" "$(printf "%s\n" "${TAGS[@]}")" >> "$GITHUB_OUTPUT"
printf "tags_with_arch<<'EOF'\n%s\nEOF\n" "$(printf "%s\n" "${TAGS_WITH_ARCH[@]}")" >> "$GITHUB_OUTPUT"
- uses: docker/build-push-action@v6
with:
context: docker/php/cli/base
file: docker/php/cli/base/Dockerfile
push: true
platforms: linux/amd64
build-args: |
PHP_VERSION=${{ env.PHP_VERSION }}
tags: ${{ steps.tags.outputs.tags_with_arch }}
cache-from: |
type=registry,ref=${{ env.IMAGE }}:buildcache-cli-${{ env.PHP_VERSION }}-amd64
type=gha,scope=cli-${{ env.PHP_VERSION }}-amd64
cache-to: |
type=registry,ref=${{ env.IMAGE }}:buildcache-cli-${{ env.PHP_VERSION }}-amd64,mode=max
type=gha,scope=cli-${{ env.PHP_VERSION }}-amd64,mode=max
sbom: false
provenance: false
build-arm64:
runs-on: ubuntu-24.04-arm64 # or your self-hosted ARM64 runner label
strategy:
fail-fast: false
matrix:
include:
- var: PHP_LATEST
- var: PHP_PREVIOUS
env:
ARCH_SUFFIX: arm64
PHP_VERSION: ${{ vars[matrix.version.var] }}
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
with:
driver: docker-container
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Compute tags (CLI)
id: tags
shell: bash
run: |
set -euo pipefail
PHP_VERSION="${PHP_VERSION:?missing}"
LINE_VERSION="$(cut -d. -f1,2 <<<"$PHP_VERSION")"
IS_LATEST="${{ matrix.version.is_latest }}"
TAGS=("php-${LINE_VERSION}-cli" "php-${PHP_VERSION}-cli")
if [[ "$IS_LATEST" == "true" ]]; then
TAGS=("php-cli" "${TAGS[@]}")
fi
ARCH="${ARCH_SUFFIX}"
mapfile -t TAGS_WITH_ARCH < <(for t in "${TAGS[@]}"; do printf "%s:%s-%s\n" "${IMAGE}" "$t" "${ARCH}"; done)
printf "tags_no_arch<<'EOF'\n%s\nEOF\n" "$(printf "%s\n" "${TAGS[@]}")" >> "$GITHUB_OUTPUT"
printf "tags_with_arch<<'EOF'\n%s\nEOF\n" "$(printf "%s\n" "${TAGS_WITH_ARCH[@]}")" >> "$GITHUB_OUTPUT"
- uses: docker/build-push-action@v6
with:
context: docker/php/cli/base
file: docker/php/cli/base/Dockerfile
push: true
platforms: linux/arm64
build-args: |
PHP_VERSION=${{ env.PHP_VERSION }}
tags: ${{ steps.tags.outputs.tags_with_arch }}
cache-from: |
type=registry,ref=${{ env.IMAGE }}:buildcache-cli-${{ env.PHP_VERSION }}-arm64
type=gha,scope=cli-${{ env.PHP_VERSION }}-arm64
cache-to: |
type=registry,ref=${{ env.IMAGE }}:buildcache-cli-${{ env.PHP_VERSION }}-arm64,mode=max
type=gha,scope=cli-${{ env.PHP_VERSION }}-arm64,mode=max
sbom: false
provenance: false
# =========================
# Multi-arch manifests
# =========================
manifest:
runs-on: ubuntu-latest
needs: [build-amd64, build-arm64]
strategy:
fail-fast: false
matrix:
include:
- var: PHP_LATEST
- var: PHP_PREVIOUS
env:
PHP_VERSION: ${{ vars[matrix.version.var] }}
steps:
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Recompute final tags (CLI)
id: tags
shell: bash
run: |
set -euo pipefail
PHP_VERSION="${PHP_VERSION:?missing}"
LINE_VERSION="$(cut -d. -f1,2 <<<"$PHP_VERSION")"
IS_LATEST="${{ matrix.version.is_latest }}"
TAGS=("php-${LINE_VERSION}-cli" "php-${PHP_VERSION}-cli")
if [[ "$IS_LATEST" == "true" ]]; then
TAGS=("php-cli" "${TAGS[@]}")
fi
printf "tags_no_arch<<'EOF'\n%s\nEOF\n" "$(printf "%s\n" "${TAGS[@]}")" >> "$GITHUB_OUTPUT"
- name: Publish multi-arch manifests (CLI)
shell: bash
env:
IMAGE: ${{ env.IMAGE }}
run: |
set -euo pipefail
while IFS= read -r TAG; do
echo "Creating manifest for ${IMAGE}:${TAG}"
docker buildx imagetools create \
-t "${IMAGE}:${TAG}" \
"${IMAGE}:${TAG}-amd64" \
"${IMAGE}:${TAG}-arm64"
done <<< "${{ steps.tags.outputs.tags_no_arch }}"