From 1e740bd27997d288faf97949e0f970eb6a01f17e Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Wed, 30 Mar 2022 09:12:41 +0200 Subject: [PATCH 01/27] Add docker workflow --- .github/workflows/build_and_push_docker.yml | 83 +++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 .github/workflows/build_and_push_docker.yml diff --git a/.github/workflows/build_and_push_docker.yml b/.github/workflows/build_and_push_docker.yml new file mode 100644 index 00000000..b8b5cbb2 --- /dev/null +++ b/.github/workflows/build_and_push_docker.yml @@ -0,0 +1,83 @@ +name: 'Build version' + +on: + push: + branches: + - master + workflow_dispatch: + inputs: + version: + required: true + +env: + REGISTRY: ghcr.io + REPO_NAME: ${{ github.repository }} + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: "Checkout Repository" + uses: actions/checkout@v2 + - name: Explain why this job ran + run: echo "The ${{ github.event_name }} event triggered this step." + + - name: Get latest version + if: "${{ github.event.inputs.version == '' || github.event.inputs.version == 'latest' }}" + run: echo "version_to_build=$(curl -s https://api.github.com/repos/DOMjudge/domjudge/git/refs/tags | jq 'reverse | ((.[].ref) / "refs/tags/" )[1]' | rev | cut -c2- | rev | cut -c2- | head -n 1)" >> $GITHUB_ENV + - name: Store input version + if: "${{ github.event.inputs.version != '' && github.event.inputs.version != 'latest' }}" + run: echo "version_to_build=${{ github.event.inputs.version }}" >> $GITHUB_ENV + - name: Print version + run: echo "${{ env.version_to_build }}" + - name: Check valid version + run: curl -s https://api.github.com/repos/DOMjudge/domjudge/git/refs/tags | jq 'reverse | ((.[].ref) / "refs/tags/" )[1]' | rev | cut -c2- | rev | cut -c2- | grep -Fxq ${{ env.version_to_build }} + - name: Set flag for latest + run: | + if [[ "${{ env.version_to_build }}" == "$(curl -s https://api.github.com/repos/DOMjudge/domjudge/git/refs/tags | jq 'reverse | ((.[].ref) / "refs/tags/" )[1]' | rev | cut -c2- | rev | cut -c2- | head -n 1)" ]]; then + echo "latest=true" >> $GITHUB_ENV + echo "latest set to true" + else + echo "latest=false" >> $GITHUB_ENV + echo "latest set to false" + fi + - name: Repo name + run: echo "IMAGE_ID=$(echo ${{ env.REGISTRY }}/${{ env.REPO_NAME }} | tr '[A-Z]' '[a-z]')" >> $GITHUB_ENV + + - name: Build containers + working-directory: ./docker + run: ./build.sh ${{ env.version_to_build }} + + - name: Add tags + run: | + docker tag domjudge/domserver:${{ env.version_to_build }} ${{ env.IMAGE_ID }}/domserver:${{ env.version_to_build }} + docker tag domjudge/judgehost:${{ env.version_to_build }} ${{ env.IMAGE_ID }}/judgehost:${{ env.version_to_build }} + docker tag domjudge/default-judgehost-chroot:${{ env.version_to_build }} ${{ env.IMAGE_ID }}/default-judgehost-chroot:${{ env.version_to_build }} + + - name: Add latest tags + if: ${{ env.latest == 'true' }} + run: | + docker tag domjudge/domserver:${{ env.version_to_build }} ${{ env.IMAGE_ID }}/domserver:latest + docker tag domjudge/judgehost:${{ env.version_to_build }} ${{ env.IMAGE_ID }}/judgehost:latest + docker tag domjudge/default-judgehost-chroot:${{ env.version_to_build }} ${{ env.IMAGE_ID }}/default-judgehost-chroot:latest + + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Push image + run: | + docker push ${{ env.IMAGE_ID }}/domserver:${{ env.version_to_build }} + docker push ${{ env.IMAGE_ID }}/judgehost:${{ env.version_to_build }} + docker push ${{ env.IMAGE_ID }}/default-judgehost-chroot:${{ env.version_to_build }} + + - name: Push latest + if: ${{ env.latest == 'true' }} + run: | + docker push ${{ env.IMAGE_ID }}/domserver:latest + docker push ${{ env.IMAGE_ID }}/judgehost:latest + docker push ${{ env.IMAGE_ID }}/default-judgehost-chroot:latest From a930ce5c3a731f878275ae33d1b3ba2540ace7a3 Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Thu, 14 Apr 2022 16:09:05 +0200 Subject: [PATCH 02/27] Change baseurl to chipcie url --- docker/domserver/build.sh | 2 +- docker/judgehost/build.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/domserver/build.sh b/docker/domserver/build.sh index 8b3c771f..cf660477 100755 --- a/docker/domserver/build.sh +++ b/docker/domserver/build.sh @@ -4,7 +4,7 @@ cd /domjudge-src/domjudge* chown -R domjudge: . # If we used a local source tarball, it might not have been built yet sudo -u domjudge make dist -sudo -u domjudge ./configure -with-baseurl=http://localhost/ +sudo -u domjudge ./configure -with-baseurl=http://dj.chipcie.ch.tudelft.nl/ # Passwords should not be included in the built image. We create empty files here to prevent passwords from being generated. sudo -u domjudge touch etc/dbpasswords.secret etc/restapi.secret etc/symfony_app.secret etc/initial_admin_password.secret diff --git a/docker/judgehost/build.sh b/docker/judgehost/build.sh index ad81dbac..670f3f5b 100755 --- a/docker/judgehost/build.sh +++ b/docker/judgehost/build.sh @@ -4,7 +4,7 @@ cd /domjudge-src/domjudge* chown -R domjudge: . # If we used a local source tarball, it might not have been built yet sudo -u domjudge make configure -sudo -u domjudge ./configure -with-baseurl=http://localhost/ +sudo -u domjudge ./configure -with-baseurl=http://dj.chipcie.ch.tudelft.nl/ echo "default http://localhost/api dummy dummy" | sudo -u domjudge tee etc/restapi.secret > /dev/null From b2c3ef339d24db2ebdb9baf466761666628c593f Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Sun, 24 Apr 2022 10:21:22 +0200 Subject: [PATCH 03/27] Add support for printer --- docker/domserver/Dockerfile | 3 ++- docker/domserver/scripts/bin/set_printer | 26 ++++++++++++++++++++ docker/domserver/scripts/start.d/20-cupsd.sh | 19 ++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 docker/domserver/scripts/bin/set_printer create mode 100755 docker/domserver/scripts/start.d/20-cupsd.sh diff --git a/docker/domserver/Dockerfile b/docker/domserver/Dockerfile index 9a9233aa..59c0ff07 100644 --- a/docker/domserver/Dockerfile +++ b/docker/domserver/Dockerfile @@ -58,7 +58,8 @@ RUN apt update \ nginx php-cli php-fpm php-zip \ php-gd php-curl php-mysql php-json php-intl \ php-gmp php-xml php-mbstring php-ldap \ - enscript lpr \ + enscript \ + printer-driver-all cups cups-pdf cups-client cups-bsd cups-filters \ ca-certificates python3-yaml \ && rm -rf /var/lib/apt/lists/* diff --git a/docker/domserver/scripts/bin/set_printer b/docker/domserver/scripts/bin/set_printer new file mode 100644 index 00000000..cf53e1f9 --- /dev/null +++ b/docker/domserver/scripts/bin/set_printer @@ -0,0 +1,26 @@ +#!/bin/bash +printerIP=$1 + +if [[ ! $printerIP =~ "://" ]]; then + printerIP="socket://$printerIP" +fi + +# Clear out all old printers +for PRINTER in $(lpstat -v 2>/dev/null| cut -d ' ' -f 3 | tr -d ':') +do + lpadmin -x $PRINTER +done +lpadmin -x ContestPrinter > /dev/null 2>&1 + +lpadmin -p Printer0 -v $printerIP -E +lpadmin -p Printer0 -c ContestPrinter +cupsenable Printer0 +cupsaccept Printer0 + +# Check if we have any printers present, if so make sure we enable the class and set it as default +lpstat -v 2>/dev/null | grep Printer0 >/dev/null 2>&1 +if [ $? -eq 0 ]; then + lpadmin -d ContestPrinter + cupsenable ContestPrinter + cupsaccept ContestPrinter +fi diff --git a/docker/domserver/scripts/start.d/20-cupsd.sh b/docker/domserver/scripts/start.d/20-cupsd.sh new file mode 100755 index 00000000..1345aa45 --- /dev/null +++ b/docker/domserver/scripts/start.d/20-cupsd.sh @@ -0,0 +1,19 @@ +#!/bin/bash -e + +function file_or_env { + file=${1}_FILE + if [ -n "${!file}" ]; then + cat "${!file}" + else + echo -n "${!1}" + fi +} + +PRINTER_URL=$(file_or_env PRINTER_URL) + +/usr/sbin/cupsd + +if [ -n "$PRINTER_URL" ]; then + echo "Setting contest printer to $PRINTER_URL" + set_printer $PRINTER_URL +fi From 2c536de282baabe4f1b0957654f650a8a39d3d57 Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Mon, 13 Jun 2022 22:10:59 +0200 Subject: [PATCH 04/27] Fix building judgehost in github workflow --- .github/workflows/build_and_push_docker.yml | 31 +++++++++++++++++---- docker/build-judgehost.sh | 2 +- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build_and_push_docker.yml b/.github/workflows/build_and_push_docker.yml index b8b5cbb2..30f20154 100644 --- a/.github/workflows/build_and_push_docker.yml +++ b/.github/workflows/build_and_push_docker.yml @@ -16,12 +16,30 @@ env: jobs: build: runs-on: ubuntu-latest - steps: - - name: "Checkout Repository" + - name: Checkout uses: actions/checkout@v2 - - name: Explain why this job ran - run: echo "The ${{ github.event_name }} event triggered this step." + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + with: + image: tonistiigi/binfmt:latest + platforms: all + + - name: Available platforms + run: echo ${{ steps.qemu.outputs.platforms }} + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + + - name: Inspect builder + run: | + echo "Name: ${{ steps.buildx.outputs.name }}" + echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}" + echo "Status: ${{ steps.buildx.outputs.status }}" + echo "Flags: ${{ steps.buildx.outputs.flags }}" + echo "Platforms: ${{ steps.buildx.outputs.platforms }}" - name: Get latest version if: "${{ github.event.inputs.version == '' || github.event.inputs.version == 'latest' }}" @@ -46,8 +64,9 @@ jobs: run: echo "IMAGE_ID=$(echo ${{ env.REGISTRY }}/${{ env.REPO_NAME }} | tr '[A-Z]' '[a-z]')" >> $GITHUB_ENV - name: Build containers - working-directory: ./docker - run: ./build.sh ${{ env.version_to_build }} + run: | + cd ./docker + sudo bash -e build.sh ${{ env.version_to_build }} - name: Add tags run: | diff --git a/docker/build-judgehost.sh b/docker/build-judgehost.sh index 2be3f9f5..3139f1a4 100755 --- a/docker/build-judgehost.sh +++ b/docker/build-judgehost.sh @@ -12,7 +12,7 @@ docker build -t "${docker_tag}-build" -f judgehost/Dockerfile.build . # Build chroot builder_name=$(echo "${docker_tag}" | sed 's/[^a-zA-Z0-9\-_]/-/g') docker rm -f "${builder_name}" > /dev/null 2>&1 || true -docker run --name "${builder_name}" --cap-add=sys_admin "${docker_tag}-build" +docker run --privileged --name "${builder_name}" --cap-add=sys_admin "${docker_tag}-build" docker cp "${builder_name}:/chroot.tar.gz" . docker cp "${builder_name}:/judgehost.tar.gz" . docker rm -f "${builder_name}" From d62ec69dc4b9ab83aa878fff8fb4f58e57c7d413 Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Sat, 18 Jun 2022 18:55:30 +0200 Subject: [PATCH 05/27] Add patches to change defualt config --- docker/domserver/Dockerfile | 5 ++++ .../scripts/patches.d/10-default-config.py | 24 +++++++++++++++++++ docker/domserver/scripts/patches.sh | 14 +++++++++++ 3 files changed, 43 insertions(+) create mode 100755 docker/domserver/scripts/patches.d/10-default-config.py create mode 100644 docker/domserver/scripts/patches.sh diff --git a/docker/domserver/Dockerfile b/docker/domserver/Dockerfile index 59c0ff07..d94ab6d2 100644 --- a/docker/domserver/Dockerfile +++ b/docker/domserver/Dockerfile @@ -34,6 +34,11 @@ RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \ ADD domjudge.tar.gz /domjudge-src COPY domserver/build.sh /domjudge-src/build.sh +# Apply patches +COPY domserver/scripts/patches.sh /scripts/patches.sh +COPY domserver/scripts/patches.d /scripts/patches.d +RUN chmod 700 /scripts/patches.sh && /scripts/patches.sh + # Build and install domserver RUN /domjudge-src/build.sh diff --git a/docker/domserver/scripts/patches.d/10-default-config.py b/docker/domserver/scripts/patches.d/10-default-config.py new file mode 100755 index 00000000..e0c0abde --- /dev/null +++ b/docker/domserver/scripts/patches.d/10-default-config.py @@ -0,0 +1,24 @@ +#!/usr/bin/python3 + +import yaml +import pathlib + +dj_source = next(pathlib.Path("/domjudge-src").glob("domjudge*")) +config = dj_source / "etc/db-config.yaml" + +with open(config) as f: + list_doc = yaml.safe_load(f) + +for category in list_doc: + if category["category"] == "Authentication": + for item in category["items"]: + if item["name"] == "auth_methods": + item["default_value"].append("xheaders") + + if category["category"] == "External systems": + for item in category["items"]: + if item["name"] == "print_command": + item["default_value"] = "/usr/bin/enscript --columns=2 --pages=-10 --landscape --pretty-print \"--header='[original]'; page $% of $=; time=$C; room='[location]'; team='[teamname]'\" [file]" + +with open(config, "w") as f: + yaml.dump(list_doc, f) diff --git a/docker/domserver/scripts/patches.sh b/docker/domserver/scripts/patches.sh new file mode 100644 index 00000000..85a9d6b1 --- /dev/null +++ b/docker/domserver/scripts/patches.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +for i in /scripts/patches.d/* +do + if [ -x "$i" ] + then + echo "[..] Running patch script" "$(basename "$i")" + if ! "$i" + then + echo "[!!] Start patch" "$(basename "$i")" "failed" + exit 1 + fi + fi +done From 548e37c9cf03dc7fdd39f6ec1301035080d73f69 Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Sat, 18 Jun 2022 18:55:55 +0200 Subject: [PATCH 06/27] Add patch to source kotlin in the kotlin run file --- .../scripts/patches.d/20-kotlin-login-shell.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 docker/domserver/scripts/patches.d/20-kotlin-login-shell.py diff --git a/docker/domserver/scripts/patches.d/20-kotlin-login-shell.py b/docker/domserver/scripts/patches.d/20-kotlin-login-shell.py new file mode 100755 index 00000000..aa454ba9 --- /dev/null +++ b/docker/domserver/scripts/patches.d/20-kotlin-login-shell.py @@ -0,0 +1,17 @@ +#!/usr/bin/python3 + +import pathlib + +# dj_source = next(pathlib.Path("/domjudge-src").glob("domjudge*")) +# kt_run = dj_source / "sql/files/defaultdata/kt/run" +kt_run = pathlib.Path("run") + +with open(kt_run) as f: + lines = f.readlines() + +for i in range(len(lines)): + if lines[i] == "#!/bin/sh\n": + lines[i] = lines[i] + ". /etc/profile.d/kotlin.sh\n" + +with open(kt_run, "w") as f: + f.writelines(lines) From 97c4c95e02a9b77b091966b01b66cb4ed28e23ba Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Sat, 18 Jun 2022 18:57:32 +0200 Subject: [PATCH 07/27] Add script to add more repositories --- docker/judgehost/Dockerfile | 2 ++ docker/judgehost/Dockerfile.build | 2 ++ docker/judgehost/add_repositories.sh | 8 ++++++++ docker/judgehost/chroot-and-tar.sh | 2 ++ 4 files changed, 14 insertions(+) create mode 100644 docker/judgehost/add_repositories.sh diff --git a/docker/judgehost/Dockerfile b/docker/judgehost/Dockerfile index c92ea072..4ccc6e88 100644 --- a/docker/judgehost/Dockerfile +++ b/docker/judgehost/Dockerfile @@ -20,6 +20,8 @@ RUN apt update \ gcc g++ default-jre-headless default-jdk ghc fp-compiler \ && rm -rf /var/lib/apt/lists/* +COPY judgehost/add_repositories.sh /add_repositories.sh +RUN chmod 700 /add_repositories.sh && /add_repositories.sh && rm -f /add_repositories.sh # Add chroot and judgehost data ADD chroot.tar.gz / ADD judgehost.tar.gz / diff --git a/docker/judgehost/Dockerfile.build b/docker/judgehost/Dockerfile.build index b822b8cc..45b8386e 100644 --- a/docker/judgehost/Dockerfile.build +++ b/docker/judgehost/Dockerfile.build @@ -3,6 +3,8 @@ LABEL org.opencontainers.image.authors="DOMjudge team " ENV DEBIAN_FRONTEND=noninteractive +COPY judgehost/add_repositories.sh /scripts/add_repositories.sh + # Install required packages for build of judgehost RUN apt update \ && apt install --no-install-recommends --no-install-suggests -y \ diff --git a/docker/judgehost/add_repositories.sh b/docker/judgehost/add_repositories.sh new file mode 100644 index 00000000..ed5aff52 --- /dev/null +++ b/docker/judgehost/add_repositories.sh @@ -0,0 +1,8 @@ +apt-get update +apt-get install software-properties-common gnupg + +echo "deb [trusted=yes] https://pc2.ecs.baylor.edu/apt focal main" >> /etc/apt/sources.list +echo 'Acquire::https::pc2.ecs.baylor.edu::Verify-Peer "false"; +Acquire::https::pc2.ecs.baylor.edu::Verify-Host "false";' >> /etc/apt/apt.conf.d/80trust-baylor-mirror + +apt-get update diff --git a/docker/judgehost/chroot-and-tar.sh b/docker/judgehost/chroot-and-tar.sh index 15a00394..8d5df753 100755 --- a/docker/judgehost/chroot-and-tar.sh +++ b/docker/judgehost/chroot-and-tar.sh @@ -1,5 +1,7 @@ #!/bin/bash +sed -i.bak '/# Upgrade the system, and install\/remove packages as desired/i mkdir \"\$CHROOTDIR\/scripts\/" && cp \/scripts\/add_repositories.sh \"\$CHROOTDIR\/scripts\/" && chmod -R 755 \"\$CHROOTDIR\/scripts\/" && in_chroot \"\/scripts\/add_repositories.sh\"\n' /opt/domjudge/judgehost/bin/dj_make_chroot + # Usage: https://github.com/DOMjudge/domjudge/blob/main/misc-tools/dj_make_chroot.in#L58-L87 /opt/domjudge/judgehost/bin/dj_make_chroot From a17e3de4c96dc3efec7d9dd2c00f67a8619008ef Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Sat, 18 Jun 2022 18:58:00 +0200 Subject: [PATCH 08/27] Install additional languages --- docker/judgehost/Dockerfile | 6 ++++++ docker/judgehost/chroot-and-tar.sh | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/docker/judgehost/Dockerfile b/docker/judgehost/Dockerfile index 4ccc6e88..e13d37ac 100644 --- a/docker/judgehost/Dockerfile +++ b/docker/judgehost/Dockerfile @@ -20,8 +20,14 @@ RUN apt update \ gcc g++ default-jre-headless default-jdk ghc fp-compiler \ && rm -rf /var/lib/apt/lists/* +# Install more languages COPY judgehost/add_repositories.sh /add_repositories.sh RUN chmod 700 /add_repositories.sh && /add_repositories.sh && rm -f /add_repositories.sh +RUN apt update \ + && apt install --no-install-recommends --no-install-suggests -y \ + openjdk-17-jre-headless openjdk-17-jdk-headless pypy3 icpc-kotlinc \ + && rm -rf /var/lib/apt/lists/* + # Add chroot and judgehost data ADD chroot.tar.gz / ADD judgehost.tar.gz / diff --git a/docker/judgehost/chroot-and-tar.sh b/docker/judgehost/chroot-and-tar.sh index 8d5df753..a5a62411 100755 --- a/docker/judgehost/chroot-and-tar.sh +++ b/docker/judgehost/chroot-and-tar.sh @@ -3,7 +3,7 @@ sed -i.bak '/# Upgrade the system, and install\/remove packages as desired/i mkdir \"\$CHROOTDIR\/scripts\/" && cp \/scripts\/add_repositories.sh \"\$CHROOTDIR\/scripts\/" && chmod -R 755 \"\$CHROOTDIR\/scripts\/" && in_chroot \"\/scripts\/add_repositories.sh\"\n' /opt/domjudge/judgehost/bin/dj_make_chroot # Usage: https://github.com/DOMjudge/domjudge/blob/main/misc-tools/dj_make_chroot.in#L58-L87 -/opt/domjudge/judgehost/bin/dj_make_chroot +/opt/domjudge/judgehost/bin/dj_make_chroot -i openjdk-17-jre-headless,openjdk-17-jdk-headless,pypy3,icpc-kotlinc cd / echo "[..] Compressing chroot" From 77c5fa6e18cbd8531edd0d6c3e646c0580b56da6 Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Sat, 18 Jun 2022 18:58:27 +0200 Subject: [PATCH 09/27] Use Ubuntu 22.04 for judgehosts --- docker/judgehost/Dockerfile | 2 +- docker/judgehost/Dockerfile.build | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/judgehost/Dockerfile b/docker/judgehost/Dockerfile index e13d37ac..d22f7cd2 100644 --- a/docker/judgehost/Dockerfile +++ b/docker/judgehost/Dockerfile @@ -1,4 +1,4 @@ -FROM debian:stable +FROM ubuntu:22.04 LABEL org.opencontainers.image.authors="DOMjudge team " ENV DEBIAN_FRONTEND=noninteractive \ diff --git a/docker/judgehost/Dockerfile.build b/docker/judgehost/Dockerfile.build index 45b8386e..e984bc33 100644 --- a/docker/judgehost/Dockerfile.build +++ b/docker/judgehost/Dockerfile.build @@ -1,4 +1,4 @@ -FROM debian:stable-slim +FROM ubuntu:22.04 LABEL org.opencontainers.image.authors="DOMjudge team " ENV DEBIAN_FRONTEND=noninteractive From 5fa8bc9e4f89ca5419be559bf97e07bb09bd1d63 Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Sat, 18 Jun 2022 19:23:36 +0200 Subject: [PATCH 10/27] Fix path to kotlin run file --- docker/domserver/scripts/patches.d/20-kotlin-login-shell.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docker/domserver/scripts/patches.d/20-kotlin-login-shell.py b/docker/domserver/scripts/patches.d/20-kotlin-login-shell.py index aa454ba9..6db69c59 100755 --- a/docker/domserver/scripts/patches.d/20-kotlin-login-shell.py +++ b/docker/domserver/scripts/patches.d/20-kotlin-login-shell.py @@ -2,9 +2,8 @@ import pathlib -# dj_source = next(pathlib.Path("/domjudge-src").glob("domjudge*")) -# kt_run = dj_source / "sql/files/defaultdata/kt/run" -kt_run = pathlib.Path("run") +dj_source = next(pathlib.Path("/domjudge-src").glob("domjudge*")) +kt_run = dj_source / "sql/files/defaultdata/kt/run" with open(kt_run) as f: lines = f.readlines() From da8f277763e9b6df0ba4a3a1ff5364b6921c3b01 Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Sat, 2 Jul 2022 11:23:17 +0200 Subject: [PATCH 11/27] Update icpc repo --- docker/judgehost/add_repositories.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docker/judgehost/add_repositories.sh b/docker/judgehost/add_repositories.sh index ed5aff52..e36c688e 100644 --- a/docker/judgehost/add_repositories.sh +++ b/docker/judgehost/add_repositories.sh @@ -1,8 +1,8 @@ apt-get update apt-get install software-properties-common gnupg -echo "deb [trusted=yes] https://pc2.ecs.baylor.edu/apt focal main" >> /etc/apt/sources.list -echo 'Acquire::https::pc2.ecs.baylor.edu::Verify-Peer "false"; -Acquire::https::pc2.ecs.baylor.edu::Verify-Host "false";' >> /etc/apt/apt.conf.d/80trust-baylor-mirror +echo "deb [trusted=yes] https://sysopspackages.icpc.global/apt focal main" >> /etc/apt/sources.list +echo 'Acquire::https::sysopspackages.icpc.global::Verify-Peer "false"; +Acquire::https::sysopspackages.icpc.global::Verify-Host "false";' >> /etc/apt/apt.conf.d/80trust-baylor-mirror apt-get update From 3f3cfd96773237444bd584023f23fc9a6b15b27f Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Sat, 2 Jul 2022 11:25:35 +0200 Subject: [PATCH 12/27] Rename kotlin script --- .../patches.d/{20-kotlin-login-shell.py => 20-source-kotlin.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename docker/domserver/scripts/patches.d/{20-kotlin-login-shell.py => 20-source-kotlin.py} (100%) diff --git a/docker/domserver/scripts/patches.d/20-kotlin-login-shell.py b/docker/domserver/scripts/patches.d/20-source-kotlin.py similarity index 100% rename from docker/domserver/scripts/patches.d/20-kotlin-login-shell.py rename to docker/domserver/scripts/patches.d/20-source-kotlin.py From 88f6f01bb3bc5aa57d47d2b0d85a0f79149a21c8 Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Fri, 29 Jul 2022 13:11:30 +0200 Subject: [PATCH 13/27] Add automatically importing affiliations --- docker/domserver/Dockerfile | 1 + .../domserver/scripts/bin/import_affiliations | 124 ++++++++++++++++++ .../scripts/start.d/99-affiliations.sh | 3 + 3 files changed, 128 insertions(+) create mode 100644 docker/domserver/scripts/bin/import_affiliations create mode 100755 docker/domserver/scripts/start.d/99-affiliations.sh diff --git a/docker/domserver/Dockerfile b/docker/domserver/Dockerfile index d94ab6d2..e84365c3 100644 --- a/docker/domserver/Dockerfile +++ b/docker/domserver/Dockerfile @@ -66,6 +66,7 @@ RUN apt update \ enscript \ printer-driver-all cups cups-pdf cups-client cups-bsd cups-filters \ ca-certificates python3-yaml \ + vim wget httpie \ && rm -rf /var/lib/apt/lists/* # Install composer diff --git a/docker/domserver/scripts/bin/import_affiliations b/docker/domserver/scripts/bin/import_affiliations new file mode 100644 index 00000000..3e489abf --- /dev/null +++ b/docker/domserver/scripts/bin/import_affiliations @@ -0,0 +1,124 @@ +#!/bin/bash +# +# +# ARG_POSITIONAL_SINGLE([git-repository],[Github repository to download the affiliations from (optional)],[robertdijk/icpc-logos]) +# ARG_HELP([Import logos and affiliations from a github repo]) +# ARGBASH_GO() +# needed because of Argbash --> m4_ignore([ +### START OF CODE GENERATED BY Argbash v2.9.0 one line above ### +# Argbash is a bash code generator used to get arguments parsing right. +# Argbash is FREE SOFTWARE, see https://argbash.io for more info +# Generated online by https://argbash.io/generate + + +die() +{ + local _ret="${2:-1}" + test "${_PRINT_HELP:-no}" = yes && print_help >&2 + echo "$1" >&2 + exit "${_ret}" +} + + +begins_with_short_option() +{ + local first_option all_short_options='h' + first_option="${1:0:1}" + test "$all_short_options" = "${all_short_options/$first_option/}" && return 1 || return 0 +} + +# THE DEFAULTS INITIALIZATION - POSITIONALS +_positionals=() +_arg_git_repository="robertdijk/icpc-logos" +# THE DEFAULTS INITIALIZATION - OPTIONALS + + +print_help() +{ + printf '%s\n' "Import logos and affiliations from a github repo" + printf 'Usage: %s [-h|--help] []\n' "$0" + printf '\t%s\n' ": Github repository to download the affiliations from (optional) (default: 'robertdijk/icpc-logos')" + printf '\t%s\n' "-h, --help: Prints help" +} + + +parse_commandline() +{ + _positionals_count=0 + while test $# -gt 0 + do + _key="$1" + case "$_key" in + -h|--help) + print_help + exit 0 + ;; + -h*) + print_help + exit 0 + ;; + *) + _last_positional="$1" + _positionals+=("$_last_positional") + _positionals_count=$((_positionals_count + 1)) + ;; + esac + shift + done +} + + +handle_passed_args_count() +{ + test "${_positionals_count}" -le 1 || _PRINT_HELP=yes die "FATAL ERROR: There were spurious positional arguments --- we expect between 0 and 1, but got ${_positionals_count} (the last one was: '${_last_positional}')." 1 +} + + +assign_positional_args() +{ + local _positional_name _shift_for=$1 + _positional_names="_arg_git_repository " + + shift "$_shift_for" + for _positional_name in ${_positional_names} + do + test $# -gt 0 || break + eval "$_positional_name=\${1}" || die "Error during argument parsing, possibly an Argbash bug." 1 + shift + done +} + +parse_commandline "$@" +handle_passed_args_count +assign_positional_args 1 "${_positionals[@]}" + +# OTHER STUFF GENERATED BY Argbash + +### END OF CODE GENERATED BY Argbash (sortof) ### ]) +# [ <-- needed because of Argbash + +tmp_dir=$(mktemp -d -t affiliations-XXXXXXXXXX) + +ADMINPASS=$(cat /opt/domjudge/domserver/etc/initial_admin_password.secret) + +curl -s https://api.github.com/repos/$_arg_git_repository/releases/latest \ +| grep browser_download_url \ +| grep background_64.zip \ +| cut -d : -f 2,3 \ +| tr -d \" \ +| wget -P $tmp_dir -qi - + +curl -s https://api.github.com/repos/$_arg_git_repository/releases/latest \ +| grep browser_download_url \ +| grep organizations.json \ +| cut -d : -f 2,3 \ +| tr -d \" \ +| wget -P $tmp_dir -qi - + + +unzip -j -o -q $tmp_dir/background_64.zip -d /opt/domjudge/domserver/webapp/public/images/affiliations +http -a admin:$ADMINPASS --check-status -b -f POST "http://localhost:80/api/users/organizations" json@$tmp_dir/organizations.json --ignore-stdin + +rm -rf $tmp_dir + +# ] <-- needed because of Argbash diff --git a/docker/domserver/scripts/start.d/99-affiliations.sh b/docker/domserver/scripts/start.d/99-affiliations.sh new file mode 100755 index 00000000..759cbd04 --- /dev/null +++ b/docker/domserver/scripts/start.d/99-affiliations.sh @@ -0,0 +1,3 @@ +#!/bin/bash -e + +(sleep 30 && import_affiliations) & From 547eaf65455ff63b089fd0071b4d76511d78f9c2 Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Sun, 31 Jul 2022 16:36:19 +0200 Subject: [PATCH 14/27] Update default config --- docker/domserver/scripts/patches.d/10-default-config.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docker/domserver/scripts/patches.d/10-default-config.py b/docker/domserver/scripts/patches.d/10-default-config.py index e0c0abde..cc582c07 100755 --- a/docker/domserver/scripts/patches.d/10-default-config.py +++ b/docker/domserver/scripts/patches.d/10-default-config.py @@ -19,6 +19,13 @@ for item in category["items"]: if item["name"] == "print_command": item["default_value"] = "/usr/bin/enscript --columns=2 --pages=-10 --landscape --pretty-print \"--header='[original]'; page $% of $=; time=$C; room='[location]'; team='[teamname]'\" [file]" + if item["name"] == "data_source": + item["default_value"] = 1 + + if category["category"] == "Display": + for item in category["items"]: + if item["name"] == "show_affiliation_logos": + item["default_value"] = True with open(config, "w") as f: yaml.dump(list_doc, f) From eb138192189f71c29e41e1275111bcf91852a40b Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Fri, 19 Aug 2022 10:47:17 +0200 Subject: [PATCH 15/27] Enable kotlin by default --- .../scripts/patches.d/30-enable-kotlin.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 docker/domserver/scripts/patches.d/30-enable-kotlin.py diff --git a/docker/domserver/scripts/patches.d/30-enable-kotlin.py b/docker/domserver/scripts/patches.d/30-enable-kotlin.py new file mode 100755 index 00000000..61d529fb --- /dev/null +++ b/docker/domserver/scripts/patches.d/30-enable-kotlin.py @@ -0,0 +1,20 @@ +#!/usr/bin/python3 + +import pathlib + +dj_source = next(pathlib.Path("/domjudge-src").glob("domjudge*")) +language_fixture_php = dj_source / "webapp/src/DataFixtures/DefaultData/LanguageFixture.php" + +with open(language_fixture_php, "r") as f: + lines = f.readlines() + +for i in range(len(lines)): + if lines[i] == " ['kt', 'kotlin', 'Kotlin', ['kt'], true, 'Main class', false, true, 1, 'kt'],\n": + lines[i] = " ['kt', 'kotlin', 'Kotlin', ['kt'], true, 'Main class', true, true, 1, 'kt'],\n" + break +else: + print(f"Couldn't find kotlin line in {language_fixture_php}") + exit(1) + +with open(language_fixture_php, "w") as f: + f.writelines(lines) From 8741b9c12c522c6a2ce4a0f5a220ae5597e74d57 Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Fri, 19 Aug 2022 10:51:28 +0200 Subject: [PATCH 16/27] Add DOMjudge team to admin --- .../scripts/patches.d/40-admin-team.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 docker/domserver/scripts/patches.d/40-admin-team.py diff --git a/docker/domserver/scripts/patches.d/40-admin-team.py b/docker/domserver/scripts/patches.d/40-admin-team.py new file mode 100755 index 00000000..8f4fdf2e --- /dev/null +++ b/docker/domserver/scripts/patches.d/40-admin-team.py @@ -0,0 +1,20 @@ +#!/usr/bin/python3 + +import pathlib + +dj_source = next(pathlib.Path("/domjudge-src").glob("domjudge*")) +user_fixture_php = dj_source / "webapp/src/DataFixtures/DefaultData/UserFixture.php" + +with open(user_fixture_php, "r") as f: + lines = f.readlines() + +for i in range(len(lines)): + if lines[i] == " ->setUsername('admin')\n": + lines[i] = " ->setUsername('admin')->setTeam($this->getReference(TeamFixture::DOMJUDGE_REFERENCE))\n" + break +else: + print(f"Couldn't find admin line in {user_fixture_php}") + exit(1) + +with open(user_fixture_php, "w") as f: + f.writelines(lines) From 5c29c00eb7acc50460bbe53dfa75877e8f63d04a Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Sat, 15 Oct 2022 16:37:03 +0200 Subject: [PATCH 17/27] Update kotlin script --- .../patches.d/20-set-kotlin-location.py | 24 +++++++++++++++++++ .../scripts/patches.d/20-source-kotlin.py | 16 ------------- 2 files changed, 24 insertions(+), 16 deletions(-) create mode 100644 docker/domserver/scripts/patches.d/20-set-kotlin-location.py delete mode 100755 docker/domserver/scripts/patches.d/20-source-kotlin.py diff --git a/docker/domserver/scripts/patches.d/20-set-kotlin-location.py b/docker/domserver/scripts/patches.d/20-set-kotlin-location.py new file mode 100644 index 00000000..cacfe1e1 --- /dev/null +++ b/docker/domserver/scripts/patches.d/20-set-kotlin-location.py @@ -0,0 +1,24 @@ +#!/usr/bin/python3 + +import pathlib + +dj_source = next(pathlib.Path("/domjudge-src").glob("domjudge*")) +kt_run = dj_source / "sql/files/defaultdata/kt/run" + +with open(kt_run) as f: + lines = f.readlines() + +for i in range(len(lines)): + if lines[i].startswith("KOTLIN_DIR="): + lines[i] = "# " + lines[i] + +for i in range(len(lines)): + if lines[i].startswith("# KOTLIN_DIR=/usr/lib/kotlinc/bin"): + lines[i] = lines[i][2:] + break +else: + print(f"Couldn't find KOTLIN_DIR line in {kt_run}") + exit(1) + +with open(kt_run, "w") as f: + f.writelines(lines) diff --git a/docker/domserver/scripts/patches.d/20-source-kotlin.py b/docker/domserver/scripts/patches.d/20-source-kotlin.py deleted file mode 100755 index 6db69c59..00000000 --- a/docker/domserver/scripts/patches.d/20-source-kotlin.py +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/python3 - -import pathlib - -dj_source = next(pathlib.Path("/domjudge-src").glob("domjudge*")) -kt_run = dj_source / "sql/files/defaultdata/kt/run" - -with open(kt_run) as f: - lines = f.readlines() - -for i in range(len(lines)): - if lines[i] == "#!/bin/sh\n": - lines[i] = lines[i] + ". /etc/profile.d/kotlin.sh\n" - -with open(kt_run, "w") as f: - f.writelines(lines) From 1332bea2c0520ce9f3028e44ad3d5280763d74f7 Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Wed, 19 Oct 2022 10:23:55 +0200 Subject: [PATCH 18/27] Set C and CPP standard --- .../scripts/patches.d/50-set-c-standard.py | 20 +++++++++++++++++++ .../scripts/patches.d/60-set-cpp-standard.py | 20 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100755 docker/domserver/scripts/patches.d/50-set-c-standard.py create mode 100755 docker/domserver/scripts/patches.d/60-set-cpp-standard.py diff --git a/docker/domserver/scripts/patches.d/50-set-c-standard.py b/docker/domserver/scripts/patches.d/50-set-c-standard.py new file mode 100755 index 00000000..fb172e5c --- /dev/null +++ b/docker/domserver/scripts/patches.d/50-set-c-standard.py @@ -0,0 +1,20 @@ +#!/usr/bin/python3 + +import pathlib + +dj_source = next(pathlib.Path("/domjudge-src").glob("domjudge*")) +c_run = dj_source / "sql/files/defaultdata/c/run" + +with open(c_run) as f: + lines = f.readlines() + +for i in range(len(lines)): + if lines[i].startswith("gcc"): + lines[i] = "gcc" + " -std=gnu17" + lines[i][3:] + break +else: + print(f"Couldn't find gcc line in {c_run}") + exit(1) + +with open(c_run, "w") as f: + f.writelines(lines) diff --git a/docker/domserver/scripts/patches.d/60-set-cpp-standard.py b/docker/domserver/scripts/patches.d/60-set-cpp-standard.py new file mode 100755 index 00000000..fa7b892c --- /dev/null +++ b/docker/domserver/scripts/patches.d/60-set-cpp-standard.py @@ -0,0 +1,20 @@ +#!/usr/bin/python3 + +import pathlib + +dj_source = next(pathlib.Path("/domjudge-src").glob("domjudge*")) +cpp_run = dj_source / "sql/files/defaultdata/cpp/run" + +with open(cpp_run) as f: + lines = f.readlines() + +for i in range(len(lines)): + if lines[i].startswith("g++"): + lines[i] = "g++" + " -std=gnu++20" + lines[i][3:] + break +else: + print(f"Couldn't find g++ line in {cpp_run}") + exit(1) + +with open(cpp_run, "w") as f: + f.writelines(lines) From ac22f2d612cfed214b5c933315cd359b03df96b7 Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Sun, 20 Nov 2022 15:20:01 +0100 Subject: [PATCH 19/27] Only download affiliation logos, and change to transparent --- docker/domserver/scripts/bin/import_affiliations | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docker/domserver/scripts/bin/import_affiliations b/docker/domserver/scripts/bin/import_affiliations index 3e489abf..adea4d6a 100644 --- a/docker/domserver/scripts/bin/import_affiliations +++ b/docker/domserver/scripts/bin/import_affiliations @@ -103,7 +103,7 @@ ADMINPASS=$(cat /opt/domjudge/domserver/etc/initial_admin_password.secret) curl -s https://api.github.com/repos/$_arg_git_repository/releases/latest \ | grep browser_download_url \ -| grep background_64.zip \ +| grep transparent_64.zip \ | cut -d : -f 2,3 \ | tr -d \" \ | wget -P $tmp_dir -qi - @@ -116,8 +116,8 @@ curl -s https://api.github.com/repos/$_arg_git_repository/releases/latest \ | wget -P $tmp_dir -qi - -unzip -j -o -q $tmp_dir/background_64.zip -d /opt/domjudge/domserver/webapp/public/images/affiliations -http -a admin:$ADMINPASS --check-status -b -f POST "http://localhost:80/api/users/organizations" json@$tmp_dir/organizations.json --ignore-stdin +unzip -j -o -q $tmp_dir/transparent_64.zip -d /opt/domjudge/domserver/webapp/public/images/affiliations +# http -a admin:$ADMINPASS --check-status -b -f POST "http://localhost:80/api/users/organizations" json@$tmp_dir/organizations.json --ignore-stdin rm -rf $tmp_dir From 7f79165752c2ee961d17ae57d78b1dd327b3533d Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Thu, 29 Dec 2022 23:49:00 +0100 Subject: [PATCH 20/27] Update workflow to support branches --- .github/workflows/build_and_push_docker.yml | 254 +++++++++++++------- 1 file changed, 170 insertions(+), 84 deletions(-) diff --git a/.github/workflows/build_and_push_docker.yml b/.github/workflows/build_and_push_docker.yml index 30f20154..c18cb334 100644 --- a/.github/workflows/build_and_push_docker.yml +++ b/.github/workflows/build_and_push_docker.yml @@ -1,3 +1,4 @@ +--- name: 'Build version' on: @@ -7,96 +8,181 @@ on: workflow_dispatch: inputs: version: - required: true + required: false env: REGISTRY: ghcr.io REPO_NAME: ${{ github.repository }} jobs: - build: + get_version: runs-on: ubuntu-latest + outputs: + docker_tags: ${{ steps.dowload_domjudge.outputs.docker_tags }} + domjudge_cache_key: ${{ steps.domjudge_cache_key.outputs.domjudge_cache_key }} steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - with: - image: tonistiigi/binfmt:latest - platforms: all - - - name: Available platforms - run: echo ${{ steps.qemu.outputs.platforms }} - - - name: Set up Docker Buildx - id: buildx - uses: docker/setup-buildx-action@v1 - - - name: Inspect builder - run: | - echo "Name: ${{ steps.buildx.outputs.name }}" - echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}" - echo "Status: ${{ steps.buildx.outputs.status }}" - echo "Flags: ${{ steps.buildx.outputs.flags }}" - echo "Platforms: ${{ steps.buildx.outputs.platforms }}" - - - name: Get latest version - if: "${{ github.event.inputs.version == '' || github.event.inputs.version == 'latest' }}" - run: echo "version_to_build=$(curl -s https://api.github.com/repos/DOMjudge/domjudge/git/refs/tags | jq 'reverse | ((.[].ref) / "refs/tags/" )[1]' | rev | cut -c2- | rev | cut -c2- | head -n 1)" >> $GITHUB_ENV - - name: Store input version - if: "${{ github.event.inputs.version != '' && github.event.inputs.version != 'latest' }}" - run: echo "version_to_build=${{ github.event.inputs.version }}" >> $GITHUB_ENV - - name: Print version - run: echo "${{ env.version_to_build }}" - - name: Check valid version - run: curl -s https://api.github.com/repos/DOMjudge/domjudge/git/refs/tags | jq 'reverse | ((.[].ref) / "refs/tags/" )[1]' | rev | cut -c2- | rev | cut -c2- | grep -Fxq ${{ env.version_to_build }} - - name: Set flag for latest - run: | - if [[ "${{ env.version_to_build }}" == "$(curl -s https://api.github.com/repos/DOMjudge/domjudge/git/refs/tags | jq 'reverse | ((.[].ref) / "refs/tags/" )[1]' | rev | cut -c2- | rev | cut -c2- | head -n 1)" ]]; then - echo "latest=true" >> $GITHUB_ENV - echo "latest set to true" - else - echo "latest=false" >> $GITHUB_ENV - echo "latest set to false" - fi - - name: Repo name - run: echo "IMAGE_ID=$(echo ${{ env.REGISTRY }}/${{ env.REPO_NAME }} | tr '[A-Z]' '[a-z]')" >> $GITHUB_ENV - - - name: Build containers - run: | + - name: Checkout + uses: actions/checkout@v2 + + - name: Download Domjudge + id: dowload_domjudge + run: | + FILE="domjudge.tar.gz" + REPO="DOMjudge/domjudge" + INPUT_VERSION=${{ github.event.inputs.version }} + DOCKER_TAGS=( "latest" ) + DOCKER_TAGS+=( "packaging-$(git rev-parse --short HEAD)" ) + + DJ_TAGS=$(curl -s https://api.github.com/repos/${REPO}/git/refs/tags | jq 'reverse | ((.[].ref) / "refs/tags/" )[1]' | rev | cut -c2- | rev | cut -c2-) + RELEASE_VERSION=$(echo "${DJ_TAGS}" | head -n 1) + TAG_TO_BUILD="" + + if [[ "$INPUT_VERSION" == "" || "$INPUT_VERSION" == "release" || "$INPUT_VERSION" == "$RELEASE_VERSION" ]]; then + TAG_TO_BUILD=$RELEASE_VERSION + DOCKER_TAGS+=( "$RELEASE_VERSION" ) + fi + + if [[ "$TAG_TO_BUILD" == "" ]] && echo "$DJ_TAGS" | grep -F -q -x "$INPUT_VERSION"; then + TAG_TO_BUILD=$INPUT_VERSION + DOCKER_TAGS+=( "$INPUT_VERSION" ) + fi + + if [[ "$TAG_TO_BUILD" != "" ]]; then + echo "DOCKER_TAGS: ${DOCKER_TAGS[*]}" + echo "TAG_TO_BUILD: $TAG_TO_BUILD" + echo "docker_tags=${DOCKER_TAGS[*]}" >> $GITHUB_OUTPUT + wget "https://github.com/${REPO}/archive/refs/tags/${TAG_TO_BUILD}.tar.gz" -O ${FILE} + exit 0 + fi + + DJ_BRANCHES=$(curl -s https://api.github.com/repos/${REPO}/branches | jq '.[].name' | rev | cut -c2- | rev | cut -c2-) + BRANCH_TO_BUILD="" + + if [[ "$BRANCH_TO_BUILD" == "" ]] && echo "$DJ_BRANCHES" | grep -F -q -x "$INPUT_VERSION"; then + BRANCH_TO_BUILD=$INPUT_VERSION + DOCKER_TAGS+=( "$INPUT_VERSION" ) + fi + + if [[ "$BRANCH_TO_BUILD" != "" ]]; then + echo "DOCKER_TAGS: ${DOCKER_TAGS[*]}" + echo "BRANCH_TO_BUILD: $BRANCH_TO_BUILD" + echo "docker_tags=${DOCKER_TAGS[*]}" >> $GITHUB_OUTPUT + wget "https://github.com/${REPO}/archive/refs/heads/${BRANCH_TO_BUILD}.tar.gz" -O ${FILE} + exit 0 + fi + + DJ_COMMITS=$(curl -s https://api.github.com/repos/${REPO}/commits | jq '.[].sha' | rev | cut -c2- | rev | cut -c2-) + COMMIT_TO_BUILD="" + + if [[ "$COMMIT_TO_BUILD" == "" ]] && echo "$DJ_COMMITS" | grep -F -q -x "$INPUT_VERSION"; then + COMMIT_TO_BUILD=$INPUT_VERSION + DOCKER_TAGS+=( "$INPUT_VERSION" ) + fi + + if [[ "$COMMIT_TO_BUILD" != "" ]]; then + echo "DOCKER_TAGS: ${DOCKER_TAGS[*]}" + echo "COMMIT_TO_BUILD: $COMMIT_TO_BUILD" + echo "docker_tags=${DOCKER_TAGS[*]}" >> $GITHUB_OUTPUT + wget "https://github.com/${REPO}/archive/${COMMIT_TO_BUILD}.tar.gz" -O ${FILE} + exit 0 + fi + + exit 1 + - id: domjudge_cache_key + run: echo "domjudge_cache_key=${{ runner.os }}-${{ hashFiles('domjudge.tar.gz') }}" >> $GITHUB_OUTPUT + - name: Print docker tags + run: echo ${{ steps.dowload_domjudge.outputs.docker_tags }} + - uses: actions/cache@v3 + with: + path: domjudge.tar.gz + key: ${{ runner.os }}-${{ hashFiles('domjudge.tar.gz') }} + + build_domserver: + needs: get_version + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - uses: actions/cache@v3 + with: + path: domjudge.tar.gz + key: ${{ needs.get_version.outputs.domjudge_cache_key }} + + - run: mv domjudge.tar.gz ./docker + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + with: + image: tonistiigi/binfmt:latest + platforms: all + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + + - name: Build container + run: | cd ./docker - sudo bash -e build.sh ${{ env.version_to_build }} - - - name: Add tags - run: | - docker tag domjudge/domserver:${{ env.version_to_build }} ${{ env.IMAGE_ID }}/domserver:${{ env.version_to_build }} - docker tag domjudge/judgehost:${{ env.version_to_build }} ${{ env.IMAGE_ID }}/judgehost:${{ env.version_to_build }} - docker tag domjudge/default-judgehost-chroot:${{ env.version_to_build }} ${{ env.IMAGE_ID }}/default-judgehost-chroot:${{ env.version_to_build }} - - - name: Add latest tags - if: ${{ env.latest == 'true' }} - run: | - docker tag domjudge/domserver:${{ env.version_to_build }} ${{ env.IMAGE_ID }}/domserver:latest - docker tag domjudge/judgehost:${{ env.version_to_build }} ${{ env.IMAGE_ID }}/judgehost:latest - docker tag domjudge/default-judgehost-chroot:${{ env.version_to_build }} ${{ env.IMAGE_ID }}/default-judgehost-chroot:latest - - - name: Login to GitHub Container Registry - uses: docker/login-action@v1 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Push image - run: | - docker push ${{ env.IMAGE_ID }}/domserver:${{ env.version_to_build }} - docker push ${{ env.IMAGE_ID }}/judgehost:${{ env.version_to_build }} - docker push ${{ env.IMAGE_ID }}/default-judgehost-chroot:${{ env.version_to_build }} - - - name: Push latest - if: ${{ env.latest == 'true' }} - run: | - docker push ${{ env.IMAGE_ID }}/domserver:latest - docker push ${{ env.IMAGE_ID }}/judgehost:latest - docker push ${{ env.IMAGE_ID }}/default-judgehost-chroot:latest + sudo bash -e ./build-domjudge.sh "domjudge/domserver:chipcie" + + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Docker tag and push + run: | + IMAGE_ID=$(echo ${{ env.REGISTRY }}/${{ env.REPO_NAME }} | tr '[A-Z]' '[a-z]') + + for TAG in ${{ needs.get_version.outputs.docker_tags }}; do + docker tag domjudge/domserver:chipcie ${IMAGE_ID}/domserver:$TAG + docker push ${IMAGE_ID}/domserver:$TAG + done + + build_judgehost: + needs: get_version + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - uses: actions/cache@v3 + with: + path: domjudge.tar.gz + key: ${{ needs.get_version.outputs.domjudge_cache_key }} + + - run: mv domjudge.tar.gz ./docker + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + with: + image: tonistiigi/binfmt:latest + platforms: all + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + + - name: Build container + run: | + cd ./docker + sudo bash -e ./build-judgehost.sh "domjudge/judgehost:chipcie" + + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Docker tag and push + run: | + IMAGE_ID=$(echo ${{ env.REGISTRY }}/${{ env.REPO_NAME }} | tr '[A-Z]' '[a-z]') + + for TAG in ${{ needs.get_version.outputs.docker_tags }}; do + docker tag domjudge/judgehost:chipcie ${IMAGE_ID}/judgehost:$TAG + docker push ${IMAGE_ID}/judgehost:$TAG + done From 138ac93762cd0cbdec3864ca837f3a9836552d0b Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Thu, 25 May 2023 11:29:21 +0200 Subject: [PATCH 21/27] Make set kotlin location executable --- docker/domserver/scripts/patches.d/20-set-kotlin-location.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 docker/domserver/scripts/patches.d/20-set-kotlin-location.py diff --git a/docker/domserver/scripts/patches.d/20-set-kotlin-location.py b/docker/domserver/scripts/patches.d/20-set-kotlin-location.py old mode 100644 new mode 100755 From 45250ef27c012c8473004748c103519570e55a2f Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Thu, 3 Aug 2023 20:39:14 +0200 Subject: [PATCH 22/27] Update 30-enable-kotlin.py Make it compatible with future domjusge versions --- .../domserver/scripts/patches.d/30-enable-kotlin.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/docker/domserver/scripts/patches.d/30-enable-kotlin.py b/docker/domserver/scripts/patches.d/30-enable-kotlin.py index 61d529fb..a31659fd 100755 --- a/docker/domserver/scripts/patches.d/30-enable-kotlin.py +++ b/docker/domserver/scripts/patches.d/30-enable-kotlin.py @@ -1,6 +1,7 @@ #!/usr/bin/python3 import pathlib +import re dj_source = next(pathlib.Path("/domjudge-src").glob("domjudge*")) language_fixture_php = dj_source / "webapp/src/DataFixtures/DefaultData/LanguageFixture.php" @@ -9,9 +10,14 @@ lines = f.readlines() for i in range(len(lines)): - if lines[i] == " ['kt', 'kotlin', 'Kotlin', ['kt'], true, 'Main class', false, true, 1, 'kt'],\n": - lines[i] = " ['kt', 'kotlin', 'Kotlin', ['kt'], true, 'Main class', true, true, 1, 'kt'],\n" - break + elements = lines[i].split(',') + + if len(elements) >= 10 and elements[6].strip().lower() == 'false': + if 'kt' in elements[0]: + elements[6] = 'true' + + lines[i] = ','.join(elements) + break else: print(f"Couldn't find kotlin line in {language_fixture_php}") exit(1) From bc956ade0e8d8d2760357f122073d69738f6b131 Mon Sep 17 00:00:00 2001 From: Maarten Weyns Date: Fri, 15 Sep 2023 17:43:28 +0200 Subject: [PATCH 23/27] Update judgehost and apt repo to jammy --- docker/judgehost/add_repositories.sh | 2 +- docker/judgehost/chroot-and-tar.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/judgehost/add_repositories.sh b/docker/judgehost/add_repositories.sh index e36c688e..1ff291c1 100644 --- a/docker/judgehost/add_repositories.sh +++ b/docker/judgehost/add_repositories.sh @@ -1,7 +1,7 @@ apt-get update apt-get install software-properties-common gnupg -echo "deb [trusted=yes] https://sysopspackages.icpc.global/apt focal main" >> /etc/apt/sources.list +echo "deb [trusted=yes] https://sysopspackages.icpc.global/apt/jammy jammy main" >> /etc/apt/sources.list echo 'Acquire::https::sysopspackages.icpc.global::Verify-Peer "false"; Acquire::https::sysopspackages.icpc.global::Verify-Host "false";' >> /etc/apt/apt.conf.d/80trust-baylor-mirror diff --git a/docker/judgehost/chroot-and-tar.sh b/docker/judgehost/chroot-and-tar.sh index a5a62411..6d15acdc 100755 --- a/docker/judgehost/chroot-and-tar.sh +++ b/docker/judgehost/chroot-and-tar.sh @@ -3,7 +3,7 @@ sed -i.bak '/# Upgrade the system, and install\/remove packages as desired/i mkdir \"\$CHROOTDIR\/scripts\/" && cp \/scripts\/add_repositories.sh \"\$CHROOTDIR\/scripts\/" && chmod -R 755 \"\$CHROOTDIR\/scripts\/" && in_chroot \"\/scripts\/add_repositories.sh\"\n' /opt/domjudge/judgehost/bin/dj_make_chroot # Usage: https://github.com/DOMjudge/domjudge/blob/main/misc-tools/dj_make_chroot.in#L58-L87 -/opt/domjudge/judgehost/bin/dj_make_chroot -i openjdk-17-jre-headless,openjdk-17-jdk-headless,pypy3,icpc-kotlinc +/opt/domjudge/judgehost/bin/dj_make_chroot -R jammy -i openjdk-17-jre-headless,openjdk-17-jdk-headless,pypy3,icpc-kotlinc cd / echo "[..] Compressing chroot" From f992d6aee789d2bff8dc78382225e338d74cda5a Mon Sep 17 00:00:00 2001 From: Maarten Weyns Date: Sun, 5 Nov 2023 11:30:27 +0100 Subject: [PATCH 24/27] Change icpc-logos repo location --- docker/domserver/scripts/bin/import_affiliations | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docker/domserver/scripts/bin/import_affiliations b/docker/domserver/scripts/bin/import_affiliations index adea4d6a..9796f8b3 100644 --- a/docker/domserver/scripts/bin/import_affiliations +++ b/docker/domserver/scripts/bin/import_affiliations @@ -1,7 +1,7 @@ #!/bin/bash # # -# ARG_POSITIONAL_SINGLE([git-repository],[Github repository to download the affiliations from (optional)],[robertdijk/icpc-logos]) +# ARG_POSITIONAL_SINGLE([git-repository],[Github repository to download the affiliations from (optional)],[WISVCH/icpc-logos]) # ARG_HELP([Import logos and affiliations from a github repo]) # ARGBASH_GO() # needed because of Argbash --> m4_ignore([ @@ -29,7 +29,7 @@ begins_with_short_option() # THE DEFAULTS INITIALIZATION - POSITIONALS _positionals=() -_arg_git_repository="robertdijk/icpc-logos" +_arg_git_repository="WISVCH/icpc-logos" # THE DEFAULTS INITIALIZATION - OPTIONALS @@ -37,7 +37,7 @@ print_help() { printf '%s\n' "Import logos and affiliations from a github repo" printf 'Usage: %s [-h|--help] []\n' "$0" - printf '\t%s\n' ": Github repository to download the affiliations from (optional) (default: 'robertdijk/icpc-logos')" + printf '\t%s\n' ": Github repository to download the affiliations from (optional) (default: 'WISVCH/icpc-logos')" printf '\t%s\n' "-h, --help: Prints help" } From f84320c274731d10c38b19cf16cdd5eb172a408f Mon Sep 17 00:00:00 2001 From: Alireza Ghasemi Date: Mon, 9 Oct 2023 14:50:43 +0330 Subject: [PATCH 25/27] Fixup PHP version to 8.? Fix PHP version in the PHP timezone configuration script, used to access PHP's configuration directory. --- docker/domserver/scripts/start.d/10-timezone.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/domserver/scripts/start.d/10-timezone.sh b/docker/domserver/scripts/start.d/10-timezone.sh index ee8ace07..c046ad2a 100755 --- a/docker/domserver/scripts/start.d/10-timezone.sh +++ b/docker/domserver/scripts/start.d/10-timezone.sh @@ -6,7 +6,7 @@ dpkg-reconfigure -f noninteractive tzdata echo "[ok] Container timezone set to: ${CONTAINER_TIMEZONE}"; echo # Configure php -php_folder=$(echo "/etc/php/7."?"/") +php_folder=$(echo "/etc/php/8."?"/") cat > "$php_folder/fpm/conf.d/99-timezone.ini" <<- EOF [Date] From 78897a73d442a774ba5dfe67208e3e943ec6d6bc Mon Sep 17 00:00:00 2001 From: Maarten Weyns Date: Wed, 8 Nov 2023 16:05:07 +0100 Subject: [PATCH 26/27] Update domserver base to Debian bookworm --- docker/domserver/Dockerfile | 11 +++++++---- docker/domserver/build.sh | 7 +++++-- docker/domserver/configure.sh | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/docker/domserver/Dockerfile b/docker/domserver/Dockerfile index 8248cde6..400079d2 100644 --- a/docker/domserver/Dockerfile +++ b/docker/domserver/Dockerfile @@ -1,4 +1,4 @@ -FROM debian:bullseye-slim AS domserver-build +FROM debian:bookworm-slim AS domserver-build LABEL org.opencontainers.image.authors="DOMjudge team " ENV DEBIAN_FRONTEND=noninteractive @@ -12,13 +12,16 @@ RUN apt update \ php-gd php-curl php-mysql php-json php-intl \ php-gmp php-xml php-mbstring \ sudo bsdmainutils ntp libcgroup-dev procps \ - python3-sphinx python3-sphinx-rtd-theme python3-pygments rst2pdf fontconfig python3-yaml \ + python3-venv fontconfig \ texlive-latex-recommended texlive-latex-extra \ - texlive-fonts-recommended texlive-lang-european latexmk \ + texlive-fonts-recommended texlive-lang-european latexmk tex-gyre \ libcurl4-gnutls-dev libjsoncpp-dev libmagic-dev \ enscript lpr ca-certificates \ && rm -rf /var/lib/apt/lists/* +# Use venv to install latest Sphinx. 6.1.0 or higher is required to build DOMjudge docs. +RUN python3 -m venv /venv && . /venv/bin/activate && pip3 install sphinx sphinx-rtd-theme rst2pdf + # Set up user RUN useradd -m domjudge @@ -40,7 +43,7 @@ RUN chmod 700 /scripts/patches.sh && /scripts/patches.sh RUN /domjudge-src/build.sh # Now create an image with the actual build in it -FROM debian:bullseye-slim +FROM debian:bookworm-slim LABEL org.opencontainers.image.authors="DOMjudge team " ENV DEBIAN_FRONTEND=noninteractive \ diff --git a/docker/domserver/build.sh b/docker/domserver/build.sh index cf660477..4ab23958 100755 --- a/docker/domserver/build.sh +++ b/docker/domserver/build.sh @@ -1,9 +1,12 @@ #!/bin/sh -eu +# Use venv to use latest Sphinx. 6.1.0 or higher is required to build DOMjudge docs. +. /venv/bin/activate + cd /domjudge-src/domjudge* chown -R domjudge: . # If we used a local source tarball, it might not have been built yet -sudo -u domjudge make dist +sudo -u domjudge sh -c '. /venv/bin/activate && make dist' sudo -u domjudge ./configure -with-baseurl=http://dj.chipcie.ch.tudelft.nl/ # Passwords should not be included in the built image. We create empty files here to prevent passwords from being generated. @@ -25,5 +28,5 @@ then rm /opt/domjudge/domserver/webapp/.env.local /opt/domjudge/domserver/webapp/.env.local.php fi -sudo -u domjudge make docs +sudo -u domjudge sh -c '. /venv/bin/activate && make docs' make install-docs diff --git a/docker/domserver/configure.sh b/docker/domserver/configure.sh index 55684046..5bd82143 100644 --- a/docker/domserver/configure.sh +++ b/docker/domserver/configure.sh @@ -23,7 +23,7 @@ done # Configure php -php_folder=$(echo "/etc/php/7."?"/") +php_folder=$(echo "/etc/php/8."?"/") php_version=$(basename "$php_folder") if [ ! -d "$php_folder" ] From 8c6cd894afd87117b1a4bea8df832c14fee4ab8c Mon Sep 17 00:00:00 2001 From: Maarten Weyns Date: Wed, 8 Nov 2023 16:17:46 +0100 Subject: [PATCH 27/27] Add python3-yaml apt package --- docker/domserver/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/domserver/Dockerfile b/docker/domserver/Dockerfile index 400079d2..ced93d97 100644 --- a/docker/domserver/Dockerfile +++ b/docker/domserver/Dockerfile @@ -12,7 +12,7 @@ RUN apt update \ php-gd php-curl php-mysql php-json php-intl \ php-gmp php-xml php-mbstring \ sudo bsdmainutils ntp libcgroup-dev procps \ - python3-venv fontconfig \ + python3-venv python3-yaml fontconfig \ texlive-latex-recommended texlive-latex-extra \ texlive-fonts-recommended texlive-lang-european latexmk tex-gyre \ libcurl4-gnutls-dev libjsoncpp-dev libmagic-dev \