Skip to content

Commit 6283816

Browse files
committed
Add Apache2 configuration to docker-contributor
Adding configuration for Apache2 enables easier testing of webserver-specific features and issues. By default, the contributor image still uses NGINX as webserver. Add an option to use Apache2 by default, or switch back and forth between NGINX/Apache2 with the `switch-webserver` command.
1 parent 4983ddc commit 6283816

File tree

8 files changed

+58
-3
lines changed

8 files changed

+58
-3
lines changed

docker-contributor/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ ENV DEBIAN_FRONTEND=noninteractive \
1616
DJ_DB_INSTALL_BARE=0 \
1717
PHPSUPPORTED="8.1 8.2 8.3" \
1818
DEFAULTPHPVERSION="8.3" \
19+
DEFAULTWEBSERVER="nginx" \
1920
APTINSTALL="apt-get install -y -o Dpkg::Options::=--force-confdef -o Dpkg::Options::=--force-confold"
2021

2122
# Install required packages and clean up afterwards to make this image layer smaller

docker-contributor/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ The container includes the following:
99
* Set up or update the database.
1010
* Set up the webserver.
1111
* Create a chroot.
12-
* PHP-FPM and nginx for running the web interface.
12+
* PHP-FPM and apache2 or nginx for running the web interface.
1313
* Two running judgedaemons using a chroot.
1414
* Scripts for reading the log files of the webserver and the judgedaemons.
1515
* A script to create a dummy DOMjudge user and submit all test submissions.
@@ -67,6 +67,7 @@ The following environment variables are supported by the container:
6767
* `MYSQL_DATABASE` (defaults to `domjudge`): set the database to use.
6868
* `FPM_MAX_CHILDREN` (defaults to `40`): the maximum number of PHP FPM children to spawn.
6969
* `DJ_SKIP_MAKE` (defaults to `0`): set to `1` to skip the maintainer setup and install commands. This will speed up the startup process of the container and is useful if this is already done before.
70+
* `DEFAULTWEBSERVER` (defaults to `nginx`): set to `apache2` to use the Apache2 httpd server as default webserver.
7071

7172
#### Passwords through files
7273

@@ -97,6 +98,8 @@ If you have named your container something other than `domjudge`, be sure to cha
9798

9899
The following commands are available:
99100

101+
* `apache2-access-log`: tail the access log of apache2.
102+
* `apache2-error-log`: tail the error log of apache2.
100103
* `nginx-access-log`: tail the access log of nginx.
101104
* `nginx-error-log`: tail the error log of nginx.
102105
* `judgedaemon-log 0` and `judgedaemon-log 1`: tail the log of the first / second judgeaemon.
@@ -105,6 +108,7 @@ The following commands are available:
105108
* `xdebug-enable`: enable Xdebug debugging. See note below
106109
* `xdebug-disable`: disable Xdebug debugging. See note below
107110
* `switch-php <version>`: switch to using the given PHP version.
111+
* `switch-webserver <apache2|nginx>`: switch to using the given webserver.
108112

109113
Of course, you can always run `docker exec -it domjudge bash` to get a bash shell inside the container.
110114

