Skip to content

Commit

Permalink
Merge branch 'main' into nelmiodoc_copy_as_installing_user
Browse files Browse the repository at this point in the history
  • Loading branch information
vmcj authored Aug 25, 2024
2 parents 570c856 + bdd6ea3 commit cb2c984
Show file tree
Hide file tree
Showing 408 changed files with 26,333 additions and 5,272 deletions.
127 changes: 66 additions & 61 deletions .github/jobs/baseinstall.sh
Original file line number Diff line number Diff line change
@@ -1,54 +1,20 @@
#!/bin/sh

# Functions to annotate the Github actions logs
alias trace_on='set -x'
alias trace_off='{ set +x; } 2>/dev/null'

section_start_internal () {
echo "::group::$1"
trace_on
}

section_end_internal () {
echo "::endgroup::"
trace_on
}

alias section_start='trace_off ; section_start_internal '
alias section_end='trace_off ; section_end_internal '
. .github/jobs/ci_settings.sh

export version="$1"
db=${2:-install}

set -eux

section_start "Update packages"
sudo apt update
section_end

section_start "Install needed packages"
sudo apt install -y acl zip unzip nginx php php-fpm php-gd \
php-cli php-intl php-mbstring php-mysql php-curl php-json \
php-xml php-zip ntp make sudo debootstrap \
libcgroup-dev lsof php-cli php-curl php-json php-xml \
php-zip procps gcc g++ default-jre-headless \
default-jdk-headless ghc fp-compiler autoconf automake bats \
python3-sphinx python3-sphinx-rtd-theme rst2pdf fontconfig \
python3-yaml latexmk curl
section_end

PHPVERSION=$(php -r 'echo PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION."\n";')
export PHPVERSION

section_start "Install composer"
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
HASH="$(wget -q -O - https://composer.github.io/installer.sig)"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
section_end

section_start "Run composer"
export APP_ENV="dev"
composer install --no-scripts
cd webapp
composer install --no-scripts |tee "$ARTIFACTS"/composer_out.txt
cd ..
section_end

section_start "Set simple admin password"
Expand All @@ -58,59 +24,98 @@ section_end

section_start "Install domserver"
make configure
./configure --with-baseurl='https://localhost/domjudge/' --enable-doc-build=no --prefix="/opt/domjudge"
./configure \
--with-baseurl='https://localhost/domjudge/' \
--with-domjudge-user=root \
--enable-doc-build=no \
--enable-judgehost-build=no | tee "$ARTIFACTS"/configure.txt

make domserver
sudo make install-domserver
make install-domserver
section_end

section_start "Explicit start mysql + install DB"
sudo /etc/init.d/mysql start
section_start "SQL settings"
cat > ~/.my.cnf <<EOF
[client]
host=sqlserver
user=root
password=root
EOF
cat ~/.my.cnf

mysql_root "CREATE DATABASE IF NOT EXISTS \`domjudge\` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
mysql_root "CREATE USER IF NOT EXISTS \`domjudge\`@'%' IDENTIFIED BY 'domjudge';"
mysql_root "GRANT SELECT, INSERT, UPDATE, DELETE ON \`domjudge\`.* TO 'domjudge'@'%';"
mysql_root "FLUSH PRIVILEGES;"

# Show some MySQL debugging
mysql_root "show databases"
mysql_root "SELECT CURRENT_USER();"
mysql_root "SELECT USER();"
mysql_root "SELECT user,host FROM mysql.user"
echo "unused:sqlserver:domjudge:domjudge:domjudge:3306" > /opt/domjudge/domserver/etc/dbpasswords.secret
mysql_user "SELECT CURRENT_USER();"
mysql_user "SELECT USER();"
section_end

section_start "Install DOMjudge database"
/opt/domjudge/domserver/bin/dj_setup_database -uroot -proot bare-install
section_end

section_start "Show PHP config"
php -v | tee -a "$ARTIFACTS"/php.txt
php -m | tee -a "$ARTIFACTS"/php.txt
section_end

section_start "Show general config"
printenv | tee -a "$ARTIFACTS"/environment.txt
cp /etc/os-release "$ARTIFACTS"/os-release.txt
cp /proc/cmdline "$ARTIFACTS"/cmdline.txt
section_end

