Skip to content

Build base Docker images #279

Build base Docker images

Build base Docker images #279

name: Build base Docker images
on:
push:
pull_request:
workflow_dispatch:
schedule:
- cron: '0 0 * * 1'
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
cfg:
- { PHP_VERSION: "8.5", PHP_VERSION_FPM: php85-fpm }
- { PHP_VERSION: "8.4", PHP_VERSION_FPM: php84-fpm }
- { PHP_VERSION: "8.3", PHP_VERSION_FPM: php83-fpm }
- { PHP_VERSION: "8.2", PHP_VERSION_FPM: php82-fpm }
- { PHP_VERSION: "8.1", PHP_VERSION_FPM: php81-fpm }
- { PHP_VERSION: "7.4", PHP_VERSION_FPM: php74-fpm }
- { PHP_VERSION: "7.3", PHP_VERSION_FPM: php73-fpm }
- { PHP_VERSION: "7.2", PHP_VERSION_FPM: php72-fpm }
- { PHP_VERSION: "7.1", PHP_VERSION_FPM: php71-fpm }
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# Step 1: Build the docker image (load into local docker for testing)
- name: Build the Docker image
uses: docker/build-push-action@v6
with:
context: .
load: true
tags: |
michielgerritsen/magento2-base-image:${{ matrix.cfg.PHP_VERSION }}
michielgerritsen/magento2-base-image:${{ matrix.cfg.PHP_VERSION_FPM }}
build-args: PHP_VERSION=${{ matrix.cfg.PHP_VERSION }}
cache-from: type=gha
cache-to: type=gha,mode=max
# Step 2: Test the docker image
- name: Test that the image is working
run: |
docker run -v ${{ github.workspace }}/tests:/tests \
-e PHP_VERSION=${{ matrix.cfg.PHP_VERSION }} \
michielgerritsen/magento2-base-image:${{ matrix.cfg.PHP_VERSION }} \
bash -c './start-services && /tests/run-tests.sh'
- name: Test Varnish support
run: |
docker run -v ${{ github.workspace }}/tests:/tests \
-e ENABLE_VARNISH=true \
-e PHP_VERSION=${{ matrix.cfg.PHP_VERSION }} \
michielgerritsen/magento2-base-image:${{ matrix.cfg.PHP_VERSION }} \
bash -c './start-services && /tests/run-tests.sh'
# Step 3: Push images (single push per registry, avoids duplicate untagged entries)
- name: Login to Docker Hub
if: github.ref == 'refs/heads/main'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Login to ghcr.io
if: github.ref == 'refs/heads/main'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push images
if: github.ref == 'refs/heads/main'
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: |
michielgerritsen/magento2-base-image:${{ matrix.cfg.PHP_VERSION }}
michielgerritsen/magento2-base-image:${{ matrix.cfg.PHP_VERSION_FPM }}
ghcr.io/${{ github.repository }}/magento2-base-image:${{ matrix.cfg.PHP_VERSION }}
ghcr.io/${{ github.repository }}/magento2-base-image:${{ matrix.cfg.PHP_VERSION_FPM }}
build-args: PHP_VERSION=${{ matrix.cfg.PHP_VERSION }}
cache-from: type=gha