diff --git a/docker-contributor/Dockerfile b/docker-contributor/Dockerfile index 084663ca..3be8a7ce 100644 --- a/docker-contributor/Dockerfile +++ b/docker-contributor/Dockerfile @@ -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 diff --git a/docker-contributor/README.md b/docker-contributor/README.md index cd265fea..41324f83 100644 --- a/docker-contributor/README.md +++ b/docker-contributor/README.md @@ -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. @@ -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 @@ -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. @@ -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 `: switch to using the given PHP version. +* `switch-webserver `: 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. @@ -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 diff --git a/docker-contributor/scripts/bin/apache2-access-log b/docker-contributor/scripts/bin/apache2-access-log new file mode 100644 index 00000000..418d6c1b --- /dev/null +++ b/docker-contributor/scripts/bin/apache2-access-log @@ -0,0 +1,2 @@ +#!/bin/bash +supervisorctl tail -f apache2 diff --git a/docker-contributor/scripts/bin/apache2-error-log b/docker-contributor/scripts/bin/apache2-error-log new file mode 100644 index 00000000..be78e366 --- /dev/null +++ b/docker-contributor/scripts/bin/apache2-error-log @@ -0,0 +1,2 @@ +#!/bin/bash +supervisorctl tail -f apache2 stderr diff --git a/docker-contributor/scripts/bin/switch-webserver b/docker-contributor/scripts/bin/switch-webserver new file mode 100644 index 00000000..7db0184c --- /dev/null +++ b/docker-contributor/scripts/bin/switch-webserver @@ -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 diff --git a/docker-contributor/scripts/start.sh b/docker-contributor/scripts/start.sh index 06e27f5b..e1866cf2 100644 --- a/docker-contributor/scripts/start.sh +++ b/docker-contributor/scripts/start.sh @@ -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>/ 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//User domjudge\nGroup domjudge\n/' $APACHE2_CONFIG_FILE +# Redirect logs to stdout/stderr +sudo sed -i 's//TransferLog \/dev\/stdout\nErrorLog \/dev\/stderr\n/' $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 @@ -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 diff --git a/docker-contributor/supervisor/apache2.conf b/docker-contributor/supervisor/apache2.conf new file mode 100644 index 00000000..cd8eba5d --- /dev/null +++ b/docker-contributor/supervisor/apache2.conf @@ -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 diff --git a/docker-contributor/supervisor/nginx.conf b/docker-contributor/supervisor/nginx.conf index 4ac205a1..efebb34c 100644 --- a/docker-contributor/supervisor/nginx.conf +++ b/docker-contributor/supervisor/nginx.conf @@ -1,5 +1,5 @@ [program:nginx] command=nginx -g "daemon off;" numprocs=1 -autostart=true +autostart=false autorestart=true