Skip to content

Commit 86b3d24

Browse files
author
Maya Baya
committed
feat: Add support for plugins and website preinstallation
1 parent 26e17a6 commit 86b3d24

File tree

5 files changed

+121
-14
lines changed

5 files changed

+121
-14
lines changed

Dockerfile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ ENV AUTO_UPDATE_CRON="0 5 * * TUE" \
1717
PHP_UPLOAD_MAX_FILESIZE="32M" \
1818
PHP_MEMORY_LIMIT="128M" \
1919
HEALTH_CHECK_ALLOWED_SUBNET="" \
20-
FORCE_UPGRADE=false
20+
FORCE_UPGRADE=false \
21+
ENABLED_PLUGINS="" \
22+
WP_PREINSTALL=false \
23+
WP_SITE_URL=example.org \
24+
WP_SITE_ADMIN_LOGIN=admin \
25+
WP_SITE_ADMIN_PASSWORD=riotkit \
26+
WP_SITE_ADMIN_EMAIL=example@example.org
2127

2228
# p2 (jinja2)
2329
RUN wget https://github.com/wrouesnel/p2cli/releases/download/r13/p2-linux-x86_64 -O /usr/bin/p2 && chmod +x /usr/bin/p2
@@ -73,7 +79,8 @@ RUN cat /etc/group | grep -v "www-data" > /etc/group.tmp \
7379
# add entrypoints
7480
ADD container-files/entrypoint-riotkit.sh /usr/local/bin/
7581
ADD container-files/entrypoint.sh /usr/local/bin/docker-entrypoint.sh
76-
RUN chmod +x /usr/local/bin/entrypoint-riotkit.sh /usr/local/bin/docker-entrypoint.sh
82+
ADD container-files/install-plugins-first-time.sh /usr/local/bin/install-plugins-first-time.sh
83+
RUN chmod +x /usr/local/bin/entrypoint-riotkit.sh /usr/local/bin/docker-entrypoint.sh /usr/local/bin/install-plugins-first-time.sh
7784

7885
# high user id number should be more compatible with OpenShift
7986
USER 65161

Makefile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,17 @@ build:
66
run:
77
docker run --rm --name wp-riotkit -p 8090:8080 ${IMAGE}
88

9-
test: test_installed
9+
test: test_installed test_installs_plugins
1010

1111
test_installed:
1212
docker run --rm --name wp-riotkit ${IMAGE} /bin/bash -c "echo 'Testing installation...'; test -f /var/www/riotkit/index.php && test -f /var/www/riotkit/wp-admin/index.php"
13+
14+
test_installs_plugins:
15+
docker rm -f wph-test-mariadb || true
16+
docker network remove wph-test || true
17+
docker network create wph-test
18+
19+
# MariaDB (dependency)
20+
docker run --rm -d --name wph-test-mariadb -e MARIADB_ROOT_PASSWORD=riotkit -e MARIADB_PASSWORD=riotkit -e MARIADB_USER=wp -e MARIADB_DATABASE=wp --network wph-test --network-alias mariadb.db.svc.cluster.local mariadb:10.7.3 && sleep 15
21+
docker run --rm --name wp-riotkit -e WP_PREINSTALL=true -e WORDPRESS_DB_HOST=mariadb.db.svc.cluster.local -e WORDPRESS_DB_PASSWORD=riotkit -e WORDPRESS_DB_USER=root -e WORDPRESS_DB_NAME=wp -e ENABLED_PLUGINS="amazon-s3-and-cloudfront,classic-editor" --network wph-test ${IMAGE} /bin/bash -c "/bin/true"
22+
docker rm -f wph-test-mariadb || true

