Skip to content

Commit 38d8a35

Browse files
author
Maya Baya
committed
feat: Improvements to the plugin installation, so all plugins
1 parent 8841c8e commit 38d8a35

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
lines changed

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ ENV AUTO_UPDATE_CRON="0 5 * * TUE" \
2626
WP_SITE_ADMIN_EMAIL=example@example.org \
2727
ACCESS_LOG=/dev/stdout \
2828
ERROR_LOG=/dev/stderr \
29-
WORDPRESS_DB_TABLE_PREFIX=wp_
29+
WORDPRESS_TABLE_PREFIX=wp_ \
30+
WP_INSTALLATION_WAIT_INTERVAL=20 \
31+
WP_PLUGINS_REINSTALL_RETRIES=30
3032

3133
# p2 (jinja2)
3234
RUN wget https://github.com/wrouesnel/p2cli/releases/download/r13/p2-linux-x86_64 -O /usr/bin/p2 && chmod +x /usr/bin/p2

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,12 @@ services:
8080
WORDPRESS_DB_USER: "your_user"
8181
WORDPRESS_DB_PASSWORD: "${DB_PASSWORD_THERE}"
8282
WORDPRESS_DB_NAME: "your_app"
83+
WORDPRESS_TABLE_PREFIX: "wp_"
8384
AUTO_UPDATE_CRON: "0 5 * * SAT"
8485
XMLRPC_DISABLED: "true"
8586
DISABLE_DIRECT_CONTENT_PHP_EXECUTION: "false"
8687
ENABLED_PLUGINS: "amazon-s3-and-cloudfront"
87-
88+
8889
# basic auth on administrative endpoints
8990
BASIC_AUTH_ENABLED: "true"
9091
BASIC_AUTH_USER: john
@@ -116,6 +117,9 @@ WP_SITE_ADMIN_EMAIL: example@example.org
116117
# this means that when `WP_PREINSTALL=false`, then the entrypoint will wait for user
117118
# to complete the installation wizard, then the plugins will be installed
118119
ENABLED_PLUGINS: "amazon-s3-and-cloudfront,classic-editor"
120+
121+
WP_INSTALLATION_WAIT_INTERVAL: 20 # in seconds, how long to wait until the WordPress is installed to start installing plugins
122+
WP_PLUGINS_REINSTALL_RETRIES: 30 # 30 retries with 20s interval
119123
```
120124
121125
**Example log:**
@@ -156,6 +160,13 @@ Plugin installed successfully.
156160
Success: Installed 1 of 1 plugins.
157161
```
158162
163+
### How it works?
164+
165+
- Plugins will be installed AFTER WordPress will be installed. Use `WP_PREINSTALL: true` to install WordPress immediately, else the plugins will be installed after user will finish installation process
166+
- There will be `WP_PLUGINS_REINSTALL_RETRIES` retries of plugins installation
167+
- If at least one plugin installation will fail, then **after exceeding maximum number of retries the container will exit**
168+
- Even if some plugins installation will fail, the rest will be installed (installation process does not exit immediately after first fail)
169+
159170
Keeping wp-content and themes in GIT repository (Kubernetes only)
160171
-----------------------------------------------------------------
161172

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,46 @@
11
#!/bin/bash
22

33
installPlugins() {
4+
status=0
5+
46
IFS=, read -ra plugins <<< "${ENABLED_PLUGINS}"
57
for plugin in "${plugins[@]}"; do
68
echo " >> Installing plugin '${plugin}'"
7-
wp plugin install "${plugin}" || return 1
9+
if ! wp plugin install "${plugin}"; then
10+
status=1
11+
fi
812
done
13+
14+
return ${status}
915
}
1016

1117
if [[ "${1}" == "no-wait" ]]; then
1218
installPlugins
1319
else
20+
retryNum=0
21+
retryMaxNum=${WP_PLUGINS_REINSTALL_RETRIES}
22+
1423
while [[ ! -f /var/www/riotkit/wp-content/.plugins-installed ]]; do
1524
if wp core is-installed; then
1625
if installPlugins; then
1726
echo " >> Plugins installed"
1827
break
1928
else
29+
if [[ "$retryNum" -gt "$retryMaxNum" ]]; then
30+
echo " >> Cannot install plugins - maximum retries of ${$retryMaxNum} exceeded"
31+
exit 1
32+
fi
33+
2034
echo " !!! Plugins installation failed"
35+
retryNum=$((retryNum+1))
2136
fi
2237
else
2338
echo " ... Waiting for Wordpress to be installed"
2439
fi
2540

26-
sleep 20
41+
sleep "${WP_INSTALLATION_WAIT_INTERVAL}"
2742
done
2843

29-
echo ">> Fuckwork mode on"
44+
echo ">> Plugins installed, fuckwork mode on"
3045
sleep 999999999
3146
fi

wp-config-sample.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
* You can have multiple installations in one database if you give each
5959
* a unique prefix. Only numbers, letters, and underscores please!
6060
*/
61-
$table_prefix = isset($_SERVER['WORDPRESS_DB_TABLE_PREFIX']) ? $_SERVER['WORDPRESS_DB_TABLE_PREFIX'] : 'wp_';
61+
$table_prefix = isset($_SERVER['WORDPRESS_TABLE_PREFIX']) ? $_SERVER['WORDPRESS_TABLE_PREFIX'] : 'wp_';
6262

6363
/**
6464
* For developers: WordPress debugging mode.

0 commit comments

Comments
 (0)