@@ -114,7 +118,7 @@ To restart any of the services, run the following:
114118
docker exec -it domjudge supervisorctl restart [service]
115119
```
116120

117-
where `[service]` is one of `nginx`, `php`, `judgedaemon0` or `judgedaemon1`.
121+
where `[service]` is one of `apache2`, `nginx`, `php`, `judgedaemon0` or `judgedaemon1`.
118122

119123
### Xdebug
120124

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
supervisorctl tail -f apache2
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
supervisorctl tail -f apache2 stderr
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
WEBSERVER=$1
3+
if [ "${WEBSERVER}" = "nginx" ]
4+
then
5+
sudo supervisorctl stop apache2
6+
sudo supervisorctl start nginx
7+
elif [ "${WEBSERVER}" = "apache2" ]
8+
then
9+
sudo supervisorctl stop nginx
10+
sudo supervisorctl start apache2
11+
else
12+
echo "Usage: $0 [apache2|nginx]"
13+
exit 1
14+
fi

docker-contributor/scripts/start.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,23 @@ sudo sed -i '/error_log/d' $NGINX_CONFIG_FILE
149149
# Use debug front controller
150150
sudo sed -i 's/app\.php/app_dev.php/g' $NGINX_CONFIG_FILE
151151
sudo sed -i 's/app\\\.php/app\\_dev.php/g' $NGINX_CONFIG_FILE
152+
153+
# Configure Apache2
154+
APACHE2_CONFIG_FILE=/etc/apache2/conf-available/domjudge.conf
155+
sudo cp etc/apache.conf $APACHE2_CONFIG_FILE
156+
sudo a2enmod proxy_fcgi setenvif rewrite
157+
sudo cp "/etc/apache2/conf-available/php$DEFAULTPHPVERSION-fpm.conf" /etc/apache2/conf-available/php-domjudge-fpm.conf
158+
sudo sed -i 's/proxy:unix:.*|/proxy:unix:\/var\/run\/php-fpm-domjudge.sock|/' /etc/apache2/conf-available/php-domjudge-fpm.conf
159+
sudo a2enconf php-domjudge-fpm domjudge
160+
sudo rm /etc/apache2/sites-enabled/000-default.conf
161+
# Run DOMjudge in root
162+
sudo sed -i '/^#<VirtualHost \*>/,/^#<\/VirtualHost>/ s/#//' $APACHE2_CONFIG_FILE
163+
sudo sed -i 's/^Alias \/domjudge/#Alias \/domjudge/' $APACHE2_CONFIG_FILE
164+
# Run as user and group 'domjudge'
165+
sudo sed -i 's/<VirtualHost \*>/User domjudge\nGroup domjudge\n<VirtualHost \*>/' $APACHE2_CONFIG_FILE
166+
# Redirect logs to stdout/stderr
167+
sudo sed -i 's/<VirtualHost \*>/TransferLog \/dev\/stdout\nErrorLog \/dev\/stderr\n<VirtualHost \*>/' $APACHE2_CONFIG_FILE
168+
152169
# Set up permissions (make sure the script does not stop if this fails, as this will happen on macOS / Windows)
153170
sudo chown domjudge: "${PROJECT_DIR}/webapp/var"
154171
echo "[ok] Webserver config installed"; echo
@@ -176,4 +193,14 @@ echo "[ok] Sudoers configuration added"; echo
176193
sudo sed -i "s|PROJECT_DIR|${PROJECT_DIR}|" /etc/supervisor/conf.d/judgedaemon.conf
177194
sudo sed -i "s|PROJECT_DIR|${PROJECT_DIR}|" /etc/supervisor/conf.d/judgedaemonextra.conf
178195

196+
echo "[..] Configuring default webserver"
197+
if [ "${DEFAULTWEBSERVER}" = "apache2" ] || [ "${DEFAULTWEBSERVER}" = "nginx" ]
198+
then
199+
sudo sed -i "s|autostart=false|autostart=true|" "/etc/supervisor/conf.d/$DEFAULTWEBSERVER.conf"
200+
else
201+
echo "Unsupported webserver '$DEFAULTWEBSERVER'"
202+
exit 1
203+
fi
204+
echo "[ok] Configured default webserver"; echo
205+
179206
exec sudo supervisord -n -c /etc/supervisor/supervisord.conf
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[program:apache2]
2+
command=pidproxy /var/run/apache2/apache2.pid /bin/bash -c "source /etc/apache2/envvars && apache2ctl -D FOREGROUND"
3+
numprocs=1
4+
autostart=false
5+
autorestart=true
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[program:nginx]
22
command=nginx -g "daemon off;"
33
numprocs=1
4-
autostart=true
4+
autostart=false
55
autorestart=true

0 commit comments

Comments
 (0)