From 739d746bd96bf38a1e53ec76568439a456d96c75 Mon Sep 17 00:00:00 2001 From: Navarr Date: Fri, 3 Mar 2023 10:56:44 -0500 Subject: [PATCH 01/11] Update to CentOS 9, add aarch64/arm64 support to PHP images --- php/README.md | 2 +- php/cli-loaders/Dockerfile | 15 +++++++++++---- php/cli/Dockerfile | 4 ++-- php/fpm-loaders/Dockerfile | 16 ++++++++++++---- php/scripts/build.sh | 3 ++- scripts/build.sh | 3 ++- 6 files changed, 30 insertions(+), 13 deletions(-) diff --git a/php/README.md b/php/README.md index 405c3c0..053064d 100644 --- a/php/README.md +++ b/php/README.md @@ -19,7 +19,7 @@ Images for older versions of PHP may be available (see Docker Hub for available ## Additional Extensions -These images are built top of the official CentOS Stream 8 images using Remi's RPMs Repository to install PHP and include the following extensions: +These images are built top of the official CentOS Stream 9 images using Remi's RPMs Repository to install PHP and include the following extensions: * bcmath * gd diff --git a/php/cli-loaders/Dockerfile b/php/cli-loaders/Dockerfile index 9cf2734..ff14014 100644 --- a/php/cli-loaders/Dockerfile +++ b/php/cli-loaders/Dockerfile @@ -1,13 +1,17 @@ ARG IMAGE_NAME="davidalger/php" ARG PHP_VERSION FROM ${IMAGE_NAME}:${PHP_VERSION} +ARG TARGETPLATFORM # Install and enable Source Gaurdian loader RUN PHP_VERSION=$(php -v | head -n1 | cut -d' ' -f2 | cut -d. -f1-2) \ + && if [ "${TARGETPLATFORM}" = "linux/amd64" ]; then SGARCH=x86_64; \ + elif [ "${TARGETPLATFORM}" = "linux/arm64" ]; then SGARCH=aarch64; \ + else SGARCH=x86_64; fi \ && mkdir -p /tmp/sourceguardian \ && cd /tmp/sourceguardian \ - && curl -Os https://www.sourceguardian.com/loaders/download/loaders.linux-x86_64.tar.gz \ - && tar xzf loaders.linux-x86_64.tar.gz \ + && curl -Os https://www.sourceguardian.com/loaders/download/loaders.linux-${SGARCH}.tar.gz \ + && tar xzf loaders.linux-${SGARCH}.tar.gz \ && SOURCEGUARDIAN_LOADER_PATH=ixed.${PHP_VERSION}.lin \ && if [[ -f ${SOURCEGUARDIAN_LOADER_PATH} ]]; then \ cp ${SOURCEGUARDIAN_LOADER_PATH} "$(php -i | grep '^extension_dir =' | cut -d' ' -f3)/sourceguardian.so" \ @@ -20,10 +24,13 @@ RUN PHP_VERSION=$(php -v | head -n1 | cut -d' ' -f2 | cut -d. -f1-2) \ # Install and enable IonCube loader RUN PHP_VERSION=$(php -v | head -n1 | cut -d' ' -f2 | cut -d. -f1-2) \ + && if [ "$TARGETPLATFORM" = "linux/amd64" ]; then ICARCH=x86-64; \ + elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then ICARCH=aarch64; \ + else ICARCH=x86-64; fi \ && mkdir -p /tmp/ioncube \ && cd /tmp/ioncube \ - && curl -Os https://downloads.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.gz \ - && tar xzf ioncube_loaders_lin_x86-64.tar.gz \ + && curl -Os https://downloads.ioncube.com/loader_downloads/ioncube_loaders_lin_${ICARCH}.tar.gz \ + && tar xzf ioncube_loaders_lin_${ICARCH}.tar.gz \ && IONCUBE_LOADER_PATH=ioncube/ioncube_loader_lin_${PHP_VERSION}.so \ && if [[ -f ${IONCUBE_LOADER_PATH} ]]; then \ cp ${IONCUBE_LOADER_PATH} "$(php -i | grep '^extension_dir =' | cut -d' ' -f3)/ioncube_loader.so" \ diff --git a/php/cli/Dockerfile b/php/cli/Dockerfile index d1386d9..13cc7f8 100644 --- a/php/cli/Dockerfile +++ b/php/cli/Dockerfile @@ -1,4 +1,4 @@ -FROM quay.io/centos/centos:stream8 +FROM quay.io/centos/centos:stream9 ARG PHP_VERSION ARG PHP_EXTENSIONS="bcmath cli common gd gmp intl json mbstring \ @@ -10,7 +10,7 @@ RUN dnf update -y \ RUN set -eux \ && dnf install -y epel-release \ - && dnf install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm \ + && dnf install -y https://rpms.remirepo.net/enterprise/remi-release-9.rpm \ && dnf module reset php -y \ && dnf module install -y php:remi-${PHP_VERSION} \ && PHP_VERSION=$(echo ${PHP_VERSION} | awk -F '.' '{print $1$2}') \ diff --git a/php/fpm-loaders/Dockerfile b/php/fpm-loaders/Dockerfile index 9c17c1c..e1d8c44 100644 --- a/php/fpm-loaders/Dockerfile +++ b/php/fpm-loaders/Dockerfile @@ -2,12 +2,17 @@ ARG IMAGE_NAME="davidalger/php" ARG PHP_VERSION FROM ${IMAGE_NAME}:${PHP_VERSION}-fpm +ARG TARGETPLATFORM + # Install and enable Source Gaurdian loader RUN PHP_VERSION=$(php -v | head -n1 | cut -d' ' -f2 | cut -d. -f1-2) \ + && if [ "${TARGETPLATFORM}" = "linux/amd64" ]; then SGARCH=x86_64; \ + elif [ "${TARGETPLATFORM}" = "linux/arm64" ]; then SGARCH=aarch64; \ + else SGARCH=x86_64; fi \ && mkdir -p /tmp/sourceguardian \ && cd /tmp/sourceguardian \ - && curl -Os https://www.sourceguardian.com/loaders/download/loaders.linux-x86_64.tar.gz \ - && tar xzf loaders.linux-x86_64.tar.gz \ + && curl -Os https://www.sourceguardian.com/loaders/download/loaders.linux-${SGARCH}.tar.gz \ + && tar xzf loaders.linux-${SGARCH}.tar.gz \ && SOURCEGUARDIAN_LOADER_PATH=ixed.${PHP_VERSION}.lin \ && if [[ -f ${SOURCEGUARDIAN_LOADER_PATH} ]]; then \ cp ${SOURCEGUARDIAN_LOADER_PATH} "$(php -i | grep '^extension_dir =' | cut -d' ' -f3)/sourceguardian.so" \ @@ -20,10 +25,13 @@ RUN PHP_VERSION=$(php -v | head -n1 | cut -d' ' -f2 | cut -d. -f1-2) \ # Install and enable IonCube loader RUN PHP_VERSION=$(php -v | head -n1 | cut -d' ' -f2 | cut -d. -f1-2) \ + && if [ "$TARGETPLATFORM" = "linux/amd64" ]; then ICARCH=x86-64; \ + elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then ICARCH=aarch64; \ + else ICARCH=x86-64; fi \ && mkdir -p /tmp/ioncube \ && cd /tmp/ioncube \ - && curl -Os https://downloads.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.gz \ - && tar xzf ioncube_loaders_lin_x86-64.tar.gz \ + && curl -Os https://downloads.ioncube.com/loader_downloads/ioncube_loaders_lin_${ICARCH}.tar.gz \ + && tar xzf ioncube_loaders_lin_${ICARCH}.tar.gz \ && IONCUBE_LOADER_PATH=ioncube/ioncube_loader_lin_${PHP_VERSION}.so \ && if [[ -f ${IONCUBE_LOADER_PATH} ]]; then \ cp ${IONCUBE_LOADER_PATH} "$(php -i | grep '^extension_dir =' | cut -d' ' -f3)/ioncube_loader.so" \ diff --git a/php/scripts/build.sh b/php/scripts/build.sh index daca75f..c5b0046 100755 --- a/php/scripts/build.sh +++ b/php/scripts/build.sh @@ -38,6 +38,7 @@ fi VERSION_LIST="${VERSION_LIST:-"7.4"}" VARIANT_LIST="${VARIANT_LIST:-"cli cli-loaders fpm fpm-loaders"}" +docker buildx create --use IMAGE_NAME="${IMAGE_NAME:-"davidalger/php"}" for BUILD_VERSION in ${VERSION_LIST}; do MAJOR_VERSION="$(echo "${BUILD_VERSION}" | sed -E 's/([0-9])([0-9])/\1.\2/')" @@ -50,7 +51,7 @@ for BUILD_VERSION in ${VERSION_LIST}; do printf "\e[01;31m==> building %s:%s (%s)\033[0m\n" \ "${IMAGE_NAME}" "${BUILD_VERSION}" "${BUILD_VARIANT}" - docker build -t "${IMAGE_NAME}:build" "${BUILD_VARIANT}" $(printf -- "--build-arg %s " "${BUILD_ARGS[@]}") + docker buildx build --platform=linux/amd64,linux/arm64 -t "${IMAGE_NAME}:build" "${BUILD_VARIANT}" $(printf -- "--build-arg %s " "${BUILD_ARGS[@]}") # Strip the term 'cli' from tag suffix as this is the default variant TAG_SUFFIX="$(echo "${BUILD_VARIANT}" | sed -E 's/^(cli$|cli-)//')" diff --git a/scripts/build.sh b/scripts/build.sh index 0d55717..752592d 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -57,6 +57,7 @@ fi ## define image repository to push WARDEN_IMAGE_REPOSITORY="${WARDEN_IMAGE_REPOSITORY:-"docker.io/wardenenv"}" +docker buildx create --use ## iterate over and build each Dockerfile for file in $(find ${SEARCH_PATH} -type f -name Dockerfile | sort -V); do BUILD_DIR="$(dirname "${file}")" @@ -118,6 +119,6 @@ for file in $(find ${SEARCH_PATH} -type f -name Dockerfile | sort -V); do fi printf "\e[01;31m==> building ${IMAGE_TAG} from ${BUILD_DIR}/Dockerfile with context ${BUILD_CONTEXT}\033[0m\n" - docker build -t "${IMAGE_TAG}" -f ${BUILD_DIR}/Dockerfile ${BUILD_ARGS[@]} ${BUILD_CONTEXT} + docker buildx build --platform=linux/arm64,linux/amd64 -t "${IMAGE_TAG}" -f ${BUILD_DIR}/Dockerfile ${BUILD_ARGS[@]} ${BUILD_CONTEXT} [[ $PUSH_FLAG ]] && docker push "${IMAGE_TAG}" || true done From db47b46fa0b179d313abfbd6cd533327c79507e7 Mon Sep 17 00:00:00 2001 From: Navarr Date: Fri, 3 Mar 2023 10:56:50 -0500 Subject: [PATCH 02/11] Fix push flag in build script --- php/scripts/build.sh | 6 +++--- scripts/build.sh | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/php/scripts/build.sh b/php/scripts/build.sh index c5b0046..910e9cb 100755 --- a/php/scripts/build.sh +++ b/php/scripts/build.sh @@ -19,13 +19,13 @@ readonly BASE_DIR="$( pushd "${BASE_DIR}" >/dev/null ## if --push is passed as first argument to script, this will login to docker hub and push images -PUSH_FLAG=${PUSH_FLAG:-0} +PUSH_FLAG=${PUSH_FLAG:=0} if [[ "${1:-}" = "--push" ]]; then PUSH_FLAG=1 fi ## login to docker hub as needed -if [[ $PUSH_FLAG && ${PRE_AUTH:-0} != 1 ]]; then +if [[ $PUSH_FLAG != 0 && ${PRE_AUTH:-0} != 1 ]]; then if [ -t 1 ]; then docker login else @@ -70,7 +70,7 @@ for BUILD_VERSION in ${VERSION_LIST}; do for TAG in "${IMAGE_TAGS[@]}"; do docker tag "${IMAGE_NAME}:build" "${TAG}" echo "Successfully tagged ${TAG}" - [[ $PUSH_FLAG ]] && docker push "${TAG}" + if [[ ${PUSH_FLAG} != 0 ]]; then docker push "${TAG}"; fi done docker image rm "${IMAGE_NAME}:build" done diff --git a/scripts/build.sh b/scripts/build.sh index 752592d..e8c29e7 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -44,7 +44,7 @@ if [[ -z ${SEARCH_PATH} ]]; then fi ## login to docker hub as needed -if [[ ${PUSH_FLAG} && ${PRE_AUTH:-0} != 1 ]]; then +if [[ ${PUSH_FLAG} != 0 && ${PRE_AUTH:-0} != 1 ]]; then if [[ ${DOCKER_USERNAME:-} ]]; then echo "Attempting non-interactive docker login (via provided credentials)" echo "${DOCKER_PASSWORD:-}" | docker login -u "${DOCKER_USERNAME:-}" --password-stdin ${DOCKER_REGISTRY:-docker.io} @@ -120,5 +120,5 @@ for file in $(find ${SEARCH_PATH} -type f -name Dockerfile | sort -V); do printf "\e[01;31m==> building ${IMAGE_TAG} from ${BUILD_DIR}/Dockerfile with context ${BUILD_CONTEXT}\033[0m\n" docker buildx build --platform=linux/arm64,linux/amd64 -t "${IMAGE_TAG}" -f ${BUILD_DIR}/Dockerfile ${BUILD_ARGS[@]} ${BUILD_CONTEXT} - [[ $PUSH_FLAG ]] && docker push "${IMAGE_TAG}" || true + if [[ $PUSH_FLAG != 0 ]]; then docker push "${IMAGE_TAG}"; fi done From 1616fb4887e9f920310af5cda56ea30f5739a5c2 Mon Sep 17 00:00:00 2001 From: Navarr Date: Sat, 4 Mar 2023 17:11:26 -0500 Subject: [PATCH 03/11] Make changes that prevent building php-fpm for Arm64 * Upgrade NodeJS base from 10 to 18 * Remove Python2 that is no longer available in CentOS 9 * Build Mailhog in a golang builder and import --- php-fpm/Dockerfile | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/php-fpm/Dockerfile b/php-fpm/Dockerfile index ae310c2..80d26d8 100644 --- a/php-fpm/Dockerfile +++ b/php-fpm/Dockerfile @@ -1,6 +1,10 @@ ARG PHP_SOURCE_IMAGE="docker.io/davidalger/php" ARG PHP_VERSION ARG PHP_VARIANT="fpm-loaders" + +FROM golang:alpine AS mhs-builder +RUN go install github.com/mailhog/mhsendmail@latest + FROM ${PHP_SOURCE_IMAGE}:${PHP_VERSION}-${PHP_VARIANT} # Clear undesired settings from base fpm images @@ -15,12 +19,7 @@ RUN dnf install -y which pv sudo bind-utils python3-pip bash-completion rsync so && dnf clean all \ && rm -rf /var/cache/dnf -RUN dnf install -y python2 \ - && ln -s /bin/python2 /bin/python \ - && dnf clean all \ - && rm -rf /var/cache/dnf - -ENV NODE_VERSION 10 +ENV NODE_VERSION 18 RUN npm install -g n \ && n install ${NODE_VERSION} \ && rm -rf /usr/local/n/versions/node @@ -32,11 +31,7 @@ COPY etc/php.d/*.ini /etc/php.d/ COPY etc/php.d/05-additions.ini.template /etc/php.d/ # Install mhsendmail to support routing email through mailhog -RUN mkdir -p /tmp/mhsendmail \ - && cd /tmp/mhsendmail \ - && curl -vLOs https://github.com/mailhog/mhsendmail/releases/download/v0.2.0/mhsendmail_linux_amd64 \ - && chmod +x mhsendmail_linux_amd64 \ - && mv mhsendmail_linux_amd64 /usr/local/bin/mhsendmail +COPY --from=mhs-builder /go/bin/mhsendmail /usr/local/bin/mhsendmail # Install awscli to support data backfill workflows using S3 storage; segno for QR code generation RUN pip3 install awscli segno --no-cache-dir From d51a68355328af54230578df229a8c3f72c0be29 Mon Sep 17 00:00:00 2001 From: Navarr Date: Sat, 4 Mar 2023 17:21:21 -0500 Subject: [PATCH 04/11] Add ability to have -indev images --- .github/workflows/php.yml | 8 ++++++++ php/scripts/build.sh | 3 +++ scripts/build.sh | 3 +++ 3 files changed, 14 insertions(+) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 8606f8e..30576ff 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -3,6 +3,7 @@ on: push: branches: - main + - develop paths: - php/** - .github/workflows/php.yml @@ -28,6 +29,7 @@ jobs: VERSION_LIST: 7.4 8.0 8.1 8.2 VARIANT_LIST: cli cli-loaders fpm fpm-loaders PUSH_FLAG: 1 + INDEV_FLAG: ${{ github.ref == 'refs/heads/main' && 0 || 1 }} run: bash php/scripts/build.sh php-fpm: @@ -55,6 +57,7 @@ jobs: PUSH_FLAG: 1 PHP_VERSION: ${{ matrix.php_version }} PHP_VARIANT: ${{ matrix.php_variant }} + INDEV_FLAG: ${{ github.ref == 'refs/heads/main' && 0 || 1 }} run: bash scripts/build.sh "${BUILD_GROUP}" - uses: docker/login-action@v2 with: @@ -68,6 +71,7 @@ jobs: PUSH_FLAG: 1 PHP_VERSION: ${{ matrix.php_version }} PHP_VARIANT: ${{ matrix.php_variant }} + INDEV_FLAG: ${{ github.ref == 'refs/heads/main' && 0 || 1 }} run: bash scripts/build.sh "${BUILD_GROUP}" magento1: @@ -95,6 +99,7 @@ jobs: PUSH_FLAG: 1 PHP_VERSION: ${{ matrix.php_version }} PHP_VARIANT: ${{ matrix.php_variant }} + INDEV_FLAG: ${{ github.ref == 'refs/heads/main' && 0 || 1 }} run: bash scripts/build.sh "${BUILD_GROUP}" - uses: docker/login-action@v2 with: @@ -108,6 +113,7 @@ jobs: PUSH_FLAG: 1 PHP_VERSION: ${{ matrix.php_version }} PHP_VARIANT: ${{ matrix.php_variant }} + INDEV_FLAG: ${{ github.ref == 'refs/heads/main' && 0 || 1 }} run: bash scripts/build.sh "${BUILD_GROUP}" magento2: @@ -135,6 +141,7 @@ jobs: PUSH_FLAG: 1 PHP_VERSION: ${{ matrix.php_version }} PHP_VARIANT: ${{ matrix.php_variant }} + INDEV_FLAG: ${{ github.ref == 'refs/heads/main' && 0 || 1 }} run: bash scripts/build.sh "${BUILD_GROUP}" - uses: docker/login-action@v2 with: @@ -148,4 +155,5 @@ jobs: PUSH_FLAG: 1 PHP_VERSION: ${{ matrix.php_version }} PHP_VARIANT: ${{ matrix.php_variant }} + INDEV_FLAG: ${{ github.ref == 'refs/heads/main' && 0 || 1 }} run: bash scripts/build.sh "${BUILD_GROUP}" \ No newline at end of file diff --git a/php/scripts/build.sh b/php/scripts/build.sh index 910e9cb..4288dd3 100755 --- a/php/scripts/build.sh +++ b/php/scripts/build.sh @@ -40,6 +40,9 @@ VARIANT_LIST="${VARIANT_LIST:-"cli cli-loaders fpm fpm-loaders"}" docker buildx create --use IMAGE_NAME="${IMAGE_NAME:-"davidalger/php"}" +if [[ "${INDEV_FLAG:-1}" != "0" ]]; then + IMAGE_NAME = "${IMAGE_NAME}-indev" +fi for BUILD_VERSION in ${VERSION_LIST}; do MAJOR_VERSION="$(echo "${BUILD_VERSION}" | sed -E 's/([0-9])([0-9])/\1.\2/')" for BUILD_VARIANT in ${VARIANT_LIST}; do diff --git a/scripts/build.sh b/scripts/build.sh index e8c29e7..88eb69d 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -62,6 +62,9 @@ docker buildx create --use for file in $(find ${SEARCH_PATH} -type f -name Dockerfile | sort -V); do BUILD_DIR="$(dirname "${file}")" IMAGE_TAG="${WARDEN_IMAGE_REPOSITORY}/$(echo "${BUILD_DIR}" | cut -d/ -f1)" + if [[ "${INDEV_FLAG:-1}" != "0" ]]; then + IMAGE_TAG = "${IMAGE_TAG}-indev" + fi IMAGE_SUFFIX="$(echo "${BUILD_DIR}" | cut -d/ -f2- -s | tr / - | sed 's/^-//')" echo $IMAGE_SUFFIX From c5c2131a4160904642edc072635e8a5e84998e3c Mon Sep 17 00:00:00 2001 From: Navarr Date: Sat, 4 Mar 2023 17:24:31 -0500 Subject: [PATCH 05/11] Fix GitHub Actions Syntax --- .github/workflows/php.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 30576ff..cd0a13a 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -29,7 +29,7 @@ jobs: VERSION_LIST: 7.4 8.0 8.1 8.2 VARIANT_LIST: cli cli-loaders fpm fpm-loaders PUSH_FLAG: 1 - INDEV_FLAG: ${{ github.ref == 'refs/heads/main' && 0 || 1 }} + INDEV_FLAG: ${{ github.ref == 'refs/heads/main' && '0' || '1' }} run: bash php/scripts/build.sh php-fpm: @@ -57,7 +57,7 @@ jobs: PUSH_FLAG: 1 PHP_VERSION: ${{ matrix.php_version }} PHP_VARIANT: ${{ matrix.php_variant }} - INDEV_FLAG: ${{ github.ref == 'refs/heads/main' && 0 || 1 }} + INDEV_FLAG: ${{ github.ref == 'refs/heads/main' && '0' || '1' }} run: bash scripts/build.sh "${BUILD_GROUP}" - uses: docker/login-action@v2 with: @@ -71,7 +71,7 @@ jobs: PUSH_FLAG: 1 PHP_VERSION: ${{ matrix.php_version }} PHP_VARIANT: ${{ matrix.php_variant }} - INDEV_FLAG: ${{ github.ref == 'refs/heads/main' && 0 || 1 }} + INDEV_FLAG: ${{ github.ref == 'refs/heads/main' && '0' || '1' }} run: bash scripts/build.sh "${BUILD_GROUP}" magento1: @@ -99,7 +99,7 @@ jobs: PUSH_FLAG: 1 PHP_VERSION: ${{ matrix.php_version }} PHP_VARIANT: ${{ matrix.php_variant }} - INDEV_FLAG: ${{ github.ref == 'refs/heads/main' && 0 || 1 }} + INDEV_FLAG: ${{ github.ref == 'refs/heads/main' && '0' || '1' }} run: bash scripts/build.sh "${BUILD_GROUP}" - uses: docker/login-action@v2 with: @@ -113,7 +113,7 @@ jobs: PUSH_FLAG: 1 PHP_VERSION: ${{ matrix.php_version }} PHP_VARIANT: ${{ matrix.php_variant }} - INDEV_FLAG: ${{ github.ref == 'refs/heads/main' && 0 || 1 }} + INDEV_FLAG: ${{ github.ref == 'refs/heads/main' && '0' || '1' }} run: bash scripts/build.sh "${BUILD_GROUP}" magento2: @@ -141,7 +141,7 @@ jobs: PUSH_FLAG: 1 PHP_VERSION: ${{ matrix.php_version }} PHP_VARIANT: ${{ matrix.php_variant }} - INDEV_FLAG: ${{ github.ref == 'refs/heads/main' && 0 || 1 }} + INDEV_FLAG: ${{ github.ref == 'refs/heads/main' && '0' || '1' }} run: bash scripts/build.sh "${BUILD_GROUP}" - uses: docker/login-action@v2 with: @@ -155,5 +155,5 @@ jobs: PUSH_FLAG: 1 PHP_VERSION: ${{ matrix.php_version }} PHP_VARIANT: ${{ matrix.php_variant }} - INDEV_FLAG: ${{ github.ref == 'refs/heads/main' && 0 || 1 }} + INDEV_FLAG: ${{ github.ref == 'refs/heads/main' && '0' || '1' }} run: bash scripts/build.sh "${BUILD_GROUP}" \ No newline at end of file From 1b0e7c31e00e9fdb18d9911bfe3c6a700e03be9a Mon Sep 17 00:00:00 2001 From: Navarr Date: Sat, 4 Mar 2023 17:28:16 -0500 Subject: [PATCH 06/11] Build From 31945f869cf6b04b95b4d0be2927ef74d7f025b7 Mon Sep 17 00:00:00 2001 From: Navarr Date: Sat, 4 Mar 2023 17:31:17 -0500 Subject: [PATCH 07/11] Fix erroneous extra spaces --- php/scripts/build.sh | 2 +- scripts/build.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/php/scripts/build.sh b/php/scripts/build.sh index 4288dd3..8d92bb8 100755 --- a/php/scripts/build.sh +++ b/php/scripts/build.sh @@ -41,7 +41,7 @@ VARIANT_LIST="${VARIANT_LIST:-"cli cli-loaders fpm fpm-loaders"}" docker buildx create --use IMAGE_NAME="${IMAGE_NAME:-"davidalger/php"}" if [[ "${INDEV_FLAG:-1}" != "0" ]]; then - IMAGE_NAME = "${IMAGE_NAME}-indev" + IMAGE_NAME="${IMAGE_NAME}-indev" fi for BUILD_VERSION in ${VERSION_LIST}; do MAJOR_VERSION="$(echo "${BUILD_VERSION}" | sed -E 's/([0-9])([0-9])/\1.\2/')" diff --git a/scripts/build.sh b/scripts/build.sh index 88eb69d..01c0d86 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -63,7 +63,7 @@ for file in $(find ${SEARCH_PATH} -type f -name Dockerfile | sort -V); do BUILD_DIR="$(dirname "${file}")" IMAGE_TAG="${WARDEN_IMAGE_REPOSITORY}/$(echo "${BUILD_DIR}" | cut -d/ -f1)" if [[ "${INDEV_FLAG:-1}" != "0" ]]; then - IMAGE_TAG = "${IMAGE_TAG}-indev" + IMAGE_TAG="${IMAGE_TAG}-indev" fi IMAGE_SUFFIX="$(echo "${BUILD_DIR}" | cut -d/ -f2- -s | tr / - | sed 's/^-//')" echo $IMAGE_SUFFIX From 4793818a15b8fef44e17b54774979565494ac22e Mon Sep 17 00:00:00 2001 From: Navarr Date: Sat, 4 Mar 2023 17:41:13 -0500 Subject: [PATCH 08/11] Ensure php-fpm builds pull from the correct centos-php builds when indev --- scripts/build.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/build.sh b/scripts/build.sh index 01c0d86..8a15ed7 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -83,10 +83,16 @@ for file in $(find ${SEARCH_PATH} -type f -name Dockerfile | sort -V); do ## define default sources for main php and environment images export PHP_SOURCE_IMAGE="${PHP_SOURCE_IMAGE:-"docker.io/davidalger/php"}" + if [[ "${INDEV_FLAG:-1}" != "0" ]]; then + export PHP_SOURCE_IMAGE="${PHP_SOURCE_IMAGE}-indev" + fi BUILD_ARGS+=("--build-arg") BUILD_ARGS+=("PHP_SOURCE_IMAGE") export ENV_SOURCE_IMAGE="${ENV_SOURCE_IMAGE:-"${WARDEN_IMAGE_REPOSITORY}/php-fpm"}" + if [[ "${INDEV_FLAG:-1}" != "0" ]]; then + export ENV_SOURCE_IMAGE="${ENV_SOURCE_IMAGE}-indev" + fi BUILD_ARGS+=("--build-arg") BUILD_ARGS+=("ENV_SOURCE_IMAGE") From fb1238ab5516317a507c6814137d707076edc641 Mon Sep 17 00:00:00 2001 From: Navarr Date: Sat, 4 Mar 2023 17:56:19 -0500 Subject: [PATCH 09/11] Have BuildX output to docker --- php/scripts/build.sh | 2 +- scripts/build.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/php/scripts/build.sh b/php/scripts/build.sh index 8d92bb8..174cc26 100755 --- a/php/scripts/build.sh +++ b/php/scripts/build.sh @@ -54,7 +54,7 @@ for BUILD_VERSION in ${VERSION_LIST}; do printf "\e[01;31m==> building %s:%s (%s)\033[0m\n" \ "${IMAGE_NAME}" "${BUILD_VERSION}" "${BUILD_VARIANT}" - docker buildx build --platform=linux/amd64,linux/arm64 -t "${IMAGE_NAME}:build" "${BUILD_VARIANT}" $(printf -- "--build-arg %s " "${BUILD_ARGS[@]}") + docker buildx build -o type=docker --platform=linux/amd64,linux/arm64 -t "${IMAGE_NAME}:build" "${BUILD_VARIANT}" $(printf -- "--build-arg %s " "${BUILD_ARGS[@]}") # Strip the term 'cli' from tag suffix as this is the default variant TAG_SUFFIX="$(echo "${BUILD_VARIANT}" | sed -E 's/^(cli$|cli-)//')" diff --git a/scripts/build.sh b/scripts/build.sh index 8a15ed7..16b2f3d 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -128,6 +128,6 @@ for file in $(find ${SEARCH_PATH} -type f -name Dockerfile | sort -V); do fi printf "\e[01;31m==> building ${IMAGE_TAG} from ${BUILD_DIR}/Dockerfile with context ${BUILD_CONTEXT}\033[0m\n" - docker buildx build --platform=linux/arm64,linux/amd64 -t "${IMAGE_TAG}" -f ${BUILD_DIR}/Dockerfile ${BUILD_ARGS[@]} ${BUILD_CONTEXT} + docker buildx build -o type=docker --platform=linux/arm64,linux/amd64 -t "${IMAGE_TAG}" -f ${BUILD_DIR}/Dockerfile ${BUILD_ARGS[@]} ${BUILD_CONTEXT} if [[ $PUSH_FLAG != 0 ]]; then docker push "${IMAGE_TAG}"; fi done From 0499c26724075b4fe6ce845e8a03900c863afd5f Mon Sep 17 00:00:00 2001 From: Navarr Date: Sun, 5 Mar 2023 12:58:52 -0500 Subject: [PATCH 10/11] Restructure how we use buildx so we can still use info from docker run --- php/scripts/build.sh | 11 ++++------- scripts/build.sh | 4 ++-- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/php/scripts/build.sh b/php/scripts/build.sh index 174cc26..29121cd 100755 --- a/php/scripts/build.sh +++ b/php/scripts/build.sh @@ -54,7 +54,7 @@ for BUILD_VERSION in ${VERSION_LIST}; do printf "\e[01;31m==> building %s:%s (%s)\033[0m\n" \ "${IMAGE_NAME}" "${BUILD_VERSION}" "${BUILD_VARIANT}" - docker buildx build -o type=docker --platform=linux/amd64,linux/arm64 -t "${IMAGE_NAME}:build" "${BUILD_VARIANT}" $(printf -- "--build-arg %s " "${BUILD_ARGS[@]}") + docker build -t "${IMAGE_NAME}:build" "${BUILD_VARIANT}" $(printf -- "--build-arg %s " "${BUILD_ARGS[@]}") # Strip the term 'cli' from tag suffix as this is the default variant TAG_SUFFIX="$(echo "${BUILD_VARIANT}" | sed -E 's/^(cli$|cli-)//')" @@ -70,11 +70,8 @@ for BUILD_VERSION in ${VERSION_LIST}; do ) # Iterate and push image tags to remote registry - for TAG in "${IMAGE_TAGS[@]}"; do - docker tag "${IMAGE_NAME}:build" "${TAG}" - echo "Successfully tagged ${TAG}" - if [[ ${PUSH_FLAG} != 0 ]]; then docker push "${TAG}"; fi - done - docker image rm "${IMAGE_NAME}:build" + if [[ ${PUSH_FLAG} != 0 ]]; then + docker buildx build --push --platform=linux/arm64,linux/amd64 -t "${IMAGE_NAME}:${MAJOR_VERSION}${TAG_SUFFIX}" -t "${IMAGE_NAME}:${MINOR_VERSION}${TAG_SUFFIX}" "${BUILD_VARIANT}" $(printf -- "--build-arg %s " "${BUILD_ARGS[@]}") + fi done done diff --git a/scripts/build.sh b/scripts/build.sh index 16b2f3d..69f0689 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -128,6 +128,6 @@ for file in $(find ${SEARCH_PATH} -type f -name Dockerfile | sort -V); do fi printf "\e[01;31m==> building ${IMAGE_TAG} from ${BUILD_DIR}/Dockerfile with context ${BUILD_CONTEXT}\033[0m\n" - docker buildx build -o type=docker --platform=linux/arm64,linux/amd64 -t "${IMAGE_TAG}" -f ${BUILD_DIR}/Dockerfile ${BUILD_ARGS[@]} ${BUILD_CONTEXT} - if [[ $PUSH_FLAG != 0 ]]; then docker push "${IMAGE_TAG}"; fi + if [[ $PUSH_FLAG != 0 ]]; then PUSH_ARG="--push"; fi + docker buildx build --platform=linux/arm64,linux/amd64 ${PUSH_ARG:-} -t "${IMAGE_TAG}" -f ${BUILD_DIR}/Dockerfile ${BUILD_ARGS[@]} ${BUILD_CONTEXT} done From a5bfb89b4be17b1ebf7acf9e3e4bc9bca10dbff1 Mon Sep 17 00:00:00 2001 From: Navarr Date: Tue, 7 Mar 2023 14:09:23 -0500 Subject: [PATCH 11/11] Prevent -indev recursion --- scripts/build.sh | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/scripts/build.sh b/scripts/build.sh index 69f0689..dae0be6 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -58,6 +58,17 @@ fi WARDEN_IMAGE_REPOSITORY="${WARDEN_IMAGE_REPOSITORY:-"docker.io/wardenenv"}" docker buildx create --use + +export PHP_SOURCE_IMAGE="${PHP_SOURCE_IMAGE:-"docker.io/davidalger/php"}" +if [[ "${INDEV_FLAG:-1}" != "0" ]]; then + export PHP_SOURCE_IMAGE="${PHP_SOURCE_IMAGE}-indev" +fi + +export ENV_SOURCE_IMAGE="${ENV_SOURCE_IMAGE:-"${WARDEN_IMAGE_REPOSITORY}/php-fpm"}" +if [[ "${INDEV_FLAG:-1}" != "0" ]]; then + export ENV_SOURCE_IMAGE="${ENV_SOURCE_IMAGE}-indev" +fi + ## iterate over and build each Dockerfile for file in $(find ${SEARCH_PATH} -type f -name Dockerfile | sort -V); do BUILD_DIR="$(dirname "${file}")" @@ -82,17 +93,9 @@ for file in $(find ${SEARCH_PATH} -type f -name Dockerfile | sort -V); do fi ## define default sources for main php and environment images - export PHP_SOURCE_IMAGE="${PHP_SOURCE_IMAGE:-"docker.io/davidalger/php"}" - if [[ "${INDEV_FLAG:-1}" != "0" ]]; then - export PHP_SOURCE_IMAGE="${PHP_SOURCE_IMAGE}-indev" - fi BUILD_ARGS+=("--build-arg") BUILD_ARGS+=("PHP_SOURCE_IMAGE") - export ENV_SOURCE_IMAGE="${ENV_SOURCE_IMAGE:-"${WARDEN_IMAGE_REPOSITORY}/php-fpm"}" - if [[ "${INDEV_FLAG:-1}" != "0" ]]; then - export ENV_SOURCE_IMAGE="${ENV_SOURCE_IMAGE}-indev" - fi BUILD_ARGS+=("--build-arg") BUILD_ARGS+=("ENV_SOURCE_IMAGE")