section_start "Setup webserver"
sudo cp /opt/domjudge/domserver/etc/domjudge-fpm.conf /etc/php/$PHPVERSION/fpm/pool.d/domjudge.conf
cp /opt/domjudge/domserver/etc/domjudge-fpm.conf /etc/php/"$PHPVERSION"/fpm/pool.d/domjudge.conf

sudo rm -f /etc/nginx/sites-enabled/*
sudo cp /opt/domjudge/domserver/etc/nginx-conf /etc/nginx/sites-enabled/domjudge
rm -f /etc/nginx/sites-enabled/*
cp /opt/domjudge/domserver/etc/nginx-conf /etc/nginx/sites-enabled/domjudge

openssl req -nodes -new -x509 -keyout /tmp/server.key -out /tmp/server.crt -subj "/C=NL/ST=Noord-Holland/L=Amsterdam/O=TestingForPR/CN=localhost"
sudo cp /tmp/server.crt /usr/local/share/ca-certificates/
sudo update-ca-certificates
cp /tmp/server.crt /usr/local/share/ca-certificates/
update-ca-certificates
# shellcheck disable=SC2002
cat "$(pwd)/.github/jobs/data/nginx_extra" | sudo tee -a /etc/nginx/sites-enabled/domjudge
sudo nginx -t
cat "$(pwd)/.github/jobs/data/nginx_extra" | tee -a /etc/nginx/sites-enabled/domjudge
nginx -t
section_end

section_start "Show webserver is up"
for service in nginx php${PHPVERSION}-fpm; do
sudo systemctl restart $service
sudo systemctl status $service
service "$service" restart
service "$service" status
done
section_end

section_start "Install the example data"
/opt/domjudge/domserver/bin/dj_setup_database -uroot -proot install-examples
section_end
if [ "${db}" = "install" ]; then
section_start "Install the example data"
/opt/domjudge/domserver/bin/dj_setup_database -uroot -proot install-examples | tee -a "$ARTIFACTS/mysql.txt"
section_end
fi

section_start "Setup user"
# We're using the admin user in all possible roles
echo "DELETE FROM userrole WHERE userid=1;" | mysql -uroot -proot domjudge
mysql_root "DELETE FROM userrole WHERE userid=1;" domjudge
if [ "$version" = "team" ]; then
# Add team to admin user
echo "INSERT INTO userrole (userid, roleid) VALUES (1, 3);" | mysql -uroot -proot domjudge
echo "UPDATE user SET teamid = 1 WHERE userid = 1;" | mysql -uroot -proot domjudge
mysql_root "INSERT INTO userrole (userid, roleid) VALUES (1, 3);" domjudge
mysql_root "UPDATE user SET teamid = 1 WHERE userid = 1;" domjudge
elif [ "$version" = "jury" ]; then
# Add jury to admin user
echo "INSERT INTO userrole (userid, roleid) VALUES (1, 2);" | mysql -uroot -proot domjudge
mysql_root "INSERT INTO userrole (userid, roleid) VALUES (1, 2);" domjudge
elif [ "$version" = "balloon" ]; then
# Add balloon to admin user
echo "INSERT INTO userrole (userid, roleid) VALUES (1, 4);" | mysql -uroot -proot domjudge
mysql_root "INSERT INTO userrole (userid, roleid) VALUES (1, 4);" domjudge
elif [ "$version" = "admin" ]; then
# Add admin to admin user
echo "INSERT INTO userrole (userid, roleid) VALUES (1, 1);" | mysql -uroot -proot domjudge
mysql_root "INSERT INTO userrole (userid, roleid) VALUES (1, 1);" domjudge
fi
section_end

49 changes: 49 additions & 0 deletions .github/jobs/ci_settings.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/sh

# Store artifacts/logs
export ARTIFACTS="/tmp/artifacts"
mkdir -p "$ARTIFACTS"

# Functions to annotate the Github actions logs
trace_on () {
set -x
}
trace_off () {
{
set +x
} 2>/dev/null
}

section_start_internal () {
echo "::group::$1"
trace_on
}

section_end_internal () {
echo "::endgroup::"
trace_on
}

mysql_root () {
# shellcheck disable=SC2086
echo "$1" | mysql -uroot -proot ${2:-} | tee -a "$ARTIFACTS"/mysql.txt
}

mysql_user () {
# shellcheck disable=SC2086
echo "$1" | mysql -udomjudge -pdomjudge ${2:-} | tee -a "$ARTIFACTS"/mysql.txt
}

section_start () {
if [ "$#" -ne 1 ]; then
echo "Only 1 argument is needed for GHA, 2 was needed for GitLab."
exit 1
fi
trace_off
section_start_internal "$1"
}

section_end () {
trace_off
section_end_internal
}
16 changes: 16 additions & 0 deletions .github/jobs/composer_setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh

set -eux

. .github/jobs/ci_settings.sh

section_start "Configure PHP"
PHPVERSION=$(php -r 'echo PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION."\n";')
export PHPVERSION
echo "$PHPVERSION" | tee -a "$ARTIFACTS"/phpversion.txt
section_end

section_start "Run composer"
cd webapp
composer install --no-scripts 2>&1 | tee -a "$ARTIFACTS/composer_log.txt"
section_end
25 changes: 3 additions & 22 deletions .github/jobs/configure-checks/all.bats
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ setup() {
if [ "$distro_id" = "ID=fedora" ]; then
repo-install httpd
fi
repo-install gcc g++ libcgroup-dev
repo-install gcc g++ libcgroup-dev composer
}

run_configure () {
Expand Down Expand Up @@ -129,14 +129,6 @@ compile_assertions_finished () {
compile_assertions_finished
}

@test "Install GNU C/C++ compilers" {
# The test above already does this
# repo-remove clang
# repo-install gcc g++ libcgroup-dev
# compiler_assertions
# compile_assertions_finished
}

@test "Install C/C++ compilers (Clang as alternative)" {
if [ "$distro_id" = "ID=fedora" ]; then
# Fedora has gcc as dependency for clang
Expand Down Expand Up @@ -239,7 +231,6 @@ compile_assertions_finished () {
assert_line " - bin..............: /opt/domjudge/domserver/bin"
assert_line " - etc..............: /opt/domjudge/domserver/etc"
assert_line " - lib..............: /opt/domjudge/domserver/lib"
assert_line " - libvendor........: /opt/domjudge/domserver/lib/vendor"
assert_line " - log..............: /opt/domjudge/domserver/log"
assert_line " - run..............: /opt/domjudge/domserver/run"
assert_line " - sql..............: /opt/domjudge/domserver/sql"
Expand All @@ -256,7 +247,6 @@ compile_assertions_finished () {
assert_line " - tmp..............: /opt/domjudge/judgehost/tmp"
assert_line " - judge............: /opt/domjudge/judgehost/judgings"
assert_line " - chroot...........: /chroot/domjudge"
assert_line " - cgroup...........: /sys/fs/cgroup"
}

@test "Prefix configured" {
Expand All @@ -266,7 +256,6 @@ compile_assertions_finished () {
refute_line " * documentation.......: /opt/domjudge/doc"
refute_line " * domserver...........: /opt/domjudge/domserver"
refute_line " - bin..............: /opt/domjudge/domserver/bin"
refute_line " - libvendor........: /opt/domjudge/domserver/lib/vendor"
refute_line " - tmp..............: /opt/domjudge/domserver/tmp"
refute_line " - example_problems.: /opt/domjudge/domserver/example_problems"
refute_line " * judgehost...........: /opt/domjudge/judgehost"
Expand All @@ -278,7 +267,6 @@ compile_assertions_finished () {
assert_line " * prefix..............: /tmp"
assert_line " * documentation.......: /tmp/doc"
assert_line " * domserver...........: /tmp/domserver"
assert_line " - libvendor........: /tmp/domserver/lib/vendor"
assert_line " * judgehost...........: /tmp/judgehost"
assert_line " - judge............: /tmp/judgehost/judgings"
}
Expand All @@ -300,7 +288,6 @@ compile_assertions_finished () {
assert_line " - bin..............: /usr/local/bin"
assert_line " - etc..............: /usr/local/etc/domjudge"
assert_line " - lib..............: /usr/local/lib/domjudge"
assert_line " - libvendor........: /usr/local/lib/domjudge/vendor"
assert_line " - log..............: /usr/local/var/log/domjudge"
assert_line " - run..............: /usr/local/var/run/domjudge"
assert_line " - sql..............: /usr/local/share/domjudge/sql"
Expand All @@ -317,19 +304,17 @@ compile_assertions_finished () {
assert_line " - tmp..............: /tmp"
assert_line " - judge............: /usr/local/var/lib/domjudge/judgings"
assert_line " - chroot...........: /chroot/domjudge"
assert_line " - cgroup...........: /sys/fs/cgroup"
}

@test "Alternative dirs together with FHS" {
setup
run run_configure --enable-fhs --with-domserver_webappdir=/run/webapp --with-domserver_tmpdir=/tmp/domserver --with-judgehost_tmpdir=/srv/tmp --with-judgehost_judgedir=/srv/judgings --with-judgehost_chrootdir=/srv/chroot/domjudge --with-judgehost_cgroupdir=/sys/fs/altcgroup
run run_configure --enable-fhs --with-domserver_webappdir=/run/webapp --with-domserver_tmpdir=/tmp/domserver --with-judgehost_tmpdir=/srv/tmp --with-judgehost_judgedir=/srv/judgings --with-judgehost_chrootdir=/srv/chroot/domjudge
assert_line " * prefix..............: /usr/local"
assert_line " * documentation.......: /usr/local/share/doc/domjudge"
assert_line " * domserver...........: "
assert_line " - bin..............: /usr/local/bin"
assert_line " - etc..............: /usr/local/etc/domjudge"
assert_line " - lib..............: /usr/local/lib/domjudge"
assert_line " - libvendor........: /usr/local/lib/domjudge/vendor"
assert_line " - log..............: /usr/local/var/log/domjudge"
assert_line " - run..............: /usr/local/var/run/domjudge"
assert_line " - sql..............: /usr/local/share/domjudge/sql"
Expand All @@ -351,13 +336,11 @@ compile_assertions_finished () {
assert_line " - judge............: /srv/judgings"
refute_line " - chroot...........: /chroot/domjudge"
assert_line " - chroot...........: /srv/chroot/domjudge"
refute_line " - cgroup...........: /sys/fs/cgroup"
assert_line " - cgroup...........: /sys/fs/altcgroup"
}

@test "Alternative dirs together with defaults" {
setup
run run_configure "--with-judgehost_tmpdir=/srv/tmp --with-judgehost_judgedir=/srv/judgings --with-judgehost_chrootdir=/srv/chroot --with-judgehost_cgroupdir=/sys/fs/altcgroup --with-domserver_logdir=/log"
run run_configure "--with-judgehost_tmpdir=/srv/tmp --with-judgehost_judgedir=/srv/judgings --with-judgehost_chrootdir=/srv/chroot --with-domserver_logdir=/log"
assert_line " * prefix..............: /opt/domjudge"
assert_line " * documentation.......: /opt/domjudge/doc"
assert_line " * domserver...........: /opt/domjudge/domserver"
Expand All @@ -370,8 +353,6 @@ compile_assertions_finished () {
assert_line " - judge............: /srv/judgings"
refute_line " - chroot...........: /chroot/domjudge"
assert_line " - chroot...........: /srv/chroot"
refute_line " - cgroup...........: /sys/fs/cgroup"
assert_line " - cgroup...........: /sys/fs/altcgroup"
}

@test "Default URL not set, docs mention" {
Expand Down
3 changes: 2 additions & 1 deletion .github/jobs/data/codespellignorefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
./config.guess
./gitlab/codespell.yml
./.github/jobs/uploadcodecov.sh
./lib/vendor
./webapp/vendor
./webapp/public/bundles
./webapp/public/js/ace
./webapp/templates/bundles
Expand All @@ -26,3 +26,4 @@ nv.d3.min*
composer*
./doc/logos
./m4
./webapp/tests/Unit/Fixtures
9 changes: 9 additions & 0 deletions .github/jobs/pa11y_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"chromeLaunchConfig": {
"args": [
"--no-sandbox",
"--disable-setuid-sandbox",
"--disable-dev-shm-usage"
]
}
}
Loading

0 comments on commit cb2c984

Please sign in to comment.