Skip to content

Commit 1d8ea95

Browse files
committed
Pre-setup and post-setup tasks
All executable files present in /entrypoint-tasks/pre-setup/ and /entrypoint-tasks/post-setup/ are run at the beginning or at the end, respectively, of the actual entrypoint-script. Each of the executed files receive the CMD given to the container as their arguments. This allows e.g. to change a plugin's config, or install a technical requirement of a plugin that is to be installed. This feature is not implemented in the images for Roundcube v1.5, since they are not well maintained and will be dropped soon, anyways.
1 parent efb91c2 commit 1d8ea95

13 files changed

Lines changed: 184 additions & 1 deletion

File tree

.github/workflows/test-1.5.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ jobs:
5353
# Set these here so the values are visible in the logs for debugging.
5454
export ROUNDCUBEMAIL_TEST_IMAGE="${{ matrix.docker-tag }}"
5555
export HTTP_PORT="${{ matrix.http-port || '80' }}"
56+
export SKIP_POST_SETUP_SCRIPT_TEST="yes"
5657
for testFile in ${{ join(matrix.test-files, ' ') }};
5758
do
5859
docker compose -f ./tests/docker-compose.test-${testFile}.yml \

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,19 @@ For example:
149149
ROUNDCUBEMAIL_PLUGINS: thunderbird_labels, show_folder_size, tls_icon
150150
```
151151
152+
To overwrite the default config of a plugin you might need to use a post-setup script (see below) that moves a custom config file into the plugin's directory.
153+
154+
## Pre-setup and post-setup tasks
155+
156+
In order to execute custom tasks before or after Roundcubemail is set up in the container, you can bind-mount directories to `/entrypoint-tasks/pre-setup/` and `/entrypoint-tasks/post-setup/`. Then all executable files in those directories are executed at the beginning or the end of the actual entrypoint-script, respectively. If an executable exits with a code > 1, the entrypoint script exits, too.
157+
158+
Each executable receives the container's `CMD` as arguments.
159+
160+
They are executed in alphabetical order (the way `bash` understands it in `en_US` locale).
161+
162+
If the Roundcubemail-setup is skipped due to a custom `CMD`, these tasks are skipped as well.
163+
164+
152165
## HTTPS
153166

154167
Currently all images are configured to speak HTTP. To provide HTTPS please run an additional reverse proxy in front of them, which handles certificates and terminates TLS. Alternatively you could derive from our images (or use the advanced configuration methods) to make Apache or nginx provide HTTPS – but please refrain from opening issues asking for support with such a setup.

apache/docker-entrypoint.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,36 @@
33

44
# PWD=`pwd`
55

6+
run_entrypoint_tasks() {
7+
phase="$1"
8+
shift
9+
shopt -s nullglob
10+
echo "Running $phase-setup tasks:"
11+
for file in /entrypoint-tasks/"$phase-setup"/*; do
12+
if test ! -f "$file"; then
13+
echo "Ignoring $file because it is not a regular file."
14+
continue;
15+
fi
16+
if test ! -x "$file"; then
17+
echo "Ignoring $file because it is not executable."
18+
continue;
19+
fi
20+
echo "Running $phase-setup task $file:"
21+
"$file" "$@"
22+
# Exit in case of an error in an executable.
23+
exit_code=$?
24+
if test $exit_code -ne 0; then
25+
echo "The task exited with code $exit_code, thus the entrypoint script is exiting, too!"
26+
exit $exit_code
27+
fi
28+
echo 'Done.'
29+
done
30+
shopt -u nullglob
31+
}
32+
633
if [[ "$1" == apache2* || "$1" == php-fpm || "$1" == bin* ]]; then
34+
run_entrypoint_tasks pre "$@"
35+
736
INSTALLDIR=`pwd`
837
# docroot is empty
938
if ! [ -e index.php -a -e bin/installto.sh ]; then
@@ -207,6 +236,7 @@ if [[ "$1" == apache2* || "$1" == php-fpm || "$1" == bin* ]]; then
207236
which apk && apk add --no-cache $ASPELL_PACKAGES
208237
fi
209238

239+
run_entrypoint_tasks post "$@"
210240
fi
211241

212242
exec "$@"

fpm-alpine/docker-entrypoint.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,36 @@
33

44
# PWD=`pwd`
55

6+
run_entrypoint_tasks() {
7+
phase="$1"
8+
shift
9+
shopt -s nullglob
10+
echo "Running $phase-setup tasks:"
11+
for file in /entrypoint-tasks/"$phase-setup"/*; do
12+
if test ! -f "$file"; then
13+
echo "Ignoring $file because it is not a regular file."
14+
continue;
15+
fi
16+
if test ! -x "$file"; then
17+
echo "Ignoring $file because it is not executable."
18+
continue;
19+
fi
20+
echo "Running $phase-setup task $file:"
21+
"$file" "$@"
22+
# Exit in case of an error in an executable.
23+
exit_code=$?
24+
if test $exit_code -ne 0; then
25+
echo "The task exited with code $exit_code, thus the entrypoint script is exiting, too!"
26+
exit $exit_code
27+
fi
28+
echo 'Done.'
29+
done
30+
shopt -u nullglob
31+
}
32+
633
if [[ "$1" == apache2* || "$1" == php-fpm || "$1" == bin* ]]; then
34+
run_entrypoint_tasks pre "$@"
35+
736
INSTALLDIR=`pwd`
837
# docroot is empty
938
if ! [ -e index.php -a -e bin/installto.sh ]; then
@@ -207,6 +236,7 @@ if [[ "$1" == apache2* || "$1" == php-fpm || "$1" == bin* ]]; then
207236
which apk && apk add --no-cache $ASPELL_PACKAGES
208237
fi
209238

239+
run_entrypoint_tasks post "$@"
210240
fi
211241

212242
exec "$@"

fpm/docker-entrypoint.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,36 @@
33

44
# PWD=`pwd`
55

6+
run_entrypoint_tasks() {
7+
phase="$1"
8+
shift
9+
shopt -s nullglob
10+
echo "Running $phase-setup tasks:"
11+
for file in /entrypoint-tasks/"$phase-setup"/*; do
12+
if test ! -f "$file"; then
13+
echo "Ignoring $file because it is not a regular file."
14+
continue;
15+
fi
16+
if test ! -x "$file"; then
17+
echo "Ignoring $file because it is not executable."
18+
continue;
19+
fi
20+
echo "Running $phase-setup task $file:"
21+
"$file" "$@"
22+
# Exit in case of an error in an executable.
23+
exit_code=$?
24+
if test $exit_code -ne 0; then
25+
echo "The task exited with code $exit_code, thus the entrypoint script is exiting, too!"
26+
exit $exit_code
27+
fi
28+
echo 'Done.'
29+
done
30+
shopt -u nullglob
31+
}
32+
633
if [[ "$1" == apache2* || "$1" == php-fpm || "$1" == bin* ]]; then
34+
run_entrypoint_tasks pre "$@"
35+
736
INSTALLDIR=`pwd`
837
# docroot is empty
938
if ! [ -e index.php -a -e bin/installto.sh ]; then
@@ -207,6 +236,7 @@ if [[ "$1" == apache2* || "$1" == php-fpm || "$1" == bin* ]]; then
207236
which apk && apk add --no-cache $ASPELL_PACKAGES
208237
fi
209238

239+
run_entrypoint_tasks post "$@"
210240
fi
211241

212242
exec "$@"

templates/docker-entrypoint.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,36 @@
33

44
# PWD=`pwd`
55

6+
run_entrypoint_tasks() {
7+
phase="$1"
8+
shift
9+
shopt -s nullglob
10+
echo "Running $phase-setup tasks:"
11+
for file in /entrypoint-tasks/"$phase-setup"/*; do
12+
if test ! -f "$file"; then
13+
echo "Ignoring $file because it is not a regular file."
14+
continue;
15+
fi
16+
if test ! -x "$file"; then
17+
echo "Ignoring $file because it is not executable."
18+
continue;
19+
fi
20+
echo "Running $phase-setup task $file:"
21+
"$file" "$@"
22+
# Exit in case of an error in an executable.
23+
exit_code=$?
24+
if test $exit_code -ne 0; then
25+
echo "The task exited with code $exit_code, thus the entrypoint script is exiting, too!"
26+
exit $exit_code
27+
fi
28+
echo 'Done.'
29+
done
30+
shopt -u nullglob
31+
}
32+
633
if [[ "$1" == apache2* || "$1" == php-fpm || "$1" == bin* ]]; then
34+
run_entrypoint_tasks pre "$@"
35+
736
INSTALLDIR=`pwd`
837
# docroot is empty
938
if ! [ -e index.php -a -e bin/installto.sh ]; then
@@ -207,6 +236,7 @@ if [[ "$1" == apache2* || "$1" == php-fpm || "$1" == bin* ]]; then
207236
which apk && apk add --no-cache $ASPELL_PACKAGES
208237
fi
209238

239+
run_entrypoint_tasks post "$@"
210240
fi
211241

212242
exec "$@"

tests/docker-compose.test-apache-postgres.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ services:
2626
- ROUNDCUBEMAIL_DB_USER=roundcube # same as pgsql POSTGRES_USER env name
2727
- ROUNDCUBEMAIL_DB_PASSWORD=roundcube # same as pgsql POSTGRES_PASSWORD env name
2828
- ROUNDCUBEMAIL_SKIN=larry # Install non-default skin
29+
volumes:
30+
- "./pre-setup/:/entrypoint-tasks/pre-setup/"
31+
- "./post-setup/:/entrypoint-tasks/post-setup/"
2932

3033
roundcubedb:
3134
image: postgres:alpine
@@ -59,6 +62,7 @@ services:
5962
command: /tests/run.sh
6063
environment:
6164
- ROUNDCUBE_URL=http://roundcubemail:${HTTP_PORT:-80}/
65+
- SKIP_POST_SETUP_SCRIPT_TEST=${SKIP_POST_SETUP_SCRIPT_TEST:-no}
6266
volumes:
6367
- ./run.sh:/tests/run.sh:ro
6468
working_dir: /tests

tests/docker-compose.test-fpm-postgres.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ services:
2121
- roundcubemail-fpm
2222
volumes:
2323
- www-vol:/var/www/html
24+
- "./pre-setup/:/entrypoint-tasks/pre-setup/"
25+
- "./post-setup/:/entrypoint-tasks/post-setup/"
2426
environment:
2527
- ROUNDCUBEMAIL_DB_TYPE=pgsql
2628
- ROUNDCUBEMAIL_DB_HOST=roundcubedb # same as pgsql container name
@@ -89,6 +91,7 @@ services:
8991
working_dir: /tests
9092
environment:
9193
ROUNDCUBE_URL: http://roundcubenginx/
94+
SKIP_POST_SETUP_SCRIPT_TEST: ${SKIP_POST_SETUP_SCRIPT_TEST:-no}
9295
networks:
9396
roundcube_test_net:
9497

tests/post-setup/script.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
# Check that the file, which a pre-setup-script should have created, is present.
6+
test -f /tmp/something
7+
8+
# Leave a marker that can be checked from the outside.
9+
echo yes > public_html/post_setup_script.txt

tests/pre-setup/a-script

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
touch /tmp/something
6+
touch /tmp/anotherfile

0 commit comments

Comments
 (0)