Skip to content

Build DOMjudge container(s) (PR) #334

Build DOMjudge container(s) (PR)

Build DOMjudge container(s) (PR) #334

name: 'Build DOMjudge container(s) (PR)'
permissions:
contents: read
packages: write
on:
merge_group:
# We can't limit the files as below as this is a required check so should run
# We exit early in case no relevant file changed
types: [checks_requested]
pull_request:
branches:
- main
push:
# We don't start the job if no relevant file changed
paths:
# This is an `either`, so any file listed here will trigger
- docker/**
- .github/workflows/build-domjudge-container-PR.yml
env:
DOMJUDGE_VERSION: M.m.p
jobs:
pr-domjudge:
name: PR DOMjudge docker image(s)
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Detect changed files and compute condition
id: filter
uses: ./.github/actions/helper-detect-changed-files
with:
trigger-files: "docker .github/workflows/build-domjudge-container-PR.yml"
- name: Mark as skipped
if: steps.filter.outputs.should_run == 'false'
run: echo "Skip job, no important files changed"
- name: Set up QEMU
if: steps.filter.outputs.should_run == 'true'
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
if: steps.filter.outputs.should_run == 'true'
uses: docker/setup-buildx-action@v3
- name: Login to GitHub container registry
if: steps.filter.outputs.should_run == 'true'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- run: docker system prune -a -f
if: steps.filter.outputs.should_run == 'true'
- name: Get an unique tag for when people PR often
if: steps.filter.outputs.should_run == 'true'
run: |
GHR=${{ github.ref }}
GHA=${{ github.actor }}
echo "PR_TAG=${GHR///}${GHA//[\]\[]/}" >> $GITHUB_ENV
- name: If needed overwrite the DOMJUDGE_VERSION for this run
if: steps.filter.outputs.should_run == 'true'
run: |
if [ ${{ env.DOMJUDGE_VERSION }} != "M.m.p" ]; then
exit 0
fi
sudo apt-get update; sudo apt-get install -y jq curl
set -x
HUBURL="https://registry.hub.docker.com/v2/repositories/domjudge/domserver/tags"
TAG=$(curl $HUBURL|jq '.results | sort_by(.name) | .[-2].name')
DJ_TAG=${TAG//\"}
set +x
echo "DOMJUDGE_VERSION=$DJ_TAG" >> $GITHUB_ENV
- name: Build the container
if: steps.filter.outputs.should_run == 'true'
run: |
cd docker
./build.sh "${{ env.DOMJUDGE_VERSION }}" "${GITHUB_REPOSITORY_OWNER@L}"
cd ../docker-chroot
./build.sh "${{ env.DOMJUDGE_VERSION }}" "${GITHUB_REPOSITORY_OWNER@L}"
- name: Build and push
if: steps.filter.outputs.should_run == 'true'
run: |
for IMG in domserver judgehost default-judgehost-chroot icpc-judgehost-chroot full-judgehost-chroot; do
echo "::group::${IMG}"
IMAGE_NAME="${GITHUB_REPOSITORY_OWNER@L}/${IMG}:${{ env.DOMJUDGE_VERSION }}"
docker image tag "$IMAGE_NAME" ghcr.io/${GITHUB_REPOSITORY_OWNER@L}/$IMG:${{ env.PR_TAG }}
docker image tag "$IMAGE_NAME" ${GITHUB_REPOSITORY_OWNER@L}/$IMG:${{ env.PR_TAG }}
docker push ghcr.io/${GITHUB_REPOSITORY_OWNER@L}/$IMG:${{ env.PR_TAG }} || true
echo "::endgroup::"
done
- run: docker image list
if: steps.filter.outputs.should_run == 'true'
- name: Check the created domserver container
if: steps.filter.outputs.should_run == 'true'
run: .github/jobs/check-domjudge-container.sh ${{ env.PR_TAG }} ${GITHUB_REPOSITORY_OWNER@L}
- name: Collect docker logs on failure
if: ${{ !cancelled() }}
uses: jwalton/gh-docker-logs@v2
with:
dest: '/tmp/docker-logs'
- name: Upload all logs
if: always()
uses: actions/upload-artifact@v4
with:
name: Logs
path: /tmp/docker-logs