Skip to content

Commit

Permalink
fix(wordpress): more robust installer
Browse files Browse the repository at this point in the history
  • Loading branch information
sjinks committed Aug 17, 2024
1 parent 0a65b0f commit f1d3601
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 16 deletions.
6 changes: 2 additions & 4 deletions features/src/wordpress/devcontainer-feature.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
"id": "wordpress",
"name": "WordPress",
"description": "Sets up WordPress into the Dev Environment",
"version": "2.6.1",
"version": "2.6.2",
"documentationURL": "https://github.com/Automattic/vip-codespaces/tree/trunk/features/src/wordpress",
"containerEnv": {
"WP_CLI_CONFIG_PATH": "/etc/wp-cli/wp-cli.yaml",
"WP_CLI_ALLOW_ROOT": "1",
"COMPOSER_ALLOW_SUPERUSER": "1"
"WP_CLI_CONFIG_PATH": "/etc/wp-cli/wp-cli.yaml"
},
"updateContentCommand": "/usr/local/bin/wordpress-update-content.sh",
"postCreateCommand": "/usr/local/bin/wordpress-post-create.sh",
Expand Down
34 changes: 23 additions & 11 deletions features/src/wordpress/setup-wordpress.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ fi
MY_UID="$(id -u)"
MY_GID="$(id -g)"

if [ 0 -eq "${MY_UID}" ]; then
export WP_CLI_ALLOW_ROOT=1
fi

if [ -n "${RepositoryName}" ]; then
base=/workspaces/${RepositoryName}
else
Expand All @@ -50,25 +54,32 @@ fi
for i in client-mu-plugins images languages plugins themes; do
if [ -e "${base}/${i}" ]; then
sudo rm -rf "/wp/wp-content/${i}"
sudo ln -sf "${base}/${i}" "/wp/wp-content/${i}"
fi
done

if [ -e "${base}/vip-config" ]; then
sudo rm -rf "/wp/vip-config"
sudo ln -sf "${base}/vip-config" "/wp/vip-config"
sudo rm -rf /wp/vip-config
fi

sudo chown -R "${MY_UID}:${MY_GID}" /wp

for i in client-mu-plugins images languages plugins themes; do
if [ -e "${base}/${i}" ]; then
ln -sf "${base}/${i}" "/wp/wp-content/${i}"
fi
done

if [ -e "${base}/vip-config" ]; then
ln -sf "${base}/vip-config" "/wp/vip-config"
fi

if [ -n "${WP_PERSIST_UPLOADS}" ]; then
if [ -n "${WP_PERSIST_UPLOADS}" ] && [ -d /workspaces ]; then
sudo install -d -o "${MY_UID}" -g "${MY_GID}" -m 0755 /workspaces/uploads
sudo install -d -o "${MY_UID}" -g "${MY_GID}" -m 0755 /wp/wp-content
ln -sf /workspaces/uploads /wp/wp-content/uploads
else
sudo install -d -o "${MY_UID}" -g "${MY_GID}" -m 0755 /wp/wp-content/uploads
install -d -m 0755 /wp/wp-content/uploads
fi

sudo install -d -o "${MY_UID}" -g "${MY_GID}" /wp/config /wp/log

export WP_USERNAME="wordpress"
export WP_PASSWORD="wordpress"
export WP_DATABASE="wordpress"
Expand Down Expand Up @@ -110,8 +121,9 @@ fi
echo "GRANT ALL ON ${WP_DATABASE}.* TO 'netapp'@'localhost';"
} | mysql -h "${db_host}" -u "${db_admin_user}"

wp cache flush --skip-plugins --skip-themes
echo "Checking for WordPress installation..."
if ! wp core is-installed >/dev/null 2>&1; then
if ! wp core is-installed --skip-plugins --skip-themes >/dev/null 2>&1; then
echo "No installation found, installing WordPress..."

wp db clean --yes 2> /dev/null
Expand Down Expand Up @@ -152,11 +164,11 @@ if ! wp core is-installed >/dev/null 2>&1; then

run-parts /var/lib/wordpress/postinstall.d
else
echo "WordPress already installed"
echo "WordPress is already installed"
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"
install -D -d -m 0755 "${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
6 changes: 6 additions & 0 deletions features/src/wordpress/wordpress-post-create.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#!/bin/sh


if [ -f composer.json ] && [ -x /usr/local/bin/composer ]; then
MY_UID="$(id -un)"
if [ 0 -eq "${MY_UID}" ]; then
export COMPOSER_ALLOW_SUPERUSER=1
fi

/usr/local/bin/composer install -n || true
fi

Expand Down
7 changes: 6 additions & 1 deletion features/src/wordpress/wordpress-update-content.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
#!/bin/sh

if [ -f composer.json ] && [ -x /usr/local/bin/composer ]; then
MY_UID="$(id -un)"
if [ 0 -eq "${MY_UID}" ]; then
export COMPOSER_ALLOW_SUPERUSER=1
fi

/usr/local/bin/composer install -n || true
fi

if [ -f package.json ] && hash npm > /dev/null 2>&1; then
if [ -f package.json ] && hash npm >/dev/null 2>&1; then
if [ ! -d node_modules ] && [ -f package-lock.json ]; then
npm ci
else
Expand Down

0 comments on commit f1d3601

Please sign in to comment.