From 1412535e6d5e9fea565e3fc31276acd06bd5a555 Mon Sep 17 00:00:00 2001 From: Dom Sekotill Date: Tue, 18 Feb 2020 19:19:00 +0000 Subject: [PATCH 1/8] Add a liveness-probe MU plugin --- Dockerfile | 1 + probe.php | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 probe.php diff --git a/Dockerfile b/Dockerfile index 0c793b3..9686810 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,6 +26,7 @@ COPY --from=compile /usr/local/lib/php /usr/local/lib/php RUN --mount=type=bind,source=scripts/install-wp.sh,target=/stage \ /stage ${wp_version} +COPY probe.php wp-content/mu-plugins/ COPY opcache.ini /usr/local/etc/php/conf.d/opcache-recommended.ini COPY wp-config.php /usr/share/wordpress/wp-config.php COPY entrypoint.sh /bin/entrypoint diff --git a/probe.php b/probe.php new file mode 100644 index 0000000..efc3554 --- /dev/null +++ b/probe.php @@ -0,0 +1,16 @@ + Date: Tue, 18 Feb 2020 19:42:33 +0000 Subject: [PATCH 2/8] Remember to remove wp-config.php if it exists --- entrypoint.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/entrypoint.sh b/entrypoint.sh index 9e8ed24..a11bc72 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -46,6 +46,8 @@ declare -a WP_CONFIGS=( create_config() { + [[ -f wp-config.php ]] && unlink wp-config.php + local IFS=$'\n' sort -u <<-END_LIST | /usr/share/wordpress/wp-config.php -- GitLab From 8b83919a40f1342e60b783eaf64ae2fc99514c1d Mon Sep 17 00:00:00 2001 From: Dom Sekotill Date: Tue, 18 Feb 2020 19:42:57 +0000 Subject: [PATCH 3/8] Add [better] timestamps to log output Generally improve logging with some consistently formatted timestamps and clearer access log formats. --- Dockerfile | 1 + entrypoint.sh | 8 ++++++++ fpm.conf | 1 + nginx.conf | 7 +++++++ 4 files changed, 17 insertions(+) create mode 100644 fpm.conf diff --git a/Dockerfile b/Dockerfile index 9686810..e55cb74 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,6 +27,7 @@ RUN --mount=type=bind,source=scripts/install-wp.sh,target=/stage \ /stage ${wp_version} COPY probe.php wp-content/mu-plugins/ +COPY fpm.conf /usr/local/etc/php-fpm.d/image.conf COPY opcache.ini /usr/local/etc/php/conf.d/opcache-recommended.ini COPY wp-config.php /usr/share/wordpress/wp-config.php COPY entrypoint.sh /bin/entrypoint diff --git a/entrypoint.sh b/entrypoint.sh index a11bc72..475c184 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -44,6 +44,11 @@ declare -a WP_CONFIGS=( ) +timestamp() +{ + echo "[$(date --utc +'%Y-%m-%dT%H:%M:%S%z')] $*" +} + create_config() { [[ -f wp-config.php ]] && unlink wp-config.php @@ -158,6 +163,7 @@ run_cron() enable -f /usr/lib/bash/head head while wp cron event run --due-now || true; do sleep $(next_cron) + timestamp "Executing cron tasks" done } @@ -192,10 +198,12 @@ case "$1" in collect-static) create_config && setup_components && collect_static ;; run-cron) create_config && run_cron ;; php-fpm) + timestamp "Starting Wordpress preparation" create_config setup_components setup_media collect_static + timestamp "Completed Wordpress preparation" run_background_cron exec "$@" "${extra_args[@]}" ;; diff --git a/fpm.conf b/fpm.conf new file mode 100644 index 0000000..3e21722 --- /dev/null +++ b/fpm.conf @@ -0,0 +1 @@ +access.format = "[%{%Y-%m-%dT%H:%M:%S%z}t] %{REMOTE_ADDR}e %m %{REQUEST_URI}e%Q%q %s time=%{mili}d ms;" diff --git a/nginx.conf b/nginx.conf index 765db67..be6856f 100644 --- a/nginx.conf +++ b/nginx.conf @@ -3,10 +3,17 @@ map $http_x_forwarded_proto $forwarded_https { https on; } +log_format clear '[$time_iso8601] $remote_addr ' + '$request_method $request_uri$is_args$args $status ' + ' sent=$body_bytes_sent bytes;' + ' referrer=$http_referer;' + ' user-agent=$http_user_agent'; + server { listen 80; server_name _; root /app/static; + access_log /dev/stdout clear; # Consider all private IP addresses safe sources for X-Forwarded-For set_real_ip_from 10.0.0.0/8; -- GitLab From 180bda571e1fbc04222cbf164352a8f836e47674 Mon Sep 17 00:00:00 2001 From: Dom Sekotill Date: Tue, 18 Feb 2020 19:53:49 +0000 Subject: [PATCH 4/8] Move a bunch of top-level files into subdirectories --- Dockerfile | 14 +++++++------- fpm.conf => data/fpm.conf | 0 nginx.conf => data/nginx.conf | 0 opcache.ini => data/opcache.ini | 0 wp-config.php => data/wp-config.php | 0 probe.php => plugins/probe.php | 0 entrypoint.sh => scripts/entrypoint.sh | 0 wp.sh => scripts/wp.sh | 0 8 files changed, 7 insertions(+), 7 deletions(-) rename fpm.conf => data/fpm.conf (100%) rename nginx.conf => data/nginx.conf (100%) rename opcache.ini => data/opcache.ini (100%) rename wp-config.php => data/wp-config.php (100%) rename probe.php => plugins/probe.php (100%) rename entrypoint.sh => scripts/entrypoint.sh (100%) rename wp.sh => scripts/wp.sh (100%) diff --git a/Dockerfile b/Dockerfile index e55cb74..6ac80d3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ ARG nginx_version=latest FROM nginx:${nginx_version} as nginx LABEL uk.org.kodo.maintainer = "Dom Sekotill " -COPY nginx.conf /etc/nginx/conf.d/default.conf +COPY data/nginx.conf /etc/nginx/conf.d/default.conf FROM php:7.3-fpm-alpine as deps @@ -20,17 +20,17 @@ ARG wp_version=latest WORKDIR /app ENV WORDPRESS_ROOT=/app -COPY wp.sh /usr/local/bin/wp +COPY scripts/wp.sh /usr/local/bin/wp COPY --from=compile /usr/local/etc/php /usr/local/etc/php COPY --from=compile /usr/local/lib/php /usr/local/lib/php RUN --mount=type=bind,source=scripts/install-wp.sh,target=/stage \ /stage ${wp_version} -COPY probe.php wp-content/mu-plugins/ -COPY fpm.conf /usr/local/etc/php-fpm.d/image.conf -COPY opcache.ini /usr/local/etc/php/conf.d/opcache-recommended.ini -COPY wp-config.php /usr/share/wordpress/wp-config.php -COPY entrypoint.sh /bin/entrypoint +COPY plugins/probe.php wp-content/mu-plugins/ +COPY data/fpm.conf /usr/local/etc/php-fpm.d/image.conf +COPY data/opcache.ini /usr/local/etc/php/conf.d/opcache-recommended.ini +COPY data/wp-config.php /usr/share/wordpress/wp-config.php +COPY scripts/entrypoint.sh /bin/entrypoint # PAGER is used by the wp-cli tool, the default 'less' is not installed ENV PAGER=more diff --git a/fpm.conf b/data/fpm.conf similarity index 100% rename from fpm.conf rename to data/fpm.conf diff --git a/nginx.conf b/data/nginx.conf similarity index 100% rename from nginx.conf rename to data/nginx.conf diff --git a/opcache.ini b/data/opcache.ini similarity index 100% rename from opcache.ini rename to data/opcache.ini diff --git a/wp-config.php b/data/wp-config.php similarity index 100% rename from wp-config.php rename to data/wp-config.php diff --git a/probe.php b/plugins/probe.php similarity index 100% rename from probe.php rename to plugins/probe.php diff --git a/entrypoint.sh b/scripts/entrypoint.sh similarity index 100% rename from entrypoint.sh rename to scripts/entrypoint.sh diff --git a/wp.sh b/scripts/wp.sh similarity index 100% rename from wp.sh rename to scripts/wp.sh -- GitLab From ec8402bf00ba3e8f5b21a3c0d8cb868181ce199f Mon Sep 17 00:00:00 2001 From: Dom Sekotill Date: Tue, 18 Feb 2020 20:17:55 +0000 Subject: [PATCH 5/8] Add additional plugin metadata to the liveness probe --- plugins/probe.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/probe.php b/plugins/probe.php index efc3554..5c7dff5 100644 --- a/plugins/probe.php +++ b/plugins/probe.php @@ -1,10 +1,12 @@ Date: Tue, 18 Feb 2020 20:30:25 +0000 Subject: [PATCH 6/8] Enable multi-job compilation of PHP extensions --- scripts/compile.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/compile.sh b/scripts/compile.sh index 264c495..3ef2c21 100755 --- a/scripts/compile.sh +++ b/scripts/compile.sh @@ -30,7 +30,7 @@ apk add "${BUILD_DEPS[@]}" # Build & install distributed extensions docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr -docker-php-ext-install "${PHP_EXT[@]}" +docker-php-ext-install -j$(nproc) "${PHP_EXT[@]}" # Download, build & install the Image Magick extension pecl install imagick -- GitLab From df76fdc8317495407aa11890f0cc4f7a96043f07 Mon Sep 17 00:00:00 2001 From: Dom Sekotill Date: Wed, 19 Feb 2020 00:09:08 +0000 Subject: [PATCH 7/8] Fix URI queries logged twice --- data/fpm.conf | 2 +- data/nginx.conf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/data/fpm.conf b/data/fpm.conf index 3e21722..20bd27f 100644 --- a/data/fpm.conf +++ b/data/fpm.conf @@ -1 +1 @@ -access.format = "[%{%Y-%m-%dT%H:%M:%S%z}t] %{REMOTE_ADDR}e %m %{REQUEST_URI}e%Q%q %s time=%{mili}d ms;" +access.format = "[%{%Y-%m-%dT%H:%M:%S%z}t] %{REMOTE_ADDR}e %m %{REQUEST_URI}e %s time=%{mili}d ms;" diff --git a/data/nginx.conf b/data/nginx.conf index be6856f..8f5fb75 100644 --- a/data/nginx.conf +++ b/data/nginx.conf @@ -4,7 +4,7 @@ map $http_x_forwarded_proto $forwarded_https { } log_format clear '[$time_iso8601] $remote_addr ' - '$request_method $request_uri$is_args$args $status ' + '$request_method $request_uri $status ' ' sent=$body_bytes_sent bytes;' ' referrer=$http_referer;' ' user-agent=$http_user_agent'; -- GitLab From bdc210d70d2bbfc914abde2603125cff38e6064c Mon Sep 17 00:00:00 2001 From: Dom Sekotill Date: Wed, 19 Feb 2020 00:14:39 +0000 Subject: [PATCH 8/8] Update GitLab-CI with source tree rearrangements --- .gitlab-ci.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9b8fb57..2a78f43 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -19,12 +19,9 @@ before_script: only: &build-only changes: - Dockerfile - - entrypoint.sh - - nginx.conf - - opcache.ini + - data/* + - plugins/* - scripts/* - - wp-config.php - - wp.sh script: - docker build . --pull=true -- GitLab