|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +. gitlab/ci_settings.sh |
| 4 | + |
| 5 | +# If this script is called from unit.sh, we use the test environment |
| 6 | +export APP_ENV="${1:-prod}" |
| 7 | + |
| 8 | +# In the test environment, we need to use a different database |
| 9 | +[ "$APP_ENV" = "prod" ] && DATABASE_NAME=domjudge || DATABASE_NAME=domjudge_test |
| 10 | + |
| 11 | +lsb_release -a |
| 12 | + |
| 13 | +# FIXME: This chicken-egg problem is annoying but let us bootstrap for now. |
| 14 | +echo "CREATE DATABASE IF NOT EXISTS \`${DATABASE_NAME}\` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;" | mysql |
| 15 | +echo "CREATE USER 'domjudge'@'%' IDENTIFIED BY 'domjudge';" | mysql |
| 16 | +echo "GRANT SELECT, INSERT, UPDATE, DELETE ON \`${DATABASE_NAME}\`.* TO 'domjudge'@'%';" | mysql |
| 17 | + |
| 18 | +# Increase max_allowed_packet for following connections. |
| 19 | +echo "SET GLOBAL max_allowed_packet = 100*1024*1024;" | mysql |
| 20 | + |
| 21 | +# Test that SQL upgrade scripts also work with this setting |
| 22 | +if [ -n "${MYSQL_REQUIRE_PRIMARY_KEY:-}" ]; then |
| 23 | + echo 'SET GLOBAL sql_require_primary_key = 1;' | mysql |
| 24 | +fi |
| 25 | + |
| 26 | +# Generate a dbpasswords file |
| 27 | +# Note that this does not use ${DATABASE_NAME} since Symfony adds the _test postfix itself |
| 28 | +echo "unused:sqlserver:domjudge:domjudge:domjudge:3306" > etc/dbpasswords.secret |
| 29 | + |
| 30 | +# Generate APP_SECRET for symfony |
| 31 | +# shellcheck disable=SC2164 |
| 32 | +( cd etc ; ./gensymfonysecret > symfony_app.secret ) |
| 33 | + |
| 34 | +cat > webapp/config/static.yaml <<EOF |
| 35 | +parameters: |
| 36 | + domjudge.version: unconfigured |
| 37 | + domjudge.bindir: /bin |
| 38 | + domjudge.etcdir: /etc |
| 39 | + domjudge.wwwdir: /www |
| 40 | + domjudge.webappdir: /webapp |
| 41 | + domjudge.libdir: /lib |
| 42 | + domjudge.sqldir: /sql |
| 43 | + domjudge.vendordir: /webapp/vendor |
| 44 | + domjudge.logdir: /output/log |
| 45 | + domjudge.rundir: /output/run |
| 46 | + domjudge.tmpdir: /output/tmp |
| 47 | + domjudge.baseurl: http://localhost/domjudge |
| 48 | +EOF |
| 49 | + |
| 50 | +# Composer steps |
| 51 | +cd webapp |
| 52 | +# install check if the cache might be dirty |
| 53 | +set +e |
| 54 | +composer install --no-scripts || rm -rf vendor |
| 55 | +set -e |
| 56 | + |
| 57 | +# setup database and add special user |
| 58 | +# shellcheck disable=SC2164 |
| 59 | +cd /opt/domjudge/domserver |
| 60 | +setfacl -m u:www-data:r etc/restapi.secret etc/initial_admin_password.secret \ |
| 61 | + etc/dbpasswords.secret etc/symfony_app.secret |
| 62 | + |
| 63 | +# configure and restart nginx |
| 64 | +sudo rm -f /etc/nginx/sites-enabled/* |
| 65 | +sudo cp /opt/domjudge/domserver/etc/nginx-conf /etc/nginx/sites-enabled/domjudge |
| 66 | +sudo /usr/sbin/nginx |
| 67 | + |
| 68 | +# configure and restart php-fpm |
| 69 | +# shellcheck disable=SC2154 |
| 70 | +php_version="${version:-}" |
| 71 | +sudo cp /opt/domjudge/domserver/etc/domjudge-fpm.conf "/etc/php/$php_version/fpm/pool.d/domjudge-fpm.conf" |
| 72 | +echo "php_admin_value[date.timezone] = Europe/Amsterdam" | sudo tee -a "/etc/php/$php_version/fpm/pool.d/domjudge-fpm.conf" |
| 73 | +sudo /usr/sbin/php-fpm${php_version} |
| 74 | +echo "date.timezone = Europe/Amsterdam" | sudo tee -a "/etc/php/$php_version/cli/php.ini" |
| 75 | + |
| 76 | +passwd=$(cat etc/initial_admin_password.secret) |
| 77 | +echo "machine localhost login admin password $passwd" >> ~www-data/.netrc |
| 78 | +sudo -Eu www-data bin/dj_setup_database -uroot -p${MYSQL_ROOT_PASSWORD} bare-install |
| 79 | + |
| 80 | +# shellcheck disable=SC2154 |
| 81 | +if [ -n "${integration:-}" ]; then |
| 82 | + # Make sure admin has a team associated to insert submissions as well. |
| 83 | + echo "UPDATE user SET teamid=1 WHERE userid=1;" | mysql domjudge |
| 84 | +elif [ -n "${unit:-}" ]; then |
| 85 | + # Make sure admin has no team associated so we will not insert submissions during unit tests. |
| 86 | + echo "UPDATE user SET teamid=null WHERE userid=1;" | mysql domjudge_test |
| 87 | +fi |
| 88 | + |
| 89 | +sudo -Eu www-data bin/dj_setup_database -uroot -p${MYSQL_ROOT_PASSWORD} install-examples |
0 commit comments