-
-
Notifications
You must be signed in to change notification settings - Fork 121
412 lines (392 loc) · 15.5 KB
/
build-docker-server.yml
File metadata and controls
412 lines (392 loc) · 15.5 KB
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
name: Docker; Build & Push Server Image
on:
workflow_dispatch:
push:
branches:
- developer
- long-term-support
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository_owner }}/basis-server
HEADLESS_IMAGE_NAME: ${{ github.repository_owner }}/basis-headless
jobs:
check-secret:
name: Check if secrets available
timeout-minutes: 5
runs-on: ubuntu-latest
outputs:
secret-is-set: ${{ steps.secret-is-set.outputs.defined }}
steps:
- name: Check if secret is set, then set variable
id: secret-is-set
env:
TMP_SECRET1: ${{ secrets.UNITY_LICENSE }}
TMP_SECRET2: ${{ secrets.UNITY_EMAIL }}
TMP_SECRET3: ${{ secrets.UNITY_PASSWORD }}
if: "${{ env.TMP_SECRET1 != '' && env.TMP_SECRET2 != '' && env.TMP_SECRET3 != '' }}"
run: echo "defined=true" >> $GITHUB_OUTPUT
server-build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver-opts: |
network=host
- name: Log in to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
# For dev branch, tag as nightly
type=raw,value=nightly,enable=${{ github.ref == 'refs/heads/developer' }}
# For long-term-support branch, tag as latest
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/long-term-support' }}
# Also tag with commit SHA for both branches
type=sha,prefix={{branch}}-,format=short
# Tag with branch name
type=ref,event=branch
- name: Build and push Docker image
uses: docker/build-push-action@v5
id: build
with:
context: "./Basis Server"
file: "./Basis Server/Docker/Dockerfile"
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
BUILDKIT_INLINE_CACHE=1
- name: Image digest
run: 'echo "Image pushed with digest: ${{ steps.build.outputs.digest }}"'
headless-build:
name: Build headless for ${{ matrix.targetPlatform }}${{ matrix.linuxArchitecture && format(' - {0}', matrix.linuxArchitecture) || '' }}
timeout-minutes: 100
runs-on: ${{ matrix.buildPlatform }}
permissions:
actions: write # to allow us to manage cache
env:
projectPath: Basis
strategy:
fail-fast: false
matrix:
include:
- targetPlatform: StandaloneLinux64
buildPlatform: ubuntu-latest
buildName: HeadlessLinuxServer
buildOutput: LinuxServerAmd64
artifactName: LinuxHeadlessAmd64
headlessFolderName: HeadlessLinux64
linuxArchitecture: X64
customParameters: -standaloneBuildSubtarget Server -linuxArchitecture X64
buildMethod: BasisHeadlessBuild.BuildLinuxServer
- targetPlatform: StandaloneLinux64
buildPlatform: ubuntu-latest
buildName: HeadlessLinuxServer
buildOutput: LinuxServerArm64
artifactName: LinuxHeadlessArm64
headlessFolderName: HeadlessLinuxArm64
linuxArchitecture: ARM64
customParameters: -standaloneBuildSubtarget Server -linuxArchitecture ARM64
buildMethod: BasisHeadlessBuild.BuildLinuxServer
- targetPlatform: StandaloneWindows64
buildPlatform: ubuntu-latest
buildName: HeadlessWindowsServer
buildOutput: WindowsServer
artifactName: WindowsHeadless
headlessFolderName: HeadlessWindows64
customParameters: -standaloneBuildSubtarget Server
buildMethod: BasisHeadlessBuild.BuildWindowsServer
needs: [check-secret]
if: needs.check-secret.outputs.secret-is-set == 'true'
steps:
- name: Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@main
if: matrix.buildPlatform == 'ubuntu-latest'
with:
tool-cache: true
android: true
dotnet: true
haskell: true
large-packages: true
docker-images: false
swap-storage: false
- name: "Checkout repository"
timeout-minutes: 10
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: "Restore Library cache"
id: restore-cache
timeout-minutes: 10
uses: actions/cache/restore@v3
with:
path: ${{ env.projectPath }}/Library
key: Library-${{ env.projectPath }}-${{ matrix.targetPlatform }}-client-${{ hashFiles(env.projectPath) }}
restore-keys: Library-${{ env.projectPath }}-${{ matrix.targetPlatform }}-client-
enableCrossOsArchive: true
- name: "Sanitize headless project (Linux)"
if: runner.os == 'Linux'
shell: bash
run: |
python3 .github/scripts/sanitize_headless_ci.py "${projectPath}"
- name: "Install Linux Arm64 Unity SDK package"
if: matrix.targetPlatform == 'StandaloneLinux64' && matrix.linuxArchitecture == 'ARM64'
shell: bash
run: |
python3 .github/scripts/install_unity_package_latest.py "${projectPath}" "com.unity.sdk.linux-arm64"
- name: "Disable OpenVR editor setup for Windows headless builds"
if: runner.os == 'Windows'
shell: pwsh
run: |
$settingsPath = Join-Path $env:projectPath 'ProjectSettings/EditorBuildSettings.asset'
$settingsLines = Get-Content $settingsPath
$settingsLines |
Where-Object { $_ -notmatch '^\s*Unity\.XR\.OpenVR\.Settings:' } |
Set-Content $settingsPath
@(
'Assets/XR/Settings/OpenVRSettings.asset',
'Assets/XR/Settings/OpenVRSettings.asset.meta'
) | ForEach-Object {
$path = Join-Path $env:projectPath $_
if (Test-Path $path) {
Remove-Item $path -Force
}
}
- name: "Sanitize headless project (Windows)"
if: runner.os == 'Windows'
shell: pwsh
run: |
python .github/scripts/sanitize_headless_ci.py "${env:projectPath}"
- name: "Build Unity project"
timeout-minutes: 100
uses: BasisVR/unity-builder@main
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
with:
buildName: ${{ matrix.buildName }}
buildMethod: ${{ matrix.buildMethod }}
customParameters: ${{ matrix.customParameters }}
projectPath: ${{ env.projectPath }}
targetPlatform: ${{ matrix.targetPlatform }}
versioning: None
buildsPath: build/${{ matrix.buildOutput }}
linux64RemoveExecutableExtension: false
- name: "Rename Windows headless output folder"
if: matrix.targetPlatform == 'StandaloneWindows64'
shell: bash
run: |
sudo mv "build/${{ matrix.buildOutput }}/StandaloneWindows64" "build/${{ matrix.buildOutput }}/HeadlessWindows64"
sudo chown -R "$(id -u):$(id -g)" "build/${{ matrix.buildOutput }}/HeadlessWindows64"
- name: "Rename Linux headless output folder"
if: matrix.targetPlatform == 'StandaloneLinux64'
shell: bash
run: |
sudo mv "build/${{ matrix.buildOutput }}/StandaloneLinux64" "build/${{ matrix.buildOutput }}/${{ matrix.headlessFolderName }}"
sudo chown -R "$(id -u):$(id -g)" "build/${{ matrix.buildOutput }}/${{ matrix.headlessFolderName }}"
- name: "Write headless config.xml into artifact"
shell: bash
run: |
if [ "${{ matrix.targetPlatform }}" = "StandaloneWindows64" ]; then
data_dir="build/${{ matrix.buildOutput }}/${{ matrix.headlessFolderName }}/HeadlessWindowsServer_Data"
else
data_dir="build/${{ matrix.buildOutput }}/${{ matrix.headlessFolderName }}/HeadlessLinuxServer_Data"
fi
mkdir -p "$data_dir"
cat > "$data_dir/config.xml" <<'EOF'
<?xml version="1.0" encoding="utf-8"?>
<Configuration>
<Password>default_password</Password>
<Ip>server1.basisvr.org</Ip>
<Port>4296</Port>
<AvatarFileLocation></AvatarFileLocation>
<AvatarPassword></AvatarPassword>
<HealthCheckEnabled>false</HealthCheckEnabled>
<HealthCheckHost>127.0.0.1</HealthCheckHost>
<HealthCheckPort>10666</HealthCheckPort>
<HealthPath>/health</HealthPath>
<ReconnectEnabled>true</ReconnectEnabled>
<ReconnectDelaySeconds>5</ReconnectDelaySeconds>
<MaxReconnectAttempts>10</MaxReconnectAttempts>
</Configuration>
EOF
- name: "Upload headless artifact"
timeout-minutes: 5
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifactName }}
path: build/${{ matrix.buildOutput }}
headless-docker-linux:
name: Build & push headless Linux image (${{ matrix.archSuffix }})
runs-on: ubuntu-latest
needs: [headless-build]
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
include:
- artifactName: LinuxHeadlessAmd64
dockerPlatform: linux/amd64
archSuffix: amd64
artifactDir: HeadlessLinux64
- artifactName: LinuxHeadlessArm64
dockerPlatform: linux/arm64
archSuffix: arm64
artifactDir: HeadlessLinuxArm64
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download Linux headless artifact
uses: actions/download-artifact@v4
with:
name: ${{ matrix.artifactName }}
path: headless
- name: Replace libopus for amd64 headless artifact
if: matrix.archSuffix == 'amd64'
shell: bash
run: |
set -eux
plugin_dir="headless/${{ matrix.artifactDir }}/HeadlessLinuxServer_Data/Plugins"
test -f "$plugin_dir/opus.so"
rm -f "$plugin_dir/libopus.so"
cp "$plugin_dir/opus.so" "$plugin_dir/libopus.so"
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.HEADLESS_IMAGE_NAME }}
tags: |
type=raw,value=nightly-linux-${{ matrix.archSuffix }},enable=${{ github.ref == 'refs/heads/developer' }}
type=raw,value=latest-linux-${{ matrix.archSuffix }},enable=${{ github.ref == 'refs/heads/long-term-support' }}
type=sha,prefix={{branch}}-,suffix=-linux-${{ matrix.archSuffix }},format=short
type=ref,event=branch,suffix=-linux-${{ matrix.archSuffix }}
- name: Build and push headless Linux image
uses: docker/build-push-action@v5
id: build
with:
context: ./headless
file: ./.github/docker/headless/linux/Dockerfile
platforms: ${{ matrix.dockerPlatform }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
ARTIFACT_DIR=${{ matrix.artifactDir }}
- name: Image digest
run: 'echo "Headless Linux image pushed with digest: ${{ steps.build.outputs.digest }}"'
headless-docker-linux-manifest:
name: Publish headless Linux manifest
runs-on: ubuntu-latest
needs: [headless-docker-linux]
permissions:
contents: read
packages: write
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.HEADLESS_IMAGE_NAME }}
tags: |
type=raw,value=nightly-linux,enable=${{ github.ref == 'refs/heads/developer' }}
type=raw,value=latest-linux,enable=${{ github.ref == 'refs/heads/long-term-support' }}
type=sha,prefix={{branch}}-,suffix=-linux,format=short
type=ref,event=branch,suffix=-linux
- name: Create Linux multi-arch manifest
shell: bash
run: |
while IFS= read -r tag; do
[ -n "$tag" ] || continue
docker buildx imagetools create \
--tag "$tag" \
"${tag}-amd64" \
"${tag}-arm64"
done <<< "${{ steps.meta.outputs.tags }}"
headless-docker-windows:
name: Build & push headless Windows image
runs-on: ubuntu-latest
needs: [headless-build]
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download Windows headless artifact
uses: actions/download-artifact@v4
with:
name: WindowsHeadless
path: headless
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.HEADLESS_IMAGE_NAME }}
tags: |
type=raw,value=nightly-windows,enable=${{ github.ref == 'refs/heads/developer' }}
type=raw,value=latest-windows,enable=${{ github.ref == 'refs/heads/long-term-support' }}
type=sha,prefix={{branch}}-,suffix=-windows,format=short
type=ref,event=branch,suffix=-windows
- name: Build and push headless Windows image
uses: docker/build-push-action@v5
id: build
with:
context: ./headless
file: ./.github/docker/headless/windows/Dockerfile
platforms: windows/amd64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Image digest
run: 'echo "Headless Windows image pushed with digest: ${{ steps.build.outputs.digest }}"'