forked from LandSandBoat/server
-
Notifications
You must be signed in to change notification settings - Fork 0
200 lines (187 loc) · 8 KB
/
Copy pathdocker_build.yml
File metadata and controls
200 lines (187 loc) · 8 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
name: Reusable Docker Build Workflow
on:
workflow_call:
inputs:
os:
description: 'OS (Dockerfile) to build with.'
required: true
type: string
compiler:
description: 'Compiler to build with.'
required: true
type: string
compiler_version:
description: 'Compiler version to build with.'
required: false
type: string
clang_format_version:
description: 'Version of clang-format to use for devtools (sanity checks).'
required: false
type: string
default: '20'
build_type:
description: 'CMake build type.'
required: true
type: string
save_cache:
description: 'Cache build to GHA cache.'
required: false
type: boolean
default: false
build_modules:
description: 'Build with modules enabled.'
required: false
type: boolean
default: false
tracy:
description: 'Build with tracy enabled.'
required: false
type: boolean
default: false
upload_artifact:
description: 'Upload built image.'
required: false
type: boolean
default: false
publish:
description: 'Publish image to registry. Requires PUBLISH_DOCKER repo var to be set to a non-empty value and packages enabled.'
required: false
type: boolean
default: false
jobs:
Docker_Build:
name: ${{ format('docker-{0}, {1}{2}, {3}', inputs.os, inputs.compiler, inputs.compiler_version, inputs.build_type) }}
runs-on: ubuntu-latest
env:
BUILDX_NO_DEFAULT_ATTESTATIONS: 1 # https://github.com/orgs/community/discussions/45969
build_id: ${{ format('build-{0}-{1}-{2}-tracy{3}-pch{4}', inputs.os, inputs.compiler, inputs.build_type, inputs.tracy && 'ON' || 'OFF', inputs.build_type == 'Debug' && 'OFF' || 'ON') }}
ccache_id: ${{ format('ccache-{0}-{1}-{2}-tracy{3}-pch{4}', inputs.os, inputs.compiler, inputs.build_type, inputs.tracy && 'ON' || 'OFF', inputs.build_type == 'Debug' && 'OFF' || 'ON') }}
# Placeholder values. Actual values set in the first step.
REPO_OWNER: 'landsandboat'
REPO: 'landsandboat/server'
steps:
- name: Lowercase repository owner
run: |
echo "REPO_OWNER=${GITHUB_REPOSITORY_OWNER,,}" >>${GITHUB_ENV}
echo "REPO=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV}
- uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v6
with:
fetch-depth: 1
- name: Enable modules
if: ${{ inputs.build_modules }}
run: |
python3 <<EOF
with open("modules/init.txt", "w") as f:
f.write("custom\n")
f.write("era\n")
f.write("example\n")
f.write("renamer\n")
EOF
- uses: docker/setup-buildx-action@v4
id: setup_buildx
- name: Restore build cache
if: ${{ !inputs.save_cache }}
uses: actions/cache/restore@v5
env:
cmake_hash: ${{ hashFiles('**/CMakeLists.txt', '**/*.cmake') }}
source_hash: ${{ hashFiles('src/**/*', 'ext/**/*') }}
with:
path: |
${{ format('/tmp/{0}', env.build_id) }}
${{ format('/tmp/{0}', env.ccache_id) }}
key: ${{ format('buildcache-docker-{0}-{1}{2}-{3}-{4}-{5}', inputs.os, inputs.compiler, inputs.compiler_version, inputs.build_type, env.cmake_hash, env.source_hash) }}
restore-keys: |
${{ format('buildcache-docker-{0}-{1}{2}-{3}-{4}-', inputs.os, inputs.compiler, inputs.compiler_version, inputs.build_type, env.cmake_hash) }}
- name: Cache build
id: cache_build
if: ${{ inputs.save_cache }}
uses: actions/cache@v5
env:
cmake_hash: ${{ hashFiles('**/CMakeLists.txt', '**/*.cmake') }}
source_hash: ${{ hashFiles('src/**/*', 'ext/**/*') }}
with:
path: |
${{ format('/tmp/{0}', env.build_id) }}
${{ format('/tmp/{0}', env.ccache_id) }}
key: ${{ format('buildcache-docker-{0}-{1}{2}-{3}-{4}-{5}', inputs.os, inputs.compiler, inputs.compiler_version, inputs.build_type, env.cmake_hash, env.source_hash) }}
restore-keys: |
${{ format('buildcache-docker-{0}-{1}{2}-{3}-{4}-', inputs.os, inputs.compiler, inputs.compiler_version, inputs.build_type, env.cmake_hash) }}
- name: Inject cache into container
uses: reproducible-containers/buildkit-cache-dance@v3.4.0
with:
builder: ${{ steps.setup_buildx.outputs.name }}
cache-map: |
{
"${{ format('/tmp/{0}', env.build_id) }}":
{
"target": "/xiadmin/build",
"id": "${{ env.build_id }}",
"uid": "1000",
"gid": "1000"
},
"${{ format('/tmp/{0}', env.ccache_id) }}":
{
"target": "/xiadmin/.ccache",
"id": "${{ env.ccache_id }}",
"uid": "1000",
"gid": "1000"
}
}
skip-extraction: ${{ !inputs.save_cache }}
- name: Docker meta
id: docker-meta
uses: docker/metadata-action@v6
with:
images: ghcr.io/${{ env.REPO }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=branch
type=ref,event=pr
type=sha
labels: |
org.opencontainers.image.authors=LandSandBoat Dev Teams
org.opencontainers.image.title=LandSandBoat Server (${{ inputs.os }})
org.opencontainers.image.documentation=https://github.com/LandSandBoat/server/wiki
flavor: ${{ inputs.os != 'ubuntu' && format('suffix=-{0},onlatest=true', inputs.os) || '' }}
- name: Build devtools image
if: ${{ inputs.publish && vars.PUBLISH_DOCKER != '' }}
uses: docker/build-push-action@v7
with:
context: .
file: ${{ format('./docker/{0}.Dockerfile', inputs.os) }}
target: devtools
platforms: linux/amd64,linux/arm64,linux/arm/v7
build-args: |
LLVM_VERSION=${{ inputs.clang_format_version }}
push: true
tags: ${{ format('ghcr.io/{0}/devtools:{1}', env.REPO_OWNER, inputs.os) }}
- name: Docker build and push
uses: docker/build-push-action@v7
with:
context: .
file: ${{ format('./docker/{0}.Dockerfile', inputs.os) }}
push: ${{ inputs.publish && vars.PUBLISH_DOCKER != '' }}
tags: ${{ steps.docker-meta.outputs.tags }}
labels: ${{ steps.docker-meta.outputs.labels }}
annotations: ${{ steps.docker-meta.outputs.annotations }}
platforms: linux/amd64${{ (inputs.publish && vars.PUBLISH_DOCKER != '') && ',linux/arm64,linux/arm/v7' || '' }}
build-args: |
COMPILER=${{ inputs.compiler }}
${{ format('{0}={1}', startsWith(inputs.compiler, 'gcc') && 'GCC_VERSION' || 'LLVM_VERSION', inputs.compiler_version) }}
CMAKE_BUILD_TYPE=${{ inputs.build_type }}
TRACY_ENABLE=${{ inputs.tracy && 'ON' || 'OFF' }}
PCH_ENABLE=${{ inputs.build_type == 'Debug' && 'OFF' || 'ON' }}
REPO_URL=${{ github.server_url }}/${{ github.repository }}.git
COMMIT_SHA=${{ github.sha }}
outputs: ${{ (inputs.upload_artifact || (inputs.publish && vars.PUBLISH_DOCKER == '')) && format('type=docker,dest={0}/LSB_{1}_image_{2}.tar', runner.temp, inputs.os, github.sha) }}
- name: Archive image
if: ${{ inputs.upload_artifact || (inputs.publish && vars.PUBLISH_DOCKER == '') }}
uses: actions/upload-artifact@v7
with:
name: ${{ format('LSB_{0}_image_{1}', inputs.os, github.sha) }}
path: ${{ format('{0}/LSB_{1}_image_{2}.tar', runner.temp, inputs.os, github.sha) }}