-
-
Notifications
You must be signed in to change notification settings - Fork 3
273 lines (237 loc) · 8.16 KB
/
build-image.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
name: Build Container Image
on:
push:
paths:
- 'utils/build-paper.sh'
- 'health.sh'
- 'utils/download-mc-monitor.sh'
- 'entrypoint.sh'
- 'Dockerfile'
- '.dockerignore'
- '.env'
- '.github/workflows/build-image.yml'
- 'utils/java.sh'
- 'utils/set-tags.sh'
- 'test/startup.sh'
- 'test/docker-compose.yml'
- 'test/server.properties'
jobs:
build_jar:
runs-on: ubuntu-latest
outputs:
MINECRAFT_VERSION: ${{ steps.paper-commit.outputs.MINECRAFT_VERSION }}
PAPER_VERSION: ${{ steps.paper-commit.outputs.PAPER_VERSION }}
PAPER_COMMIT: ${{ steps.paper-commit.outputs.PAPER_COMMIT }}
steps:
- uses: actions/checkout@v3
- name: Get Paper commit
id: paper-commit
shell: bash
run: |
source .env
{
echo "MINECRAFT_VERSION=${MINECRAFT_VERSION}"
echo "PAPER_VERSION=${PAPER_VERSION}"
echo "PAPER_COMMIT=${PAPER_COMMIT}"
} >> "$GITHUB_OUTPUT"
- name: cache paperclip
id: cache-paperclip
uses: actions/cache@v3
with:
path: Paper/paperclip-${{ steps.paper-commit.outputs.PAPER_COMMIT }}.jar
key: paperclip-${{ runner.os }}-${{ steps.paper-commit.outputs.PAPER_COMMIT }}
- name: clone Paper
if: steps.cache-paperclip.outputs.cache-hit != 'true'
uses: actions/checkout@v3
with:
repository: PaperMC/Paper
path: Paper
ref: ${{ steps.paper-commit.outputs.PAPER_COMMIT }}
- name: setup Java
if: steps.cache-paperclip.outputs.cache-hit != 'true'
uses: actions/[email protected]
with:
distribution: 'temurin'
java-version: '16.0.2'
cache: 'gradle'
- name: Build jar
if: steps.cache-paperclip.outputs.cache-hit != 'true'
run: |
ls
bash ./utils/build-paper.sh
ls -lh Paper/paperclip-${{ steps.paper-commit.outputs.PAPER_COMMIT }}.jar
file Paper/paperclip-${{ steps.paper-commit.outputs.PAPER_COMMIT }}.jar
- name: Upload paperclip.jar as artifact
uses: actions/upload-artifact@v3
with:
if-no-files-found: error
name: paperclip-${{ steps.paper-commit.outputs.PAPER_COMMIT }}
path: Paper/paperclip-${{ steps.paper-commit.outputs.PAPER_COMMIT }}.jar
base_img_matrix:
name: Generate Base Image matrix
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v3
- name: Set Base Image matrix
id: set-matrix
run: |
imgs=$(./utils/java.sh base-img | tr '\n' ' ')
imgs=$(echo "${imgs}" | sed -e 's/ /, /g')
{
echo -n 'matrix=['
echo -n ${imgs}
echo ']'
} >> "$GITHUB_OUTPUT"
build_image:
runs-on: ubuntu-latest
needs: [build_jar, base_img_matrix]
outputs:
MINECRAFT_VERSION: ${{ needs.build_jar.outputs.MINECRAFT_VERSION }}
PAPER_VERSION: ${{ needs.build_jar.outputs.PAPER_VERSION }}
PAPER_COMMIT: ${{ needs.build_jar.outputs.PAPER_COMMIT }}
strategy:
matrix:
base_img: ${{ fromJSON(needs.base_img_matrix.outputs.matrix) }}
steps:
- uses: actions/checkout@v3
- name: clone Paper
uses: actions/checkout@v3
with:
repository: PaperMC/Paper
path: Paper
ref: ${{ needs.build_jar.outputs.PAPER_COMMIT }}
- name: download paperclip.jar from artifact
uses: actions/download-artifact@v3
with:
name: paperclip-${{ needs.build_jar.outputs.PAPER_COMMIT }}
path: paperclip-artifact
- name: Rename downloaded artifact to Paper/paperclip.jar
run: |
mv "paperclip-artifact/paperclip-${{ needs.build_jar.outputs.PAPER_COMMIT }}.jar" Paper/paperclip.jar
- name: jar exist check
run: |
ls Paper
ls -lh Paper/paperclip.jar
file Paper/paperclip.jar
if [ -d Paper/paperclip.jar ]; then
echo "Oh shit! This paperclip.jar is directory!"
exit 1
fi
- name: Cache Docker Layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Docker meta
id: meta
uses: docker/[email protected]
with:
images: ghcr.io/${{ github.repository }},sksat/${{ github.event.repository.name }}
- name: Get base-image info
id: img-info
shell: bash
run: |
base=$(cut -d':' -f 1 <<<${{ matrix.base_img }})
tag_digest=$(cut -d':' -f 2 <<<${{ matrix.base_img }})
tag=$(cut -d'@' -f 1 <<<"${tag_digest}")
digest=$(cut -d'@' -f 2 <<<"${tag_digest}")
echo "base: $base"
echo "tag: $tag"
echo "digest: $digest"
jdk="openjdk"
if [[ $base =~ 'eclipse-temurin' ]]; then
jdk='temurin'
else
jdk="$base"
fi
echo "jdk=${jdk}, base=${tag}"
{
echo "jdk=${jdk}"
echo "base=${tag}"
} >> "$GITHUB_OUTPUT"
- name: Set Tags
id: tags
shell: bash
env:
JDK: ${{ steps.img-info.outputs.jdk }}
BASE_IMG: ${{ steps.img-info.outputs.base }}
run: |
tags=$(cat << EOS | ./utils/set-tags.sh
${{ steps.meta.outputs.tags }}
EOS
)
echo "tags: ${tags}"
{
delim="$(openssl rand -hex 8)"
echo "tags<<${delim}"
echo "${tags}"
echo "${delim}"
} >> "${GITHUB_OUTPUT}"
- name: Login to ghcr.io
if: ${{ github.event_name }} != 'pull_request'
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to DockerHub
if: ${{ github.event_name }} != 'pull_request'
uses: docker/login-action@v2
with:
username: sksat
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up QEMU
id: qemu
uses: docker/[email protected]
with:
platforms: all
- name: Set up Buildx
id: buildx
uses: docker/setup-buildx-action@v2
with:
# meantime solution from: https://github.com/docker/buildx/issues/834#issuecomment-965730742
buildkitd-flags: --debug
driver-opts: image=moby/buildkit:v0.9.1
- name: Show available platforms
run: echo ${{ steps.buildx.outputs.platforms }}
- name: Build and Push
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64,linux/arm64
build-args: |
"MINECRAFT_VERSION=${{ needs.build_jar.outputs.MINECRAFT_VERSION }}"
"PAPER_VERSION=${{ needs.build_jar.outputs.PAPER_VERSION }}"
"PAPER_COMMIT=${{ needs.build_jar.outputs.PAPER_COMMIT }}"
"BASE_IMG=${{ matrix.base_img }}"
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.tags.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
test:
needs: build_image
runs-on: ubuntu-latest
strategy:
matrix:
jdk: ["openjdk", "temurin"]
steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: |
python --version
python3 -m pip install mcstatus
- name: startup test
run: |
./test/startup.sh "${GITHUB_REF#refs/heads/}-${{ needs.build_image.outputs.MINECRAFT_VERSION }}-${{ matrix.jdk }}"