Skip to content

Docker Build & Release #386

Docker Build & Release

Docker Build & Release #386

Workflow file for this run

name: Docker Build & Release
on:
workflow_dispatch:
push:
tags:
- 'v*.*'
schedule:
- cron: '30 2 * * 1,3,5'
env:
IMAGE_NAME: pimcore/pimcore
jobs:
build-php:
name: "Build PHP images"
runs-on: ubuntu-latest
if: github.repository == 'pimcore/docker'
strategy:
matrix:
include:
- { tag: '1.x', php: '8.0', distro: bullseye, version-override: "v1-dev", latest-tag: false }
- { tag: '1.x', php: '8.1', distro: bullseye, version-override: "v1-dev", latest-tag: false }
- { tag: '1.x', php: '8.2', distro: bullseye, version-override: "v1-dev", latest-tag: false }
- { tag: 'v1.3', php: '8.0', distro: bullseye, version-override: "", latest-tag: true }
- { tag: 'v1.3', php: '8.1', distro: bullseye, version-override: "", latest-tag: true }
- { tag: 'v1.3', php: '8.2', distro: bullseye, version-override: "", latest-tag: false }
- { tag: 'v2.0', php: '8.2', distro: bullseye, version-override: "", latest-tag: false }
- { tag: '2.x', php: '8.2', distro: bullseye, version-override: "v2-dev", latest-tag: false }
- { tag: 'v3.0', php: '8.2', distro: bookworm, version-override: "", latest-tag: false }
- { tag: 'v3.1', php: '8.2', distro: bookworm, version-override: "", latest-tag: false }
- { tag: 'v3.2', php: '8.2', distro: bookworm, version-override: "", latest-tag: false }
- { tag: 'v3.3', php: '8.2', distro: bookworm, version-override: "", latest-tag: true }
- { tag: 'v3.3', php: '8.3', distro: bookworm, imagick_version_from_src: 28f27044e435a2b203e32675e942eb8de620ee58, version-override: "", latest-tag: true }
- { tag: '3.x', php: '8.2', distro: bookworm, version-override: "v3-dev", latest-tag: false }
- { tag: '3.x', php: '8.3', distro: bookworm, imagick_version_from_src: 28f27044e435a2b203e32675e942eb8de620ee58, version-override: "v3-dev", latest-tag: false }
steps:
- uses: actions/checkout@v4
with:
ref: ${{ matrix.tag }}
- name: Login to DockerHub Registry
run: echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ matrix.php }}-${{ matrix.distro }}-${{ matrix.tag }}
restore-keys: |
${{ runner.os }}-buildx-${{ matrix.php }}-${{ matrix.distro }}-${{ matrix.tag }}-
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: 'amd64,arm64'
- name: Set up Buildx
uses: docker/setup-buildx-action@v3
- name: Configure and build images
id: vars
env:
VERSION_OVERRIDE: "${{ matrix.version-override }}"
run: |
set -eux;
if [[ "${{ matrix.tag }}" =~ ^v?1.[0-9x]+$ ]]; then
imageVariants=("fpm" "debug" "supervisord")
else
imageVariants=("min" "default" "max" "debug" "supervisord")
fi
for imageVariant in ${imageVariants[@]}; do
echo "Building image variant $imageVariant"
DOCKER_PLATFORMS=linux/amd64,linux/arm64
PHP_VERSION=${{ matrix.php }}
DEBIAN_VERSION="${{ matrix.distro }}"
VERSION="${{ matrix.tag }}"
# for the latest dev branch we use "dev" as the version and not the name of the branch
if [ ! -z "$VERSION_OVERRIDE" ]; then
VERSION="$VERSION_OVERRIDE"
fi
PHP_SUB_VERSION=$(docker run -i --rm php:${{ matrix.php }}-fpm-${{ matrix.distro }} php -r 'echo PHP_VERSION;')
if [ "$imageVariant" = "fpm" ] || [ "$imageVariant" = "default" ]; then
BASE_TAG="php${{ matrix.php }}"
BASE_TAG_DETAILED="php${PHP_SUB_VERSION}"
else
BASE_TAG="php${{ matrix.php }}-$imageVariant"
BASE_TAG_DETAILED="php${PHP_SUB_VERSION}-$imageVariant"
fi
# DEBUG / TEST
#BASE_TAG="testv3-$BASE_TAG"
#BASE_TAG_DETAILED="testv3-$BASE_TAG_DETAILED"
TAG="${BASE_TAG}-${VERSION}"
TAG_DETAILED="${BASE_TAG_DETAILED}-${VERSION}"
TAGS="--tag ${IMAGE_NAME}:${TAG}"
TAGS="$TAGS --tag ${IMAGE_NAME}:${TAG_DETAILED}"
# Tag latest with Version build too
if [ "true" = "${{ matrix.latest-tag }}" ]; then
TAGS="$TAGS --tag ${IMAGE_NAME}:${BASE_TAG}-latest"
fi
# Create tag for major version
if [[ $VERSION =~ ^v[0-9]+.[0-9]+$ ]]; then
VERSION_MAJOR=${VERSION//.[0-9]/}
TAGS="$TAGS --tag ${IMAGE_NAME}:${BASE_TAG}-${VERSION_MAJOR}"
fi
echo ${TAGS}
docker buildx build --output "type=image,push=true" --platform ${DOCKER_PLATFORMS} \
--target="pimcore_php_$imageVariant" \
--build-arg PHP_VERSION="${PHP_VERSION}" \
--build-arg DEBIAN_VERSION="${DEBIAN_VERSION}" \
--build-arg IMAGICK_VERSION_FROM_SRC="${{ matrix.imagick_version_from_src }}" \
--cache-from "type=local,src=/tmp/.buildx-cache" \
--cache-to "type=local,dest=/tmp/.buildx-cache-new" \
${TAGS} .
docker buildx imagetools inspect ${IMAGE_NAME}:${TAG} || true;
done
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache