Skip to content

Commit

Permalink
Merge pull request #5 from wardenenv/develop
Browse files Browse the repository at this point in the history
PHP ARM64 Support
  • Loading branch information
navarr authored Mar 20, 2023
2 parents 8837694 + a5bfb89 commit 4c70a95
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 35 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- develop
paths:
- php/**
- .github/workflows/php.yml
Expand All @@ -29,6 +30,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:
Expand Down Expand Up @@ -56,6 +58,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:
Expand All @@ -69,6 +72,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:
Expand Down Expand Up @@ -96,6 +100,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:
Expand All @@ -109,6 +114,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:
Expand Down Expand Up @@ -136,6 +142,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:
Expand All @@ -149,4 +156,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}"
17 changes: 6 additions & 11 deletions php-fpm/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion php/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 11 additions & 4 deletions php/cli-loaders/Dockerfile
Original file line number Diff line number Diff line change
@@ -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" \
Expand All @@ -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" \
Expand Down
4 changes: 2 additions & 2 deletions php/cli/Dockerfile
Original file line number Diff line number Diff line change
@@ -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 \
Expand All @@ -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}') \
Expand Down
16 changes: 12 additions & 4 deletions php/fpm-loaders/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand All @@ -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" \
Expand Down
17 changes: 9 additions & 8 deletions php/scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -38,7 +38,11 @@ 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"}"
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
Expand Down Expand Up @@ -66,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}"
[[ $PUSH_FLAG ]] && docker push "${TAG}"
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
23 changes: 18 additions & 5 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -57,10 +57,25 @@ fi
## define image repository to push
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}")"
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

Expand All @@ -78,11 +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"}"
BUILD_ARGS+=("--build-arg")
BUILD_ARGS+=("PHP_SOURCE_IMAGE")

export ENV_SOURCE_IMAGE="${ENV_SOURCE_IMAGE:-"${WARDEN_IMAGE_REPOSITORY}/php-fpm"}"
BUILD_ARGS+=("--build-arg")
BUILD_ARGS+=("ENV_SOURCE_IMAGE")

Expand Down Expand Up @@ -118,6 +131,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}
[[ $PUSH_FLAG ]] && docker push "${IMAGE_TAG}" || true
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

0 comments on commit 4c70a95

Please sign in to comment.