diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0714ceb..0360055 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,6 +1,16 @@ name: Publish Docker images -on: [push,workflow_dispatch] +on: + push: + branches: [master] + paths: + - 'php-fpm/**' + - 'nginx-wordpress/**' + - 'nginx-symfony/**' + - 'nginx-magento2/**' + - 'ci-shopware6/**' + - 'awx-ee/**' + workflow_dispatch: jobs: publish-php-fpm: diff --git a/.github/workflows/php-cli.yml b/.github/workflows/php-cli.yml new file mode 100644 index 0000000..cfade4a --- /dev/null +++ b/.github/workflows/php-cli.yml @@ -0,0 +1,74 @@ +name: PHP CLI build images + +on: + pull_request: + paths: ['php-cli/**', '.github/workflows/php-cli.yml'] + push: + branches: [master] + paths: ['php-cli/**', '.github/workflows/php-cli.yml'] + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: php-cli-${{ github.ref }} + cancel-in-progress: true + +jobs: + matrix: + runs-on: ubuntu-latest + outputs: + images: ${{ steps.manifest.outputs.images }} + steps: + - uses: actions/checkout@v7 + - id: manifest + run: | + echo "images=$(jq -c '.images' php-cli/images.json)" >> "$GITHUB_OUTPUT" + + build-test: + needs: matrix + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + strategy: + fail-fast: false + matrix: + include: ${{ fromJSON(needs.matrix.outputs.images) }} + steps: + - uses: actions/checkout@v7 + - uses: docker/setup-buildx-action@v4 + - name: Build PHP ${{ matrix.version }} + uses: docker/build-push-action@v7 + with: + context: php-cli + build-args: BASE_IMAGE=${{ matrix.baseImage }} + platforms: linux/amd64 + pull: true + load: true + tags: intercube-php-cli:test + cache-from: type=gha,scope=php-cli-${{ matrix.version }} + cache-to: type=gha,mode=max,scope=php-cli-${{ matrix.version }} + - name: Verify extensions and non-root Composer + env: + BASE_IMAGE: ${{ matrix.baseImage }} + PHP_VERSION: ${{ matrix.version }} + run: bash php-cli/test-image.sh intercube-php-cli:test "$BASE_IMAGE" "$PHP_VERSION" + - name: Log in to GHCR + if: github.event_name != 'pull_request' && github.ref == 'refs/heads/master' + uses: docker/login-action@v4 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Publish tested image + if: github.event_name != 'pull_request' && github.ref == 'refs/heads/master' + env: + PHP_VERSION: ${{ matrix.version }} + run: | + image="ghcr.io/intercube/docker/php-cli" + for tag in "$PHP_VERSION-latest" "$PHP_VERSION-$GITHUB_SHA-$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT"; do + docker tag intercube-php-cli:test "$image:$tag" + docker push "$image:$tag" + done diff --git a/php-cli/Dockerfile b/php-cli/Dockerfile new file mode 100644 index 0000000..f56772c --- /dev/null +++ b/php-cli/Dockerfile @@ -0,0 +1,7 @@ +ARG BASE_IMAGE +FROM ${BASE_IMAGE} + +LABEL org.opencontainers.image.source="https://github.com/intercube/Docker" \ + org.opencontainers.image.description="Intercube PHP CLI build image with FTP support" + +RUN install-php-extensions ftp diff --git a/php-cli/README.md b/php-cli/README.md new file mode 100644 index 0000000..7047f76 --- /dev/null +++ b/php-cli/README.md @@ -0,0 +1,63 @@ +# PHP CLI build images + +These images extend Chialab's PHP CLI images with FTP and FTPS for Composer and +Magento build steps. They preserve the base image's extensions, Composer, entry +point and support for GoCD's arbitrary non-root user. They are separate from the +older PHP-FPM development image in this repository. + +`images.json` lists the PHP versions used by the active GoCD configurations on +27 October 2026: 7.4 and 8.0–8.5. Each build pulls the current Chialab tag for that +PHP minor version. Legacy +versions are included for existing projects; this does not change their PHP +support lifecycle or the PHP versions a particular Magento release supports. + +## Build and test + +```bash +base_image=$(jq -r '.images[] | select(.version == "8.4") | .baseImage' php-cli/images.json) +docker build --build-arg "BASE_IMAGE=$base_image" -t intercube-php-cli:test php-cli +bash php-cli/test-image.sh intercube-php-cli:test "$base_image" 8.4 +``` + +Pull requests build and test every listed version without publishing. Changes +merged to `master` publish tested `linux/amd64` images to +`ghcr.io/intercube/docker/php-cli`, matching the current GoCD runner architecture. +Build pipelines use version-specific moving tags such as +`ghcr.io/intercube/docker/php-cli:8.4-latest`. Every published image also gets a +unique tag containing the PHP version, source commit, workflow run and attempt +for diagnostics and rollback. These are build images and do not configure the +PHP runtime on hosting servers. + +## Nexus rollout + +1. Verify the published image can be pulled by the GoCD agents. +2. In Nexus, create project overrides for every PHP build step of the initial + development project: Composer install, dependency compilation and static + content deployment. Preserve the task, ordering and working directory. +3. Set each override's Docker image to the same PHP version's `-latest` tag. + Nexus pulls Intercube PHP CLI `-latest` images before use, so cached images do + not prevent published updates reaching build agents. + Synchronize that project's template through Nexus; do not hand-edit its + generated GoCD JSON, which Nexus would overwrite on the next sync. +4. Run the development pipeline and verify Composer, Magento compilation, release + artifact upload, deployment and the site's response. Also verify FTP in the + target server's PHP CLI separately; the build image does not change hosting. +5. After the pilot succeeds, migrate shared defaults and existing image overrides + deliberately. Preserve custom third-party images and each project's PHP + version. Retain the previous image reference for rollback. + +Keep Composer's platform checks enabled and keep the application's lock file. +Additional extensions should come from a demonstrated application requirement, +with matching image checks, rather than bypassing Composer requirements. + +## Updates + +Run the PHP CLI build workflow on `master` to refresh from Chialab's current +version-specific tags. A version's compatibility checks must pass before its +`-latest` tag is published. Existing pipelines using that tag receive the updated +image on their next build. For an image regression, switch the affected project's +build steps to the previous run's unique image tag while investigating. + +Adding a PHP version or changing image behavior requires a reviewed change and +the complete version matrix to pass. Check application lock files as part of the +development rollout; the smoke fixture checks FTP without downloading Magento. diff --git a/php-cli/images.json b/php-cli/images.json new file mode 100644 index 0000000..5fe8af1 --- /dev/null +++ b/php-cli/images.json @@ -0,0 +1,32 @@ +{ + "images": [ + { + "version": "7.4", + "baseImage": "chialab/php:7.4" + }, + { + "version": "8.0", + "baseImage": "chialab/php:8.0" + }, + { + "version": "8.1", + "baseImage": "chialab/php:8.1" + }, + { + "version": "8.2", + "baseImage": "chialab/php:8.2" + }, + { + "version": "8.3", + "baseImage": "chialab/php:8.3" + }, + { + "version": "8.4", + "baseImage": "chialab/php:8.4" + }, + { + "version": "8.5", + "baseImage": "chialab/php:8.5" + } + ] +} diff --git a/php-cli/test-image.sh b/php-cli/test-image.sh new file mode 100755 index 0000000..2acbbc0 --- /dev/null +++ b/php-cli/test-image.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +set -euo pipefail + +image="${1:?Usage: test-image.sh IMAGE BASE_IMAGE PHP_VERSION}" +base_image="${2:?Base image is required}" +php_version="${3:?PHP minor version is required}" +fixture="$(mktemp -d)" +trap 'rm -rf "$fixture"' EXIT + +# Keep every extension supplied by Chialab, in addition to FTP and FTPS. +docker run --rm "$base_image" php -r 'echo json_encode(get_loaded_extensions());' > "$fixture/base-extensions.json" +cat > "$fixture/check.php" <<'PHP' + "$fixture/composer.json" <<'JSON' +{ + "name": "intercube/php-build-smoke-test", + "require": { "ext-ftp": "*" }, + "repositories": [ { "packagist.org": false } ] +} +JSON + +# Match GoCD's arbitrary non-root UID, writable source directory and Composer cache. +docker run --rm --user "$(id -u):$(id -g)" \ + -e COMPOSER_HOME=/mnt/pipeline/.composer \ + -w /mnt/pipeline -v "$fixture:/mnt/pipeline" \ + "$image" sh -ec 'php check.php "$1"; composer install --no-dev --no-plugins --no-scripts --no-interaction --no-progress; composer check-platform-reqs --no-dev' sh "$php_version"