Skip to content

Commit 50edf1e

Browse files
authored
Merge pull request #381 from roundcube/pre-and-post-setup-scripts
2 parents 15d7f03 + 1d8ea95 commit 50edf1e

15 files changed

Lines changed: 190 additions & 7 deletions

.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 \

.github/workflows/test.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ jobs:
7070
set -exu;
7171
for testFile in ${{ join(matrix.test-files, ' ') }};
7272
do
73-
docker compose -f ./tests/docker-compose.test-${testFile}.yml \
74-
up --exit-code-from=sut --abort-on-container-exit
73+
docker compose -f ./tests/docker-compose.test-${testFile}.yml down -v
74+
docker compose -f ./tests/docker-compose.test-${testFile}.yml up --exit-code-from=sut --abort-on-container-exit
7575
done
7676
7777
- name: Build nonroot image for "${{ matrix.variant }}"
@@ -91,6 +91,6 @@ jobs:
9191
set -exu;
9292
for testFile in ${{ join(matrix.test-files, ' ') }};
9393
do
94-
docker compose -f ./tests/docker-compose.test-${testFile}.yml \
95-
up --exit-code-from=sut --abort-on-container-exit
94+
docker compose -f ./tests/docker-compose.test-${testFile}.yml down -v
95+
docker compose -f ./tests/docker-compose.test-${testFile}.yml up --exit-code-from=sut --abort-on-container-exit
9696
done

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/nginx-default.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ server {
44
server_tokens off;
55
autoindex off;
66

7-
root /var/www/html;
7+
root /var/www/html/public_html;
88

99
location / {
1010
index index.php;

0 commit comments

Comments
 (0)