From 5d1c1c49a671186dea82319cdfee2e23877be0a9 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Wed, 11 Nov 2026 12:58:18 +1030 Subject: [PATCH] DO-2063: docker build/registry migration --- .github/workflows/build.yml | 15 ---------- .github/workflows/docker-build.yml | 47 ++++++++++++++++++++++++++++++ README.md | 23 +++++++++++---- hooks/build | 6 ---- 4 files changed, 65 insertions(+), 26 deletions(-) delete mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/docker-build.yml delete mode 100644 hooks/build diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 8808216..0000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,15 +0,0 @@ -name: Build - -on: [pull_request] - -jobs: - build: - runs-on: ubuntu-latest - strategy: - matrix: - php-version: [8.3, 8.4] - steps: - - uses: actions/checkout@v2 - with: - ref: ${{ github.event.release.target_commitish }} - - run: docker build . --build-arg PHP_VERSION=${{ matrix.php-version }} --build-arg ALPINE_VERSION=${{ vars.ALPINE_VERSION }} -t my-app:${{ matrix.php-version }} diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 0000000..e7dfca1 --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -0,0 +1,47 @@ +name: Build and Push Docker Image + +on: + pull_request: + push: + branches: + - main + - staging + workflow_dispatch: + +concurrency: + group: docker-build-${{ github.ref }} + cancel-in-progress: true + +permissions: + contents: read + packages: write + +jobs: + build-and-push: + name: PHP ${{ matrix.php-version }}${{ matrix.image.suffix }} + strategy: + fail-fast: false + matrix: + php-version: ['8.3', '8.4'] + image: + # Full pipe image (last Dockerfile stage) + - target: '' + suffix: '' + # Runtime-only image for CLI tools / IDE integrations + - target: standards-runtime + suffix: '-runtime' + uses: aligent/workflows/.github/workflows/docker-build.yml@main + with: + image-name: aligent/code-standards-pipe-php + target: ${{ matrix.image.target }} + # Only main/staging publish; pull requests and manual runs on other branches just build + push: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/staging' }} + build-args: | + PHP_VERSION=${{ matrix.php-version }} + ALPINE_VERSION=${{ vars.ALPINE_VERSION }} + # Tags: 8.4, 8.4-runtime (main); 8.4-experimental, 8.4-runtime-experimental (staging) + tags: | + type=raw,value=${{ matrix.php-version }}${{ matrix.image.suffix }}${{ github.ref_name == 'staging' && '-experimental' || '' }} + # Separate cache scope per matrix entry so builds don't overwrite each other's cache + cache-from: type=gha,scope=php-${{ matrix.php-version }}${{ matrix.image.suffix }} + cache-to: type=gha,mode=max,scope=php-${{ matrix.php-version }}${{ matrix.image.suffix }} diff --git a/README.md b/README.md index 9e5bb5c..547c8ff 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Add the following your `bitbucket-pipelines.yml` file: - step: name: "Code Standards check" script: - - pipe: docker://aligent/code-standards-pipe-php:8.2 + - pipe: docker://ghcr.io/aligent/code-standards-pipe-php:8.4 variables: STANDARDS: "Magento2" SKIP_DEPENDENCIES: "true" @@ -39,7 +39,7 @@ jobs: with: fetch-depth: 0 - name: Code Standards Test - uses: docker://aligent/code-standards-pipe-php:8.1 + uses: docker://ghcr.io/aligent/code-standards-pipe-php:8.4 env: STANDARDS: "Magento2" SKIP_DEPENDENCIES: "true" @@ -64,8 +64,21 @@ An intermediate build target `standards-runtime` is available which does not inc The following command can be used to invoke the pipe locally: ``` -docker run -v $PWD:/build --workdir=/build aligent/code-standards-pipe-php: +docker run -v $PWD:/build --workdir=/build ghcr.io/aligent/code-standards-pipe-php: ``` -Commits published to the `main` branch will trigger an automated build for the each of the configured PHP version. -Commits to `staging` will do the same but image tags will be suffixed with `-experimiental`. +## CI/CD + +Docker images are built and pushed to GitHub Container Registry (`ghcr.io/aligent/code-standards-pipe-php`) via GitHub Actions +(`.github/workflows/docker-build.yml`, using the shared `aligent/workflows` Docker build workflow). The workflow: + +- Builds every configured PHP version, as both the full pipe image (``) and the `standards-runtime` target (`-runtime`) +- Pushes images on commits to `main`; commits to `staging` push tags suffixed with `-experimental` +- Builds without pushing on pull requests +- Can be triggered manually + +### Required Variables + +| Variable | Description | +|----------|-------------| +| `ALPINE_VERSION` | Alpine version of the upstream `php:-alpine` image. The build fails if it is not set. | diff --git a/hooks/build b/hooks/build deleted file mode 100644 index 4ff514d..0000000 --- a/hooks/build +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -if [[ "$DOCKER_TAG" == *"runtime"* ]]; then - docker build --target standards-runtime --build-arg PHP_VERSION="$(echo $DOCKER_TAG | sed 's/-experimental//g' | sed 's/-runtime//g')" --build-arg ALPINE_VERSION="${ALPINE_VERSION:-}" -f $DOCKERFILE_PATH -t $IMAGE_NAME . -else - docker build --build-arg PHP_VERSION="$(echo $DOCKER_TAG | sed 's/-experimental//g')" --build-arg ALPINE_VERSION="${ALPINE_VERSION:-}" -f $DOCKERFILE_PATH -t $IMAGE_NAME . -fi