diff --git a/Dockerfile b/Dockerfile index 6c38af46ca8ae4e853189838b29fd43b53a25ee8..ac6a39521cbba9be3aef3e5048c90e4a396bf8d4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,9 @@ # syntax = docker/dockerfile:1.0-experimental -ARG nginx_version=latest -FROM nginx:${nginx_version} as nginx +ARG nginx_version +ARG php_version + +FROM nginx:${nginx_version:-latest} as nginx LABEL uk.org.kodo.maintainer = "Dom Sekotill " COPY data/nginx.conf /etc/nginx/conf.d/default.conf COPY data/fastcgi.nginx.conf /etc/nginx/fastcgi.conf @@ -9,18 +11,18 @@ COPY data/cache-bust.nginx.conf /etc/nginx/cache-bust.conf COPY data/5*.html /app/html/ -ARG php_version= FROM php:${php_version:+$php_version-}fpm-alpine as deps RUN --mount=type=bind,source=scripts/install-deps.sh,target=/stage /stage FROM deps as compile -RUN --mount=type=bind,source=scripts/compile.sh,target=/stage /stage +RUN --mount=type=bind,source=scripts/install-build-deps.sh,target=/stage /stage +RUN --mount=type=bind,source=scripts/compile-dist-ext.sh,target=/stage /stage +RUN --mount=type=bind,source=scripts/compile-imagick.sh,target=/stage /stage FROM deps as fastcgi LABEL uk.org.kodo.maintainer "Dom Sekotill " -ARG wp_version=latest WORKDIR /app ENV WORDPRESS_ROOT=/app @@ -28,6 +30,8 @@ COPY --from=compile /usr/local/etc/php /usr/local/etc/php COPY --from=compile /usr/local/lib/php /usr/local/lib/php COPY scripts/wp.sh /usr/local/bin/wp COPY data/composer.json /app/composer.json + +ARG wp_version=latest RUN --mount=type=bind,source=scripts/install-wp.sh,target=/stage \ /stage ${wp_version} diff --git a/README.md b/README.md index 4a3d5d88130b3e8cd0c360f446731904fb3e39e2..086ac39c565f82b1de727f8ea13ba41b50fd77fb 100644 --- a/README.md +++ b/README.md @@ -54,10 +54,14 @@ Build > **Note:** Building manually requires Docker 18.09 or later with the > [Buildkit][] feature enabled. +> **Note:** *(Dec 2020)* Currently WP-CLI does not support PHP-8. Likely various plugins and +> themes also do not work with PHP-8. Therefore until wider support is available, supply +> a PHP-7 version with a build argument. + To build the PHP-FPM image run: ```shell -DOCKER_BUILDKIT=1 docker build -t wordpress:tag . +DOCKER_BUILDKIT=1 docker build -t wordpress:tag --build-arg php_version=7.4.13 . ``` To build the Nginx companion image, run: diff --git a/scripts/compile.sh b/scripts/compile-dist-ext.sh similarity index 58% rename from scripts/compile.sh rename to scripts/compile-dist-ext.sh index bd52b78856135b94c21d979d4be4629d483ca91c..5317fd6f6de6ed9f11808796f44573ca6157af72 100755 --- a/scripts/compile.sh +++ b/scripts/compile-dist-ext.sh @@ -1,18 +1,6 @@ #!/bin/bash set -eux -# Packaged build dependencies -BUILD_DEPS=( - autoconf - build-base - gmp-dev - imagemagick-dev - jpeg-dev - libpng-dev - libwebp-dev - libzip-dev -) - # Distributed extensions PHP_EXT=( bcmath @@ -30,10 +18,6 @@ php_version() { return 1 } -# Install packaged dependencies -apk update -apk add "${BUILD_DEPS[@]}" - # Build & install distributed extensions if php_version -gt 7.4; then GD_ARGS=( --with-jpeg=/usr --with-webp=/usr ) @@ -42,7 +26,3 @@ else fi docker-php-ext-configure gd "${GD_ARGS[@]}" docker-php-ext-install -j$(nproc) "${PHP_EXT[@]}" - -# Download, build & install the Image Magick extension -pecl install imagick -echo "extension=imagick.so" > /usr/local/etc/php/conf.d/imagick.ini diff --git a/scripts/compile-imagick.sh b/scripts/compile-imagick.sh new file mode 100755 index 0000000000000000000000000000000000000000..fc7d1642e4d529bdc4ae2feca25b1c900c3c691d --- /dev/null +++ b/scripts/compile-imagick.sh @@ -0,0 +1,11 @@ +#!/bin/bash +set -eux + +cd $(mktemp -d) + +git clone --depth 1 https://github.com/imagick/imagick.git . +phpize +./configure +make install + +echo "extension=imagick.so" > /usr/local/etc/php/conf.d/imagick.ini diff --git a/scripts/install-build-deps.sh b/scripts/install-build-deps.sh new file mode 100755 index 0000000000000000000000000000000000000000..0d963e779adf6e84dfd056d2691ef8a6c90942ac --- /dev/null +++ b/scripts/install-build-deps.sh @@ -0,0 +1,15 @@ +#!/bin/sh +set -eux + +# Install packaged dependencies +apk update +apk add \ + autoconf \ + build-base \ + git \ + gmp-dev \ + imagemagick-dev \ + jpeg-dev \ + libpng-dev \ + libwebp-dev \ + libzip-dev \