README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Hardened version of official Wordpress container, with special support for Kuber
1313
- Non-root container
1414
- Free from Supervisord, using lightweight [multirun](https://github.com/nicolas-van/multirun) instead
1515
- Runtime NGINX and PHP configuration to adjust things like `memory_limit`, `error_reporting` or `post_max_size`
16+
- Preconfiguration of admin account, website name and list of installed plugins
17+
- Possible to upgrade Wordpress together with docker container
1618

1719
Roadmap
1820
-------
@@ -77,6 +79,7 @@ services:
7779
AUTO_UPDATE_CRON: "0 5 * * SAT"
7880
XMLRPC_DISABLED: "true"
7981
DISABLE_DIRECT_CONTENT_PHP_EXECUTION: "false"
82+
ENABLED_PLUGINS: "amazon-s3-and-cloudfront"
8083

8184
# basic auth on administrative endpoints
8285
BASIC_AUTH_ENABLED: "true"
@@ -91,6 +94,64 @@ services:
9194

9295
```
9396

97+
Automating installation
98+
-----------------------
99+
100+
You can skip installation wizard by installing WordPress on container startup.
101+
This container uses `wp-cli` to install WordPress and plugins allowing you to prepare a fully automated website.
102+
103+
**Example configuration:**
104+
```yaml
105+
WP_PREINSTALL: true
106+
WP_SITE_URL: example.org
107+
WP_SITE_ADMIN_LOGIN: admin
108+
WP_SITE_ADMIN_PASSWORD: riotkit
109+
WP_SITE_ADMIN_EMAIL: example@example.org
110+
111+
# NOTICE: The plugins will be installed right after WordPress installation is finished,
112+
# this means that when `WP_PREINSTALL=false`, then the entrypoint will wait for user
113+
# to complete the installation wizard, then the plugins will be installed
114+
ENABLED_PLUGINS: "amazon-s3-and-cloudfront,classic-editor"
115+
```
116+
117+
**Example log:**
118+
119+
```bash
120+
>> Checking if autoupdate should be scheduled... [scheduling at '0 5 * * TUE']
121+
>> Writing to basic auth file - /opt/htpasswd
122+
Adding password for user riotkit
123+
>> Rendering configuration files...
124+
>> Installing Wordpress
125+
>> UID=65161, GID=65161
126+
WordPress not found in /var/www/riotkit - copying now...
127+
sending incremental file list
128+
index.php
129+
liveness.php
130+
readiness.php
131+
...
132+
wp-includes/widgets/class-wp-widget-text.php
133+
134+
sent 58,545,704 bytes received 54,312 bytes 39,066,677.33 bytes/sec
135+
total size is 58,341,389 speedup is 1.00
136+
Complete! WordPress has been successfully copied to /var/www/riotkit
137+
No 'wp-config.php' found in /var/www/riotkit, but 'WORDPRESS_...' variables supplied; copying 'wp-config-docker.php' (WORDPRESS_DB_HOST WORDPRESS_DB_NAME WORDPRESS_DB_PASSWORD WORDPRESS_DB_USER)
138+
Success: WordPress installed successfully.
139+
>> Installing plugin 'amazon-s3-and-cloudfront'
140+
Installing WP Offload Media Lite for Amazon S3, DigitalOcean Spaces, and Google Cloud Storage (2.6.2)
141+
Downloading installation package from https://downloads.wordpress.org/plugin/amazon-s3-and-cloudfront.2.6.2.zip...
142+
Unpacking the package...
143+
Installing the plugin...
144+
Plugin installed successfully.
145+
Success: Installed 1 of 1 plugins.
146+
>> Installing plugin 'classic-editor'
147+
Installing Classic Editor (1.6.2)
148+
Downloading installation package from https://downloads.wordpress.org/plugin/classic-editor.1.6.2.zip...
149+
Unpacking the package...
150+
Installing the plugin...
151+
Plugin installed successfully.
152+
Success: Installed 1 of 1 plugins.
153+
```
154+
94155
From authors
95156
------------
96157

container-files/entrypoint-riotkit.sh

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,15 @@
33
set -eo pipefail
44

55
setupWP() {
6-
# Warning: HACK below :)
7-
# mock php-fpm to not start it immediately by WordPress entrypoint
8-
echo " >> Mock php-fpm"
9-
mv /usr/local/sbin/php-fpm /usr/local/sbin/php-fpm.bckp
10-
ln -s /bin/bash /usr/local/sbin/php-fpm
11-
126
echo " >> Installing Wordpress"
13-
/usr/local/bin/docker-entrypoint.sh php-fpm || exit 1
7+
/usr/local/bin/docker-entrypoint.sh || exit 1
8+
}
149

15-
echo " >> Cleaning up the mock"
16-
rm /usr/local/sbin/php-fpm
17-
mv /usr/local/sbin/php-fpm.bckp /usr/local/sbin/php-fpm
10+
preinstallWP() {
11+
if [[ "${WP_PREINSTALL}" == "true" ]]; then
12+
wp core install --url=${WP_SITE_URL} --title=${WP_SITE_TITLE} --admin_user=${WP_SITE_ADMIN_LOGIN} --admin_password=${WP_SITE_ADMIN_PASSWORD} --admin_email=${WP_SITE_ADMIN_EMAIL}
13+
/usr/local/bin/install-plugins-first-time.sh no-wait
14+
fi
1815
}
1916

2017
scheduleAutoupdate() {
@@ -46,6 +43,7 @@ scheduleAutoupdate
4643
setupBasicAuth
4744
setupConfiguration
4845
setupWP
46+
preinstallWP
4947

5048
# Allows to pass own CMD
5149
# Also allows to execute tests on the container
@@ -54,4 +52,4 @@ if [[ "${1}" == "exec" ]] || [[ "${1}" == "sh" ]] || [[ "${1}" == "bash" ]] || [
5452
exec "$@"
5553
fi
5654

57-
exec multirun "php-fpm" "nginx -c /etc/nginx/nginx.conf" "crond -f -d 6"
55+
exec multirun "php-fpm" "nginx -c /etc/nginx/nginx.conf" "crond -f -d 6" "/usr/local/bin/install-plugins-first-time.sh"
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
installPlugins() {
4+
IFS=, read -ra plugins <<< "${ENABLED_PLUGINS}"
5+
for plugin in "${plugins[@]}"; do
6+
echo " >> Installing plugin '${plugin}'"
7+
wp plugin install "${plugin}" || return 1
8+
done
9+
}
10+
11+
if [[ "${1}" == "no-wait" ]]; then
12+
installPlugins
13+
else
14+
while [[ ! -f /var/www/riotkit/wp-content/.plugins-installed ]]; do
15+
if wp core is-installed; then
16+
if installPlugins; then
17+
echo " >> Plugins installed"
18+
break
19+
else
20+
echo " !!! Plugins installation failed"
21+
fi
22+
else
23+
echo " ... Waiting for Wordpress to be installed"
24+
fi
25+
26+
sleep 20
27+
done
28+
29+
echo ">> Fuckwork mode on"
30+
sleep 999999999
31+
fi

0 commit comments

Comments
 (0)