Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(wordpress): make code friendly to various base images #229

Merged
merged 1 commit into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions features/src/wordpress/devcontainer-feature.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
36 changes: 16 additions & 20 deletions features/src/wordpress/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=""
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions features/src/wordpress/setup-wordpress.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions features/src/wordpress/wordpress-update-content.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

if [ -f composer.json ] && [ -x /usr/local/bin/composer ]; then
/usr/local/bin/composer install -n || true
fi