Skip to content

Commit

Permalink
Add Apache2 configuration to docker-contributor
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Kevinjil committed Oct 21, 2024
1 parent 4983ddc commit 6283816
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 3 deletions.
1 change: 1 addition & 0 deletions docker-contributor/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ ENV DEBIAN_FRONTEND=noninteractive \
DJ_DB_INSTALL_BARE=0 \
PHPSUPPORTED="8.1 8.2 8.3" \
DEFAULTPHPVERSION="8.3" \
DEFAULTWEBSERVER="nginx" \
APTINSTALL="apt-get install -y -o Dpkg::Options::=--force-confdef -o Dpkg::Options::=--force-confold"

# Install required packages and clean up afterwards to make this image layer smaller
Expand Down
8 changes: 6 additions & 2 deletions docker-contributor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The container includes the following:
* Set up or update the database.
* Set up the webserver.
* Create a chroot.
* PHP-FPM and nginx for running the web interface.
* PHP-FPM and apache2 or nginx for running the web interface.
* Two running judgedaemons using a chroot.
* Scripts for reading the log files of the webserver and the judgedaemons.
* A script to create a dummy DOMjudge user and submit all test submissions.
Expand Down Expand Up @@ -67,6 +67,7 @@ The following environment variables are supported by the container:
* `MYSQL_DATABASE` (defaults to `domjudge`): set the database to use.
* `FPM_MAX_CHILDREN` (defaults to `40`): the maximum number of PHP FPM children to spawn.
* `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.
* `DEFAULTWEBSERVER` (defaults to `nginx`): set to `apache2` to use the Apache2 httpd server as default webserver.

#### Passwords through files

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

The following commands are available:

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

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

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

where `[service]` is one of `nginx`, `php`, `judgedaemon0` or `judgedaemon1`.
where `[service]` is one of `apache2`, `nginx`, `php`, `judgedaemon0` or `judgedaemon1`.

### Xdebug

Expand Down
2 changes: 2 additions & 0 deletions docker-contributor/scripts/bin/apache2-access-log
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
supervisorctl tail -f apache2
2 changes: 2 additions & 0 deletions docker-contributor/scripts/bin/apache2-error-log
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
supervisorctl tail -f apache2 stderr
14 changes: 14 additions & 0 deletions docker-contributor/scripts/bin/switch-webserver
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
WEBSERVER=$1
if [ "${WEBSERVER}" = "nginx" ]
then
sudo supervisorctl stop apache2
sudo supervisorctl start nginx
elif [ "${WEBSERVER}" = "apache2" ]
then
sudo supervisorctl stop nginx
sudo supervisorctl start apache2
else
echo "Usage: $0 [apache2|nginx]"
exit 1
fi
27 changes: 27 additions & 0 deletions docker-contributor/scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,23 @@ sudo sed -i '/error_log/d' $NGINX_CONFIG_FILE
# Use debug front controller
sudo sed -i 's/app\.php/app_dev.php/g' $NGINX_CONFIG_FILE
sudo sed -i 's/app\\\.php/app\\_dev.php/g' $NGINX_CONFIG_FILE

# Configure Apache2
APACHE2_CONFIG_FILE=/etc/apache2/conf-available/domjudge.conf
sudo cp etc/apache.conf $APACHE2_CONFIG_FILE
sudo a2enmod proxy_fcgi setenvif rewrite
sudo cp "/etc/apache2/conf-available/php$DEFAULTPHPVERSION-fpm.conf" /etc/apache2/conf-available/php-domjudge-fpm.conf
sudo sed -i 's/proxy:unix:.*|/proxy:unix:\/var\/run\/php-fpm-domjudge.sock|/' /etc/apache2/conf-available/php-domjudge-fpm.conf
sudo a2enconf php-domjudge-fpm domjudge
sudo rm /etc/apache2/sites-enabled/000-default.conf
# Run DOMjudge in root
sudo sed -i '/^#<VirtualHost \*>/,/^#<\/VirtualHost>/ s/#//' $APACHE2_CONFIG_FILE
sudo sed -i 's/^Alias \/domjudge/#Alias \/domjudge/' $APACHE2_CONFIG_FILE
# Run as user and group 'domjudge'
sudo sed -i 's/<VirtualHost \*>/User domjudge\nGroup domjudge\n<VirtualHost \*>/' $APACHE2_CONFIG_FILE
# Redirect logs to stdout/stderr
sudo sed -i 's/<VirtualHost \*>/TransferLog \/dev\/stdout\nErrorLog \/dev\/stderr\n<VirtualHost \*>/' $APACHE2_CONFIG_FILE

# Set up permissions (make sure the script does not stop if this fails, as this will happen on macOS / Windows)
sudo chown domjudge: "${PROJECT_DIR}/webapp/var"
echo "[ok] Webserver config installed"; echo
Expand Down Expand Up @@ -176,4 +193,14 @@ echo "[ok] Sudoers configuration added"; echo
sudo sed -i "s|PROJECT_DIR|${PROJECT_DIR}|" /etc/supervisor/conf.d/judgedaemon.conf
sudo sed -i "s|PROJECT_DIR|${PROJECT_DIR}|" /etc/supervisor/conf.d/judgedaemonextra.conf

echo "[..] Configuring default webserver"
if [ "${DEFAULTWEBSERVER}" = "apache2" ] || [ "${DEFAULTWEBSERVER}" = "nginx" ]
then
sudo sed -i "s|autostart=false|autostart=true|" "/etc/supervisor/conf.d/$DEFAULTWEBSERVER.conf"
else
echo "Unsupported webserver '$DEFAULTWEBSERVER'"
exit 1
fi
echo "[ok] Configured default webserver"; echo

exec sudo supervisord -n -c /etc/supervisor/supervisord.conf
5 changes: 5 additions & 0 deletions docker-contributor/supervisor/apache2.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[program:apache2]
command=pidproxy /var/run/apache2/apache2.pid /bin/bash -c "source /etc/apache2/envvars && apache2ctl -D FOREGROUND"
numprocs=1
autostart=false
autorestart=true
2 changes: 1 addition & 1 deletion docker-contributor/supervisor/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[program:nginx]
command=nginx -g "daemon off;"
numprocs=1
autostart=true
autostart=false
autorestart=true

0 comments on commit 6283816

Please sign in to comment.