forked from DOMjudge/domjudge-packaging
-
Notifications
You must be signed in to change notification settings - Fork 0
188 lines (155 loc) · 6.09 KB
/
build_and_push_docker.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
---
name: 'Build version'
on:
push:
branches:
- master
workflow_dispatch:
inputs:
version:
required: false
env:
REGISTRY: ghcr.io
REPO_NAME: ${{ github.repository }}
jobs:
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: 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?per_page=100 | 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-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