Skip to content

PHP Docker Image CI for Sylius #11

PHP Docker Image CI for Sylius

PHP Docker Image CI for Sylius #11

Workflow file for this run

name: PHP Docker Image CI for Sylius
on:
workflow_dispatch:
push:
branches: [ main ]
paths:
- 'php/**'
- 'WORKSPACE'
schedule:
- cron: '0 20 * * 5'
concurrency:
group: sylius_php_build
cancel-in-progress: false
jobs:
build:
name: "Sylius PHP - ${{ matrix.php }}-${{ matrix.distro }}"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: [ "7.3", "7.4", "8.0", "8.1", "8.2", "8.3" ]
distro: [ "alpine" ]
steps:
- uses: actions/[email protected]
- name: Generate UUID
id: generate-uuid
run: |
UUID=$(cat /proc/sys/kernel/random/uuid)
echo "UUID=${UUID}" >> $GITHUB_OUTPUT
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Docker meta
id: meta
uses: docker/[email protected]
with:
images: ${{ vars.DOCKER_PHP_REPOSITORY_NAME }}
tags: |
type=raw,value=${{ matrix.php }}-${{ matrix.distro }}
labels: |
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
org.opencontainers.image.description=Sylius PHP ${{ matrix.php }} Docker image
org.opencontainers.image.licenses=MIT
- name: Set up Docker Buildx
uses: docker/[email protected]
- name: Cache Docker layers
uses: actions/[email protected]
with:
path: /tmp/.buildx-cache
key: "${{ runner.os }}-php-${{ matrix.php }}-${{ matrix.distro }}-buildx-cache-${{ vars.CACHE_VERSION }}-${{ steps.generate-uuid.outputs.uuid }}"
# https://github.com/actions/cache/issues/109#issuecomment-558771281
# https://github.community/t/always-save-new-cache-for-incremental-builds/172791
restore-keys: "${{ runner.os }}-php-${{ matrix.php }}-${{ matrix.distro }}-buildx-cache-${{ vars.CACHE_VERSION }}-"
- name: Docker Login
uses: docker/[email protected]
with:
registry: ${{ secrets.DOCKER_REGISTRY }}
username: ${{ secrets.DOCKER_REPOSITORY_LOGIN }}
password: ${{ secrets.DOCKER_REPOSITORY_PASSWORD }}
logout: true
- name: Build multiplatform
uses: docker/[email protected]
with:
file: ./php/Dockerfile
context: ./php
build-args: "PHP_SHORT_VERSION=${{ matrix.php }}"
platforms: linux/amd64,linux/arm64
push: false
pull: true
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new
- name: Build linux/amd64 to tar
uses: docker/[email protected]
with:
file: ./php/Dockerfile
context: ./php
build-args: "PHP_SHORT_VERSION=${{ matrix.php }}"
platforms: linux/amd64
push: false
pull: false
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=local,src=/tmp/.buildx-cache-new
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new-amd64
outputs: type=docker,dest=./external/image-amd64.tar
- name: Build linux/arm64 to tar
uses: docker/[email protected]
with:
file: ./php/Dockerfile
context: ./php
build-args: "PHP_SHORT_VERSION=${{ matrix.php }}"
platforms: linux/arm64
push: false
pull: false
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=local,src=/tmp/.buildx-cache-new
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new-arm64
outputs: type=docker,dest=./external/image-arm64.tar
- name: Mount Bazel cache
uses: actions/[email protected]
with:
path: "~/.cache/bazel"
key: "${{ runner.os }}-php-${{ matrix.php }}-${{ matrix.distro }}-bazel-cache-${{ vars.CACHE_VERSION }}-${{ steps.generate-uuid.outputs.uuid }}"
restore-keys: "${{ runner.os }}-php-${{ matrix.php }}-${{ matrix.distro }}-bazel-cache-${{ vars.CACHE_VERSION }}-"
- name: Setup PHP for Bazel
run: |
set -ex
cat > php/php-version.bzl <<EOF
PHP_VERSION = "${{ matrix.php }}"
EOF
- name: Bazel build and test
run: |
set -ex
targets=$(bazel query 'attr(visibility, "//visibility:public", //php:*)' | sort)
bazel build --curses=no ${targets}
bazel test --curses=no --test_output=errors ${targets}
- name: Push
uses: docker/[email protected]
with:
file: ./php/Dockerfile
context: ./php
build-args: "PHP_SHORT_VERSION=${{ matrix.php }}"
platforms: linux/amd64,linux/arm64
push: ${{ github.ref == 'refs/heads/main' || github.event_name == 'release' }}
pull: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache-new
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
build-xdebug:
needs: build
name: "Sylius PHP with Xdebug - ${{ matrix.php }}-${{ matrix.distro }}"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: [ "7.3", "7.4", "8.0", "8.1", "8.2", "8.3" ]
distro: [ "alpine" ]
steps:
- uses: actions/[email protected]
- name: Generate UUID
id: generate-uuid
run: |
UUID=$(cat /proc/sys/kernel/random/uuid)
echo "UUID=${UUID}" >> $GITHUB_OUTPUT
- name: Set up QEMU
id: qemu
uses: docker/setup-qemu-action@v3
- name: Available platforms
run: echo ${{ steps.qemu.outputs.platforms }}
- name: Docker meta
id: meta
uses: docker/[email protected]
with:
images: ${{ vars.DOCKER_PHP_REPOSITORY_NAME }}
tags: |
type=raw,value=${{ matrix.php }}-xdebug-${{ matrix.distro }}
- name: Set up Docker Buildx
uses: docker/[email protected]
- name: Cache Docker layers
uses: actions/[email protected]
with:
path: /tmp/.buildx-cache
key: "${{ runner.os }}-php-xdebug-${{ matrix.php }}-${{ matrix.distro }}-buildx-cache-${{ vars.CACHE_VERSION }}-${{ steps.generate-uuid.outputs.uuid }}"
# https://github.com/actions/cache/issues/109#issuecomment-558771281
# https://github.community/t/always-save-new-cache-for-incremental-builds/172791
restore-keys: "${{ runner.os }}-php-xdebug-${{ matrix.php }}-${{ matrix.distro }}-buildx-cache-${{ vars.CACHE_VERSION }}-"
- name: Docker Login
uses: docker/[email protected]
with:
registry: ${{ secrets.DOCKER_REGISTRY }}
username: ${{ secrets.DOCKER_REPOSITORY_LOGIN }}
password: ${{ secrets.DOCKER_REPOSITORY_PASSWORD }}
logout: true
- name: Prepare variable names for Docker build
id: docker-build-variable-names
run: |
PHP_VERSION="${{ matrix.php }}"
PHP_XDEBUG_VERSION_VARIABLE=XDEBUG_VERSION_PHP_${PHP_VERSION//./_}
echo "XDEBUG_VERSION=$(jq -r --arg PHP_XDEBUG_VERSION_VARIABLE "$PHP_XDEBUG_VERSION_VARIABLE" '.[$PHP_XDEBUG_VERSION_VARIABLE]' <<< '${{ toJSON(vars) }}')" >> $GITHUB_ENV
- name: Build and push
uses: docker/[email protected]
with:
file: ./php/xdebug.Dockerfile
context: ./php
build-args: |
"IMAGE_NAME=${{ vars.DOCKER_PHP_REPOSITORY_NAME }}"
"IMAGE_TAG=${{ matrix.php }}-${{ matrix.distro }}"
"XDEBUG_VERSION=${{ env.XDEBUG_VERSION }}"
platforms: linux/amd64,linux/arm64
push: ${{ github.ref == 'refs/heads/main' || github.event_name == 'release' }}
pull: true
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
build-fixuid:
needs: build-xdebug
name: "Sylius PHP with boxboat/fixuid - ${{ matrix.php }}-${{ matrix.version }}"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: [ "7.3", "7.4", "8.0", "8.1", "8.2", "8.3" ]
version: [ "alpine", "xdebug-alpine" ]
steps:
- uses: actions/[email protected]
- name: Generate UUID
id: generate-uuid
run: |
UUID=$(cat /proc/sys/kernel/random/uuid)
echo "UUID=${UUID}" >> $GITHUB_OUTPUT
- name: Set up QEMU
id: qemu
uses: docker/setup-qemu-action@v3
- name: Docker meta
id: meta
uses: docker/[email protected]
with:
images: ${{ vars.DOCKER_PHP_REPOSITORY_NAME }}
tags: |
type=raw,value=${{ matrix.php }}-fixuid-${{ matrix.version }}
- name: Set up Docker Buildx
uses: docker/[email protected]
- name: Cache Docker layers
uses: actions/[email protected]
with:
path: /tmp/.buildx-cache
key: "${{ runner.os }}-php-fixuid-${{ matrix.php }}-${{ matrix.version }}-buildx-cache-${{ vars.CACHE_VERSION }}-${{ steps.generate-uuid.outputs.uuid }}"
# https://github.com/actions/cache/issues/109#issuecomment-558771281
# https://github.community/t/always-save-new-cache-for-incremental-builds/172791
restore-keys: "${{ runner.os }}-php-fixuid-${{ matrix.php }}-${{ matrix.version }}-buildx-cache-${{ vars.CACHE_VERSION }}-"
- name: Docker Login
uses: docker/[email protected]
with:
registry: ${{ secrets.DOCKER_REGISTRY }}
username: ${{ secrets.DOCKER_REPOSITORY_LOGIN }}
password: ${{ secrets.DOCKER_REPOSITORY_PASSWORD }}
logout: true
- name: Build and push
uses: docker/[email protected]
with:
file: ./php-fixuid/Dockerfile
context: ./php-fixuid
build-args: |
"IMAGE_NAME=${{ vars.DOCKER_PHP_REPOSITORY_NAME }}"
"IMAGE_TAG=${{ matrix.php }}-${{ matrix.version }}"
platforms: linux/amd64,linux/arm64
push: ${{ github.ref == 'refs/heads/main' || github.event_name == 'release' }}
pull: true
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache