From 3125f1cfb29202d142101db80461fad31df7297d Mon Sep 17 00:00:00 2001 From: Edie Lemoine Date: Thu, 19 Sep 2024 11:51:56 +0200 Subject: [PATCH] fix(wordpress): fix ssl always being forced and plugins not installing (#16) --- images/wordpress/.env.template | 69 ------------------- images/wordpress/Dockerfile | 9 ++- .../config/wordpress/wp-cli.template.yml | 8 ++- images/wordpress/scripts/_install-plugins.sh | 27 ++++++-- images/wordpress/scripts/entrypoint.sh | 3 - 5 files changed, 34 insertions(+), 82 deletions(-) delete mode 100644 images/wordpress/.env.template diff --git a/images/wordpress/.env.template b/images/wordpress/.env.template deleted file mode 100644 index 8d7288d..0000000 --- a/images/wordpress/.env.template +++ /dev/null @@ -1,69 +0,0 @@ -### -# Core variables -### -BASE_URL=localhost:8130 -FULL_URL=https://${BASE_URL} -ROOT_DIR=/var/www/html - -### -# Set to 0 if you have a separate nginx container in your setup, to 1 to include nginx in this container. -### -WITH_NGINX=0 - -### -# Database -### -DB_HOST=db -DB_PORT=3306 -DB_USER=wordpress -DB_PASSWORD=wordpress -DB_NAME=wordpress -DB_PREFIX=wp_ - -### -# WordPress -### -WP_LOCALE=nl_NL -WP_SITE_NAME=wordpress -WP_URL_REPLACE=${FULL_URL} -WP_PLUGINS=woocommerce -WP_THEMES=storefront -WP_DEBUG=true -WP_DEBUG_DISPLAY=true -WP_ALTERNATE_WP_CRON=true - -WP_ADMIN_EMAIL=admin@${BASE_URL} -WP_ADMIN_USER=admin -WP_ADMIN_PASSWORD=admin - -WP_CUSTOMER_EMAIL=customer@${BASE_URL} -WP_CUSTOMER_USER=customer -WP_CUSTOMER_PASSWORD=customer - -### -# MySQL -### -MYSQL_HOST=${DB_HOST} -MYSQL_TCP_PORT=${DB_PORT} -MYSQL_UNIX_PORT=${DB_PORT} -MYSQL_ROOT_PASSWORD=root -MYSQL_USER=${DB_USER} -MYSQL_PASSWORD=${DB_PASSWORD} -MYSQL_DATABASE=${DB_NAME} -MYSQL_TABLE_PREFIX=${DB_PREFIX} - -### -# Nginx -### -NGINX_HOST=${BASE_URL} -NGINX_PORT=80 - -### -# Miscellaneous -### -# https://xdebug.org/docs/all_settings#mode -XDEBUG_MODE=debug - -PHP_IDE_CONFIG="serverName=${BASE_URL}" - -BLACKFIRE_DISABLE_LEGACY_PORT=1 diff --git a/images/wordpress/Dockerfile b/images/wordpress/Dockerfile index 6b2bd1f..967d766 100644 --- a/images/wordpress/Dockerfile +++ b/images/wordpress/Dockerfile @@ -76,16 +76,19 @@ COPY ./config/wordpress /tmp/wordpress # Copy nginx config COPY ./etc/nginx/http.d/* /etc/nginx/http.d/ +ENV PHP_VERSION=${PHP_VERSION} ENV WP_VERSION=${WP_VERSION} -ENV ROOT_DIR=${ROOT_DIR} - ### # Core ### ENV BASE_URL=localhost:8130 ENV FULL_URL=https://${BASE_URL} -ENV ROOT_DIR=/var/www/html +ENV ROOT_DIR=${ROOT_DIR} +ENV WITH_NGINX=0 + +ENV TMP_PLUGINS_DIR="/tmp/plugins" +ENV WP_PLUGINS_DIR="${ROOT_DIR}/wp-content/plugins" ### # Database diff --git a/images/wordpress/config/wordpress/wp-cli.template.yml b/images/wordpress/config/wordpress/wp-cli.template.yml index 3bd7436..7ceba9d 100644 --- a/images/wordpress/config/wordpress/wp-cli.template.yml +++ b/images/wordpress/config/wordpress/wp-cli.template.yml @@ -22,9 +22,11 @@ config create: @ini_set('display_errors', ${DISPLAY_ERRORS:-0}); - # SSL - define('FORCE_SSL_ADMIN', true); - $$_SERVER['HTTPS'] = 'on'; + # Force SSL if the URL starts with https:// + if (strpos('${WP_URL_REPLACE}', 'https://') === 0) { + define('FORCE_SSL_ADMIN', true); + $$_SERVER['HTTPS'] = 'on'; + } # Other $$_SERVER['document_root'] = dirname(__FILE__); diff --git a/images/wordpress/scripts/_install-plugins.sh b/images/wordpress/scripts/_install-plugins.sh index 8eff611..7dc51ca 100644 --- a/images/wordpress/scripts/_install-plugins.sh +++ b/images/wordpress/scripts/_install-plugins.sh @@ -1,6 +1,8 @@ install-plugins() { h1 "Linking, installing and activating plugins..." + PLUGINS_FOUND=$(find "$TMP_PLUGINS_DIR" -type d -mindepth 1 -maxdepth 1) + link-paths "$TMP_PLUGINS_DIR" "$WP_PLUGINS_DIR" if [ -n "$WP_SKIP_PLUGINS" ]; then @@ -8,11 +10,28 @@ install-plugins() { return fi - for path in "$TMP_PLUGINS_DIR"/*/; do - plugin=$(basename "$path") + if [ -z "$PLUGINS_FOUND" ]; then + h2 "No local plugins to install." + else + h2 "Installing local plugins..." + for path in $PLUGINS_FOUND; do + plugin=$(basename "$path") + + wp-activate plugin "$plugin" + done + fi + + PLUGINS_LIST=$(echo "$WP_PLUGINS" | tr ',' '\n') + + if [ -z "$PLUGINS_LIST" ]; then + h2 "No remote plugins to install." + else + h2 "Downloading and installing remote plugins..." - wp-activate plugin "$plugin" - done + for plugin in $PLUGINS_LIST; do + wp-activate plugin "$plugin" + done + fi h2 "Finished installing and activating plugins." } diff --git a/images/wordpress/scripts/entrypoint.sh b/images/wordpress/scripts/entrypoint.sh index cb87712..49cc0bd 100755 --- a/images/wordpress/scripts/entrypoint.sh +++ b/images/wordpress/scripts/entrypoint.sh @@ -2,9 +2,6 @@ declare -i term_width=70 -export TMP_PLUGINS_DIR="/tmp/plugins" -export WP_PLUGINS_DIR="$ROOT_DIR/wp-content/plugins" - for script in /tmp/scripts/_*; do source $script; done # Start php fpm in the background in advance.