From d3cb5836e87596b9c5e99c0fa6dfc7ba26b9598f Mon Sep 17 00:00:00 2001 From: Michael <14887731+vmcj@users.noreply.github.com> Date: Fri, 12 Jan 2024 15:56:30 +0100 Subject: [PATCH] Create action for docker build scripts The PRs for changes to those scripts will be stored in the registry of the user/organisation which forked or in our GitHub docker registry if this branch is under the domjudge organization. Here we always build against our latest version. The GitLab code had the option to not push the latest tag, for when we rebuild an older container, otherwise we always release against the overwritten value or if nothing was provided against the latest released tag (so which latest points to). --- .../workflows/build-domjudge-container-PR.yml | 57 ++++++++++++++++ .../build-domjudge-container-release.yml | 65 +++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 .github/workflows/build-domjudge-container-PR.yml create mode 100644 .github/workflows/build-domjudge-container-release.yml diff --git a/.github/workflows/build-domjudge-container-PR.yml b/.github/workflows/build-domjudge-container-PR.yml new file mode 100644 index 00000000..2c399364 --- /dev/null +++ b/.github/workflows/build-domjudge-container-PR.yml @@ -0,0 +1,57 @@ +name: 'Build domjudge container (PR)' + +on: + push: + pull_request_target: + branches: + - main + +env: + DOMJUDGE_VERSION: M.m.p + +jobs: + pr-domjudge: + if: ${{ github.repository != 'domjudge/domjudge-packaging' || github.ref != 'main' }} + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: If needed overwrite the DOMJUDGE_VERSION for this run + run: | + if [ ${{ env.DOMJUDGE_VERSION }} != "M.m.p" ]; then + exit 0 + fi + apt update; apt install -y add jq curl + set -x + HUBURL="https://registry.hub.docker.com/v2/repositories/domjudge/domserver/tags" + TAG=$(curl $HUBURL|jq '.results | sort_by(.name) | .[length-2].name') + DJ_TAG=${TAG//\"} + set +x + echo "DOMJUDGE_VERSION=$DJ_TAG" >> $GITHUB_ENV + + - name: Build the container + run: | + cd docker + set -x + sh ./build.sh "${{ env.DOMJUDGE_VERSION }}" + set +x + + - name: Build and push + run: | + for IMG in domserver judgehost default-judgehost-chroot; do + docker push domjudge/$IMG:${{ env.DOMJUDGE_VERSION }} + done diff --git a/.github/workflows/build-domjudge-container-release.yml b/.github/workflows/build-domjudge-container-release.yml new file mode 100644 index 00000000..872b3d98 --- /dev/null +++ b/.github/workflows/build-domjudge-container-release.yml @@ -0,0 +1,65 @@ +name: 'Build domjudge container (Release)' + +on: + push: + pull_request_target: + branches: + - main + +env: + DOMJUDGE_VERSION: M.m.p + DOMJUDGE_LATEST: true + +jobs: + release-domjudge: + if: ${{ github.repository == 'domjudge/domjudge-packaging' && github.ref == 'main' }} + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ env.DOCKERHUB_USERNAME }} + password: ${{ env.DOCKERHUB_TOKEN }} + + - name: If needed overwrite the DOMJUDGE_VERSION for this run + run: | + if [ ${{ env.DOMJUDGE_VERSION }} != "M.m.p" ]; then + exit 0 + fi + if [ ${{ env.DOMJUDGE_LATEST }} == "false" ]; then + echo "I don't know which version to pick!" + exit 1 + fi + apk add jq curl + set -x + HUBURL="https://registry.hub.docker.com/v2/repositories/domjudge/domserver/tags" + TAG=$(curl $HUBURL|jq '.results | sort_by(.name) | .[length-2].name') + DJ_TAG=${TAG//\"} + set +x + echo "DOMJUDGE_VERSION=$DJ_TAG" >> $GITHUB_ENV + + - name: Build the container + run: | + cd docker + set -x + sh ./build.sh "${{ env.DOMJUDGE_VERSION }}" + set +x + + - name: Build and push + run: | + for IMG in domserver judgehost default-judgehost-chroot; do + docker push domjudge/$IMG:${{ env.DOMJUDGE_VERSION }} + if [ ${{ env.DOMJUDGE_LATEST }} = "true" ]; then + docker tag domjudge/$IMG:${{ env.DOMJUDGE_VERSION }} domjudge/$IMG:latest + docker push domjudge/$IMG:latest + fi + done