Skip to content

Commit e6a2f66

Browse files
author
Maya Baya
committed
feat: Extra volumes support
1 parent 6594a77 commit e6a2f66

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,24 @@ ACCESS_LOG: off
300300
ERROR_LOG: off
301301
```
302302

303+
Mounting extra volumes
304+
----------------------
305+
306+
Every file placed in `/mnt/extra-files` will be copied during startup to `/var/www/riotkit/`, this mechanism ensures that
307+
no any file will be created with root-permissions inside of a `/var/www/riotkit` directory - mounting a volume directly could do so.
308+
309+
```yaml
310+
pv:
311+
extraVolumes:
312+
- name: my-config
313+
configMap:
314+
name: my-configmap-name
315+
extraVolumeMounts:
316+
- name: my-config
317+
mountPath: /mnt/extra-files/wp-content/some-file.php
318+
subPath: some-file.php
319+
```
320+
303321
From authors
304322
------------
305323

container-files/entrypoint-riotkit.sh

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,27 @@
22

33
set -eo pipefail
44

5+
#
6+
# Setup Wordpress files, extracts from files provided by official WordPress base image
7+
#
58
setupWP() {
69
echo " >> Installing Wordpress"
710
/usr/local/bin/docker-entrypoint.sh || exit 1
811
}
912

13+
#
14+
# Preinstall WordPress, setup admin account, set URL, install plugins etc. - make it immediately ready
15+
#
1016
preinstallWP() {
1117
if [[ "${WP_PREINSTALL}" == "true" ]]; then
1218
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}
1319
/usr/local/bin/install-plugins-first-time.sh no-wait
1420
fi
1521
}
1622

23+
#
24+
# Automatic updates
25+
#
1726
scheduleAutoupdate() {
1827
echo -n " >> Checking if autoupdate should be scheduled..."
1928
if [[ "${AUTO_UPDATE_CRON}" != "" ]]; then
@@ -24,6 +33,9 @@ scheduleAutoupdate() {
2433
fi
2534
}
2635

36+
#
37+
# Basic AUTH on wp-login.php is a very primitive additional layer of security against bots
38+
#
2739
setupBasicAuth() {
2840
if [[ "${BASIC_AUTH_USER}" ]] && [[ "${BASIC_AUTH_PASSWORD}" ]]; then
2941
echo " >> Writing to basic auth file - /opt/htpasswd"
@@ -33,17 +45,34 @@ setupBasicAuth() {
3345
fi
3446
}
3547

48+
#
49+
# Runtime configuration setup: NGINX, PHP configuration is templated during startup
50+
# to allow using environment variables as configuration
51+
#
3652
setupConfiguration() {
3753
echo " >> Rendering configuration files..."
3854
p2 --template /templates/etc/nginx/nginx.conf > /etc/nginx/nginx.conf
3955
p2 --template /templates/usr/local/etc/php/php.ini > /usr/local/etc/php/php.ini
4056
}
4157

58+
#
59+
# Extra files: In /mnt/extra-files you can volume-mount extra files that would be copied into WWW-root directory
60+
# This allows to keep WWW-root directory not mounted by any volume to avoid conflicts with permissions
61+
# (mounted volumes are creating directories owned by ROOT)
62+
#
63+
copyExtraFiles() {
64+
echo " >> Copying extra files if placed in /mnt/extra-files"
65+
if [[ -d /mnt/extra-files ]]; then
66+
cp -rf /mnt/extra-files/* /var/www/riotkit/
67+
fi
68+
}
69+
4270
scheduleAutoupdate
4371
setupBasicAuth
4472
setupConfiguration
4573
setupWP
4674
preinstallWP
75+
copyExtraFiles
4776

4877
# Allows to pass own CMD
4978
# Also allows to execute tests on the container
@@ -52,4 +81,9 @@ if [[ "${1}" == "exec" ]] || [[ "${1}" == "sh" ]] || [[ "${1}" == "bash" ]] || [
5281
exec "$@"
5382
fi
5483

55-
exec multirun "php-fpm" "nginx -c /etc/nginx/nginx.conf" "crond -f -d 6" "/usr/local/bin/install-plugins-first-time.sh"
84+
multirun_args=("php-fpm" "nginx -c /etc/nginx/nginx.conf" "/usr/local/bin/install-plugins-first-time.sh")
85+
if [[ "${AUTO_UPDATE_CRON}" != "" ]]; then
86+
multirun_args+=("crond -f -d 6")
87+
fi
88+
89+
exec multirun "${multirun_args[@]}"

helm/wordpress-hardened/templates/deployment.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ spec:
129129
- name: wp-content
130130
mountPath: /var/www/riotkit/wp-content
131131
{{- end }}
132+
{{- with .Values.pv.extraVolumeMounts }}
133+
{{- toYaml . | nindent 22 }}
134+
{{- end }}
132135
ports:
133136
- name: http
134137
containerPort: 8080
@@ -178,3 +181,6 @@ spec:
178181
configMap:
179182
name: {{ include "wordpress-hardened.fullname" . }}-waf-custom-config
180183
{{- end }}
184+
{{- with .Values.pv.extraVolumes }}
185+
{{- toYaml . | nindent 14 }}
186+
{{- end }}

helm/wordpress-hardened/values.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ pv:
3737
size: 1Gi
3838
#storageClassName: "..."
3939

40+
# use those following to e.g. mount a custom ConfigMap, or a PVC with some data
41+
extraVolumes: []
42+
extraVolumeMounts: []
43+
4044

4145
ingresses: []
4246
# - name: wp-https

0 commit comments

Comments
 (0)