mirror of
https://github.com/N0rthernL1ghts/wordpress.git
synced 2024-11-23 14:13:27 +01:00
Initialize WordPress during build time
This commit is contained in:
parent
a72f393567
commit
bb3f62ef10
|
@ -19,8 +19,8 @@ COPY ["./rootfs/", "/"]
|
||||||
# Configuration and patches
|
# Configuration and patches
|
||||||
ARG WP_VERSION
|
ARG WP_VERSION
|
||||||
|
|
||||||
# Copy docker-optimized wp-config from official image
|
# Copy WordPress source from the official image
|
||||||
COPY --from=wp-src ["/usr/src/wordpress/wp-config-docker.php", "/var/www/html/wp-config.php"]
|
COPY --from=wp-src ["/usr/src/wordpress/", "/var/www/html/"]
|
||||||
|
|
||||||
COPY ["patches/${WP_VERSION}/wp-admin-update-core.patch", "/etc/wp-mods/"]
|
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
|
ARG WP_VERSION
|
||||||
ENV WP_VERSION="${WP_VERSION}"
|
ENV WP_VERSION="${WP_VERSION}"
|
||||||
ARG WP_LOCALE="en_US"
|
|
||||||
ENV WP_LOCALE=${WP_LOCALE}
|
|
||||||
ENV ENFORCE_DISABLE_WP_UPDATES=true
|
ENV ENFORCE_DISABLE_WP_UPDATES=true
|
||||||
ENV WP_CLI_DISABLE_AUTO_CHECK_UPDATE=true
|
ENV WP_CLI_DISABLE_AUTO_CHECK_UPDATE=true
|
||||||
ENV CRON_ENABLED=true
|
ENV CRON_ENABLED=true
|
||||||
|
|
||||||
WORKDIR "/var/www/html/"
|
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 <aleksandar@puharic.com>"
|
LABEL maintainer="Aleksandar Puharic <aleksandar@puharic.com>"
|
||||||
ENTRYPOINT ["/init"]
|
ENTRYPOINT ["/init"]
|
||||||
|
|
|
@ -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
|
* If you need nginx, you can set it up as a reverse proxy
|
||||||
* NGINX Unit is modern application server, replacing old PHP-FPM
|
* 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
|
* 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)
|
#### Public builds (docker)
|
||||||
|
|
||||||
|
|
|
@ -22,28 +22,17 @@ function disableUpdatesPatch() {
|
||||||
if [ "${DISABLE_WP_UPDATES}" != "false" ]; then
|
if [ "${DISABLE_WP_UPDATES}" != "false" ]; then
|
||||||
echo "> Disabling WordPress updates..."
|
echo "> Disabling WordPress updates..."
|
||||||
patch /var/www/html/wp-admin/update-core.php </etc/wp-mods/wp-admin-update-core.patch
|
patch /var/www/html/wp-admin/update-core.php </etc/wp-mods/wp-admin-update-core.patch
|
||||||
echo "> Making the patched file read-only..."
|
echo "> Marking the patched file read-only..."
|
||||||
chmod 0440 /var/www/html/wp-admin/update-core.php
|
chmod 0440 /var/www/html/wp-admin/update-core.php
|
||||||
fi
|
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
|
# Main function
|
||||||
function main() {
|
function main() {
|
||||||
# Removes trailing zero if found
|
# Removes trailing zero if found
|
||||||
# This is required due to inconsistencies between WodPress docker image versioning and wp-cli core download
|
# 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.
|
# If patch version is 0, it is not considered by wp-cli.
|
||||||
WP_VERSION=$(echo "${WP_VERSION:?}" | sed --expression='s/.0$//g')
|
WP_VERSION=$(echo "${WP_VERSION:?}" | sed --expression='s/.0$//g')
|
||||||
WP_LOCALE="${WP_LOCALE:?}"
|
|
||||||
|
|
||||||
echo "> Verifying 'WordPress ${WP_VERSION}' installation..."
|
echo "> Verifying 'WordPress ${WP_VERSION}' installation..."
|
||||||
WP_INSTALLED_VERSION="$(wp core version)"
|
WP_INSTALLED_VERSION="$(wp core version)"
|
||||||
|
@ -51,22 +40,26 @@ function main() {
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
if [ -z "${WP_INSTALLED_VERSION}" ]; then
|
if [ -z "${WP_INSTALLED_VERSION}" ]; then
|
||||||
echo "> WordPress is not present"
|
echo "> ERROR! WordPress installation does not seem to be present or valid. Continuing anyway..."
|
||||||
echo "> Downloading 'WordPress ${WP_VERSION}'..."
|
return 0
|
||||||
deleteWordPress
|
|
||||||
wp core download --locale="${WP_LOCALE}" --version="${WP_VERSION}"
|
|
||||||
disableUpdatesPatch
|
|
||||||
elif [ "${WP_INSTALLED_VERSION}" != "${WP_VERSION}" ]; then
|
elif [ "${WP_INSTALLED_VERSION}" != "${WP_VERSION}" ]; then
|
||||||
echo "> WordPress version mismatch"
|
echo "> WARNING! WordPress version mismatch"
|
||||||
echo "> Expected version: ${WP_VERSION}"
|
echo " Expected version: ${WP_VERSION}"
|
||||||
echo "> Detected version: ${WP_INSTALLED_VERSION}"
|
echo " Detected version: ${WP_INSTALLED_VERSION}"
|
||||||
echo "> Scraping current files"
|
echo "> Seems like WordPress installation got updated outside image scope"
|
||||||
deleteWordPress
|
echo " - This is dangerous as changes will not persist when container is recreated which might lead to inconsistencies between installation and the database."
|
||||||
echo "> Downloading WordPress version '${WP_VERSION}'..."
|
echo " - You should assume that recreating the container will render the website inoperable."
|
||||||
wp core download --locale="${WP_LOCALE}" --version="${WP_VERSION}"
|
echo " - Please make sure that you're running image: nlss/wordpress:${WP_VERSION}"
|
||||||
disableUpdatesPatch
|
return 0
|
||||||
else
|
else
|
||||||
echo "> Identified 'WordPress ${WP_VERSION}'"
|
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
|
fi
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user