From bb3f62ef10f9bc088f936da88e459e36ac916171 Mon Sep 17 00:00:00 2001 From: xZero707 Date: Mon, 23 Jan 2023 23:03:06 +0100 Subject: [PATCH] Initialize WordPress during build time --- Dockerfile | 8 ++-- README.md | 3 ++ ...{10-init-wordpress => 10-verify-wordpress} | 43 ++++++++----------- rootfs/usr/src/.gitkeep | 0 4 files changed, 24 insertions(+), 30 deletions(-) rename rootfs/etc/cont-init.d/{10-init-wordpress => 10-verify-wordpress} (53%) delete mode 100644 rootfs/usr/src/.gitkeep diff --git a/Dockerfile b/Dockerfile index 228a0e1..6549936 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,8 +19,8 @@ COPY ["./rootfs/", "/"] # Configuration and patches ARG WP_VERSION -# Copy docker-optimized wp-config from official image -COPY --from=wp-src ["/usr/src/wordpress/wp-config-docker.php", "/var/www/html/wp-config.php"] +# Copy WordPress source from the official image +COPY --from=wp-src ["/usr/src/wordpress/", "/var/www/html/"] COPY ["patches/${WP_VERSION}/wp-admin-update-core.patch", "/etc/wp-mods/"] @@ -36,14 +36,12 @@ RUN chmod a+x /usr/local/bin/wp ARG WP_VERSION ENV WP_VERSION="${WP_VERSION}" -ARG WP_LOCALE="en_US" -ENV WP_LOCALE=${WP_LOCALE} ENV ENFORCE_DISABLE_WP_UPDATES=true ENV WP_CLI_DISABLE_AUTO_CHECK_UPDATE=true ENV CRON_ENABLED=true WORKDIR "/var/www/html/" -VOLUME ["/root/.wp-cli", "/var/www/html", "/var/www/html/wp-content"] +VOLUME ["/root/.wp-cli", "/var/www/html/wp-content"] LABEL maintainer="Aleksandar Puharic " ENTRYPOINT ["/init"] diff --git a/README.md b/README.md index d8741e9..27ec7ab 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,9 @@ Attempt to fix several of WordPress anti-patterns in ready to deploy container * If you need nginx, you can set it up as a reverse proxy * NGINX Unit is modern application server, replacing old PHP-FPM * Independent benchmarks have show that NGINX Unit can handle much higher load and remain stable +- 2023-01-23 WordPress is no longer installed during runtime and it's bundled into the image + * This renders WP_LOCALE environment variable useless + * Instead, you will be offered to select locale during the first setup #### Public builds (docker) diff --git a/rootfs/etc/cont-init.d/10-init-wordpress b/rootfs/etc/cont-init.d/10-verify-wordpress similarity index 53% rename from rootfs/etc/cont-init.d/10-init-wordpress rename to rootfs/etc/cont-init.d/10-verify-wordpress index 1321392..986bc4e 100755 --- a/rootfs/etc/cont-init.d/10-init-wordpress +++ b/rootfs/etc/cont-init.d/10-verify-wordpress @@ -22,28 +22,17 @@ function disableUpdatesPatch() { if [ "${DISABLE_WP_UPDATES}" != "false" ]; then echo "> Disabling WordPress updates..." patch /var/www/html/wp-admin/update-core.php Making the patched file read-only..." + echo "> Marking the patched file read-only..." chmod 0440 /var/www/html/wp-admin/update-core.php fi } -# Deletes known WordPress files -function deleteWordPress() { - echo "> Deleting WordPress installation (core files)" - - # Instead of one-line find, we're taking a bit conservative approach and separating file and directory removal - # This is to ensure that this script never runs on unintended set of files as it's data loss risk - rm -rf "/var/www/html/"{wp-includes,wp-admin} - rm -rf "/var/www/html/"{.htaccess,index.php,license.txt,readme.html,wp-activate.php,wp-blog-header.php,wp-comments-post.php,wp-config-sample.php.php,wp-cron.php,wp-links-opml.php,wp-load.php,wp-login.php,wp-mail.php,wp-settings.php,wp-signup.php,wp-trackback.php,xmlrpc.php} -} - # Main function function main() { # Removes trailing zero if found # This is required due to inconsistencies between WodPress docker image versioning and wp-cli core download # If patch version is 0, it is not considered by wp-cli. WP_VERSION=$(echo "${WP_VERSION:?}" | sed --expression='s/.0$//g') - WP_LOCALE="${WP_LOCALE:?}" echo "> Verifying 'WordPress ${WP_VERSION}' installation..." WP_INSTALLED_VERSION="$(wp core version)" @@ -51,22 +40,26 @@ function main() { set -e if [ -z "${WP_INSTALLED_VERSION}" ]; then - echo "> WordPress is not present" - echo "> Downloading 'WordPress ${WP_VERSION}'..." - deleteWordPress - wp core download --locale="${WP_LOCALE}" --version="${WP_VERSION}" - disableUpdatesPatch + echo "> ERROR! WordPress installation does not seem to be present or valid. Continuing anyway..." + return 0 elif [ "${WP_INSTALLED_VERSION}" != "${WP_VERSION}" ]; then - echo "> WordPress version mismatch" - echo "> Expected version: ${WP_VERSION}" - echo "> Detected version: ${WP_INSTALLED_VERSION}" - echo "> Scraping current files" - deleteWordPress - echo "> Downloading WordPress version '${WP_VERSION}'..." - wp core download --locale="${WP_LOCALE}" --version="${WP_VERSION}" - disableUpdatesPatch + echo "> WARNING! WordPress version mismatch" + echo " Expected version: ${WP_VERSION}" + echo " Detected version: ${WP_INSTALLED_VERSION}" + echo "> Seems like WordPress installation got updated outside image scope" + echo " - This is dangerous as changes will not persist when container is recreated which might lead to inconsistencies between installation and the database." + echo " - You should assume that recreating the container will render the website inoperable." + echo " - Please make sure that you're running image: nlss/wordpress:${WP_VERSION}" + return 0 else echo "> Identified 'WordPress ${WP_VERSION}'" + + # This will apply patch once and again only if container is recreated + if [ ! -f "/var/www/patch-applied" ]; then + disableUpdatesPatch + touch "/var/www/patch-applied" + fi + fi } diff --git a/rootfs/usr/src/.gitkeep b/rootfs/usr/src/.gitkeep deleted file mode 100644 index e69de29..0000000