Docker PHP Images GitHub workflow #487
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 PHP Images GitHub workflow | |
on: | |
pull_request: | |
branches: | |
- 'v4' | |
push: | |
branches: | |
- 'v4' | |
schedule: | |
- cron: '42 3 * * 0' | |
jobs: | |
test: | |
strategy: | |
fail-fast: false | |
matrix: | |
php_version: ['8.3','8.2','8.1','8.0','7.4','7.3','7.2'] | |
variant: ['apache','cli','fpm'] | |
# builder: [ {arch: "amd64", os: "ubuntu-latest"}, {arch: "arm64", os: "macos-latest"}] | |
builder: [ {arch: "amd64", os: "ubuntu-latest"}, {arch: "arm64", os: "ubuntu-latest"}] | |
runs-on: ${{ matrix.builder.os }} | |
name: Test ${{ matrix.php_version }}-${{ matrix.variant }} ${{ matrix.builder.arch }} only | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up Docker | |
# /!\ this action is marked as experimental | |
# It's required only for macos | |
if: ${{ matrix.builder.os == 'macos-latest' }} | |
uses: docker-practice/actions-setup-docker@master | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Build | |
run: | | |
PHP_VERSION="${{ matrix.php_version }}" | |
TAG_PREFIX="rc${GITHUB_RUN_ID}-" \ | |
docker buildx bake \ | |
--set "*.platform=linux/${{ matrix.builder.arch }}" \ | |
--set "*.output=type=docker" \ | |
--load \ | |
php${PHP_VERSION//.}-${{ matrix.variant }}-all | |
- name: Display tags built | |
run: | | |
docker image ls --filter="reference=thecodingmachine/php" --format "{{.CreatedAt}}\t{{.Size}}\t{{.Repository}}:{{.Tag}}" | |
- name: Test | |
run: | | |
TAG_PREFIX="rc${GITHUB_RUN_ID}-" \ | |
PHP_VERSION="${{ matrix.php_version }}" \ | |
BRANCH="v4" \ | |
VARIANT="${{ matrix.variant }}" \ | |
PLATFORM="linux/${{ matrix.builder.arch }}" \ | |
./tests-suite/bash_unit -f tap ./tests-suite/*.sh | |
publish: | |
# push ~ schedule | |
if: ${{ github.event_name == 'push' || github.event_name == 'schedule' }} | |
needs: | |
- test | |
runs-on: ubuntu-latest | |
name: Publish ${{ matrix.php_version }}-${{ matrix.variant }} multi-arch to dockerhub | |
strategy: | |
fail-fast: false | |
matrix: | |
php_version: ['8.3','8.2','8.1','8.0','7.4','7.3','7.2'] | |
variant: ['apache','cli','fpm'] | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to DockerHub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Fetch minor version of php | |
run: | | |
# Build slim one | |
PHP_VERSION="${{ matrix.php_version }}" | |
TAG_PREFIX="rc${GITHUB_RUN_ID}-" \ | |
docker buildx bake \ | |
--set "*.platform=linux/amd64" \ | |
--set "*.output=type=docker" \ | |
--load \ | |
php${PHP_VERSION//.}-slim-${{ matrix.variant }} | |
# Retrieve minor | |
PHP_PATCH_MINOR=`docker run --rm thecodingmachine/php:rc${GITHUB_RUN_ID}-${{ matrix.php_version }}-v4-slim-${{ matrix.variant }} php -v | head -n1 | grep -P '\d+\.\d+\.\d+' -o | head -n1` | |
echo "PHP_PATCH_MINOR=${PHP_PATCH_MINOR}" >> $GITHUB_ENV | |
- name: Display tags to build | |
run: | | |
PHP_VERSION="${{ matrix.php_version }}" | |
PHP_PATCH_MINOR="${{ env.PHP_PATCH_MINOR }}" \ | |
TAG_PREFIX="rc${GITHUB_RUN_ID}-" \ | |
IS_RELEASE="1" \ | |
docker buildx bake php${PHP_VERSION//.}-${{ matrix.variant }}-all --print --progress plain | jq ".target[].tags | join(\" \")" -r > "/tmp/tags.log" | |
cat "/tmp/tags.log" | |
- name: Build and push ${{ matrix.php_version }}-${{ matrix.variant }} | |
run: | | |
PHP_VERSION="${{ matrix.php_version }}" | |
PHP_PATCH_MINOR="${{ env.PHP_PATCH_MINOR }}" \ | |
TAG_PREFIX="rc${GITHUB_RUN_ID}-" \ | |
IS_RELEASE="1" \ | |
docker buildx bake \ | |
--set "*.platform=linux/amd64,linux/arm64" \ | |
--set "*.output=type=registry" \ | |
php${PHP_VERSION//.}-${{ matrix.variant }}-all | |
- name: Push artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ matrix.php_version }}-${{ matrix.variant }} | |
path: /tmp/tags.log | |
retention-days: 60 |