From 3c080e31ca9d97e415e904e06353efa866a41a82 Mon Sep 17 00:00:00 2001 From: Volodymyr Kolesnykov Date: Sun, 2 Jun 2024 09:04:16 +0300 Subject: [PATCH] refactor(wordpress): make code friendly to various base images --- .../src/wordpress/devcontainer-feature.json | 8 +++-- features/src/wordpress/install.sh | 36 +++++++++---------- features/src/wordpress/setup-wordpress.sh | 1 + .../src/wordpress/wordpress-update-content.sh | 5 +++ 4 files changed, 27 insertions(+), 23 deletions(-) create mode 100755 features/src/wordpress/wordpress-update-content.sh diff --git a/features/src/wordpress/devcontainer-feature.json b/features/src/wordpress/devcontainer-feature.json index 9a735a12..a886fa54 100644 --- a/features/src/wordpress/devcontainer-feature.json +++ b/features/src/wordpress/devcontainer-feature.json @@ -2,11 +2,13 @@ "id": "wordpress", "name": "WordPress", "description": "Sets up WordPress into the Dev Environment", - "version": "2.3.4", + "version": "2.4.0", "containerEnv": { - "WP_CLI_CONFIG_PATH": "/etc/wp-cli/wp-cli.yaml" + "WP_CLI_CONFIG_PATH": "/etc/wp-cli/wp-cli.yaml", + "WP_CLI_ALLOW_ROOT": "1", + "COMPOSER_ALLOW_SUPERUSER": "1" }, - "updateContentCommand": "composer install -n || true", + "updateContentCommand": "/usr/local/bin/wordpress-update-content.sh", "postCreateCommand": "/usr/local/bin/wordpress-post-create.sh", "options": { "version": { diff --git a/features/src/wordpress/install.sh b/features/src/wordpress/install.sh index 26ef0b39..a5e8e4fc 100755 --- a/features/src/wordpress/install.sh +++ b/features/src/wordpress/install.sh @@ -9,36 +9,17 @@ if [ "$(id -u || true)" -ne 0 ]; then exit 1 fi -echo '(*) Downloading WordPress...' - -if [ -z "${_REMOTE_USER}" ] || [ "${_REMOTE_USER}" = "root" ]; then - WEB_USER="${CONTAINER_USER:-www-data}" -else - WEB_USER="${_REMOTE_USER}" -fi - +: "${_REMOTE_USER:?"_REMOTE_USER is required"}" : "${MOVEUPLOADSTOWORKSPACES:=}" : "${MULTISITE:=}" : "${VERSION:=latest}" -install -d -m 0755 -o root -g root /etc/wp-cli /usr/share/wordpress -install -m 0644 -o root -g root wp-cli.yaml /etc/wp-cli -install -d -o "${WEB_USER}" -g "${WEB_USER}" -m 0755 /wp -cp -a wp/* /wp && chown -R "${WEB_USER}:${WEB_USER}" /wp/* && chmod -R 0755 /wp/* && find /wp -type f -exec chmod 0644 {} \; -su-exec "${WEB_USER}:${WEB_USER}" wp core download --path=/wp --skip-content --version="${VERSION}" - if [ "${MOVEUPLOADSTOWORKSPACES}" != 'true' ]; then WP_PERSIST_UPLOADS="" else WP_PERSIST_UPLOADS=1 fi -install -m 0755 -o root -g root setup-wordpress.sh /usr/local/bin/setup-wordpress.sh -install -m 0755 -o root -g root wordpress-post-create.sh /usr/local/bin/wordpress-post-create.sh -install -m 0644 -o root -g root wp-config.php.tpl /usr/share/wordpress/ -install -m 0644 -o root -g root 010-wplogin.tpl /usr/share/wordpress/ -install -d -D -m 0755 -o root -g root /var/lib/wordpress/postinstall.d - WP_DOMAIN="${DOMAIN:-localhost}" if [ "${MULTISITE}" != 'true' ]; then WP_MULTISITE="" @@ -47,6 +28,21 @@ else fi WP_MULTISITE_TYPE="${MULTISITE_TYPE:-subdirectory}" +echo '(*) Downloading WordPress...' + +install -d -m 0755 -o root -g root /etc/wp-cli /usr/share/wordpress +install -m 0644 -o root -g root wp-cli.yaml /etc/wp-cli +install -d -o "${_REMOTE_USER}" -g "${_REMOTE_USER}" -m 0755 /wp +cp -a wp/* /wp +chmod -R 0755 /wp +find /wp -type f -exec chmod 0644 {} \; +wp --allow-root core download --path=/wp --skip-content --version="${VERSION}" +chown -R "${_REMOTE_USER}:${_REMOTE_USER}" /wp + +install -m 0755 -o root -g root setup-wordpress.sh wordpress-post-create.sh wordpress-update-content.sh /usr/local/bin/ +install -m 0644 -o root -g root wp-config.php.tpl 010-wplogin.tpl /usr/share/wordpress/ +install -d -D -m 0755 -o root -g root /var/lib/wordpress/postinstall.d /etc/conf.d + export WP_DOMAIN WP_MULTISITE WP_MULTISITE_TYPE WP_PERSIST_UPLOADS # shellcheck disable=SC2016 envsubst '$WP_DOMAIN $WP_MULTISITE $WP_MULTISITE_TYPE $WP_PERSIST_UPLOADS' < conf-wordpress.tpl > /etc/conf.d/wordpress diff --git a/features/src/wordpress/setup-wordpress.sh b/features/src/wordpress/setup-wordpress.sh index 9bac18c1..7cbecbd8 100755 --- a/features/src/wordpress/setup-wordpress.sh +++ b/features/src/wordpress/setup-wordpress.sh @@ -150,6 +150,7 @@ else fi if [ ! -f "${HOME}/.local/share/vip-codespaces/login/010-wplogin.sh" ]; then + install -D -d -m 0755 -o "${MY_UID}" -g "${MY_GID}" "${HOME}/.local/share/vip-codespaces/login" export WP_URL="${wp_url}" # shellcheck disable=SC2016 envsubst '$WP_URL' < /usr/share/wordpress/010-wplogin.tpl > "${HOME}/.local/share/vip-codespaces/login/010-wplogin.sh" diff --git a/features/src/wordpress/wordpress-update-content.sh b/features/src/wordpress/wordpress-update-content.sh new file mode 100755 index 00000000..34100a15 --- /dev/null +++ b/features/src/wordpress/wordpress-update-content.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +if [ -f composer.json ] && [ -x /usr/local/bin/composer ]; then + /usr/local/bin/composer install -n || true +fi