Skip to content

Commit 8944e11

Browse files
committed
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). The code for world readable files has been kept. Our build script is extended to now also have an option to push to another organization/namespace so we can push the image to the github container registry of the person doing the PR. As we don't do this often we explicit clean the github runner of older versions to make sure we always build against the latest image available of our dependencies and don't encounter the earlier builds if a PR is done more often (to fix something for example). The image can be locally tested by looking at the special tag based on the branchname/issue_number.
1 parent 88b9604 commit 8944e11

File tree

3 files changed

+165
-11
lines changed

3 files changed

+165
-11
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: 'Build domjudge container (PR)'
2+
3+
on:
4+
push:
5+
pull_request_target:
6+
branches:
7+
- main
8+
9+
env:
10+
DOMJUDGE_VERSION: M.m.p
11+
12+
jobs:
13+
pr-domjudge:
14+
if: ${{ github.repository != 'domjudge/domjudge-packaging' || github.ref != 'main' }}
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
20+
- name: Set up QEMU
21+
uses: docker/setup-qemu-action@v3
22+
23+
- name: Set up Docker Buildx
24+
uses: docker/setup-buildx-action@v3
25+
26+
- name: Login to Docker Hub
27+
uses: docker/login-action@v3
28+
with:
29+
registry: ghcr.io
30+
username: ${{ github.repository_owner }}
31+
password: ${{ secrets.GITHUB_TOKEN }}
32+
33+
- run: docker system prune -a -f
34+
35+
- name: Get an unique tag for when people PR often
36+
run: |
37+
GHR=${{ github.ref }}
38+
echo "PR_TAG=${GHR///}" >> $GITHUB_ENV
39+
40+
- name: If needed overwrite the DOMJUDGE_VERSION for this run
41+
run: |
42+
if [ ${{ env.DOMJUDGE_VERSION }} != "M.m.p" ]; then
43+
exit 0
44+
fi
45+
sudo apt update; sudo apt install -y jq curl
46+
set -x
47+
HUBURL="https://registry.hub.docker.com/v2/repositories/domjudge/domserver/tags"
48+
TAG=$(curl $HUBURL|jq '.results | sort_by(.name) | .[length-2].name')
49+
DJ_TAG=${TAG//\"}
50+
set +x
51+
echo "DOMJUDGE_VERSION=$DJ_TAG" >> $GITHUB_ENV
52+
53+
- name: Build the container
54+
run: |
55+
cd docker
56+
set -x
57+
sh ./build.sh "${{ env.DOMJUDGE_VERSION }}" ${{ github.actor }}
58+
set +x
59+
60+
- run: docker image list
61+
62+
- name: Build and push
63+
run: |
64+
for IMG in domserver judgehost default-judgehost-chroot; do
65+
IMAGE_NAME="${{ github.actor }}/$IMG:${{ env.DOMJUDGE_VERSION }}"
66+
docker image tag "$IMAGE_NAME" ghcr.io/${{ github.actor }}/$IMG:${{ env.PR_TAG }}
67+
docker image tag "$IMAGE_NAME" ${{ github.actor }}/$IMG:${{ env.PR_TAG }}
68+
docker push ghcr.io/${{ github.actor }}/$IMG:${{ env.PR_TAG }}
69+
done
70+
71+
- name: Check for wrong permisions
72+
run: |
73+
docker image list
74+
set -x
75+
for IMG in domserver judgehost; do
76+
files=$(docker run --rm --pull=never "${{ github.actor }}/$IMG:${{ env.PR_TAG }}" find / -xdev -perm -o+w ! -type l ! \( -type d -a -perm -+t \) ! -type c)
77+
if [ -n "$files" ]; then
78+
echo "error: image ${{ github.actor }}/$IMG:${{ env.PR_TAG }} contains world-writable files:" >&2
79+
printf "%s\n" "$files" >&2
80+
exit 1
81+
fi
82+
done
83+
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: 'Build domjudge container (Release)'
2+
3+
on:
4+
push:
5+
pull_request_target:
6+
branches:
7+
- main
8+
9+
env:
10+
DOMJUDGE_VERSION: M.m.p
11+
DOMJUDGE_LATEST: true
12+
13+
jobs:
14+
release-domjudge:
15+
if: ${{ github.repository == 'domjudge/domjudge-packaging' && github.ref == 'main' }}
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
21+
- name: Set up QEMU
22+
uses: docker/setup-qemu-action@v3
23+
24+
- name: Set up Docker Buildx
25+
uses: docker/setup-buildx-action@v3
26+
27+
- name: Login to Docker Hub
28+
uses: docker/login-action@v3
29+
with:
30+
username: ${{ env.DOCKERHUB_USERNAME }}
31+
password: ${{ env.DOCKERHUB_TOKEN }}
32+
33+
- name: If needed overwrite the DOMJUDGE_VERSION for this run
34+
run: |
35+
if [ ${{ env.DOMJUDGE_VERSION }} != "M.m.p" ]; then
36+
exit 0
37+
fi
38+
if [ ${{ env.DOMJUDGE_LATEST }} == "false" ]; then
39+
echo "I don't know which version to pick!"
40+
exit 1
41+
fi
42+
apk add jq curl
43+
set -x
44+
HUBURL="https://registry.hub.docker.com/v2/repositories/domjudge/domserver/tags"
45+
TAG=$(curl $HUBURL|jq '.results | sort_by(.name) | .[length-2].name')
46+
DJ_TAG=${TAG//\"}
47+
set +x
48+
echo "DOMJUDGE_VERSION=$DJ_TAG" >> $GITHUB_ENV
49+
50+
- name: Build the container
51+
run: |
52+
cd docker
53+
set -x
54+
sh ./build.sh "${{ env.DOMJUDGE_VERSION }}"
55+
set +x
56+
57+
- name: Build and push
58+
run: |
59+
for IMG in domserver judgehost default-judgehost-chroot; do
60+
docker push domjudge/$IMG:${{ env.DOMJUDGE_VERSION }}
61+
if [ ${{ env.DOMJUDGE_LATEST }} = "true" ]; then
62+
docker tag domjudge/$IMG:${{ env.DOMJUDGE_VERSION }} domjudge/$IMG:latest
63+
docker push domjudge/$IMG:latest
64+
fi
65+
done

docker/build.sh

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,20 @@ then
66
export PS4='(${0}:${LINENO}): - [$?] $ '
77
fi
88

9-
if [ "$#" -ne 1 ]
9+
if [ "$#" -eq 0 ] || [ "$#" -gt 2 ]
1010
then
11-
echo "Usage: $0 domjudge-version"
11+
echo "Usage: $0 domjudge-version <namespace>"
1212
echo " For example: $0 5.3.0"
13+
echo " or: $0 5.3.0 otherNamespace"
1314
exit 1
1415
fi
1516

1617
VERSION="$1"
18+
NAMESPACE="domjudge"
19+
if [ -n "${2+x}" ]
20+
then
21+
NAMESPACE="$2"
22+
fi
1723

1824
URL=https://www.domjudge.org/releases/domjudge-${VERSION}.tar.gz
1925
FILE=domjudge.tar.gz
@@ -29,22 +35,22 @@ fi
2935
echo "[ok] DOMjudge version ${VERSION} downloaded as domjudge.tar.gz"; echo
3036

3137
echo "[..] Building Docker image for domserver..."
32-
./build-domjudge.sh "domjudge/domserver:${VERSION}"
38+
./build-domjudge.sh "${NAMESPACE}/domserver:${VERSION}"
3339
echo "[ok] Done building Docker image for domserver"
3440

3541
echo "[..] Building Docker image for judgehost using intermediate build image..."
36-
./build-judgehost.sh "domjudge/judgehost:${VERSION}"
42+
./build-judgehost.sh "${NAMESPACE}/judgehost:${VERSION}"
3743
echo "[ok] Done building Docker image for judgehost"
3844

3945
echo "[..] Building Docker image for judgehost chroot..."
40-
docker build -t "domjudge/default-judgehost-chroot:${VERSION}" -f judgehost/Dockerfile.chroot .
46+
docker build -t "${NAMESPACE}/default-judgehost-chroot:${VERSION}" -f judgehost/Dockerfile.chroot .
4147
echo "[ok] Done building Docker image for judgehost chroot"
4248

43-
echo "All done. Image domjudge/domserver:${VERSION} and domjudge/judgehost:${VERSION} created"
49+
echo "All done. Image ${NAMESPACE}/domserver:${VERSION} and ${NAMESPACE}/judgehost:${VERSION} created"
4450
echo "If you are a DOMjudge maintainer with access to the domjudge organization on Docker Hub, you can now run the following command to push them to Docker Hub:"
45-
echo "$ docker push domjudge/domserver:${VERSION} && docker push domjudge/judgehost:${VERSION} && docker push domjudge/default-judgehost-chroot:${VERSION}"
51+
echo "$ docker push ${NAMESPACE}/domserver:${VERSION} && docker push ${NAMESPACE}/judgehost:${VERSION} && docker push $NAMESPACE}/default-judgehost-chroot:${VERSION}"
4652
echo "If this is the latest release, also run the following command:"
47-
echo "$ docker tag domjudge/domserver:${VERSION} domjudge/domserver:latest && \
48-
docker tag domjudge/judgehost:${VERSION} domjudge/judgehost:latest && \
49-
docker tag domjudge/default-judgehost-chroot:${VERSION} domjudge/default-judgehost-chroot:latest && \
50-
docker push domjudge/domserver:latest && docker push domjudge/judgehost:latest && docker push domjudge/default-judgehost-chroot:latest"
53+
echo "$ docker tag ${NAMESPACE}/domserver:${VERSION} ${NAMESPACE}/domserver:latest && \
54+
docker tag ${NAMESPACE}/judgehost:${VERSION} ${NAMESPACE}/judgehost:latest && \
55+
docker tag ${NAMESPACE}/default-judgehost-chroot:${VERSION} ${NAMESPACE}/default-judgehost-chroot:latest && \
56+
docker push ${NAMESPACE}/domserver:latest && docker push ${NAMESPACE}/judgehost:latest && docker push ${NAMESPACE}/default-judgehost-chroot:latest"

0 commit comments

Comments
 (0)