This repository has been archived by the owner on Oct 8, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 14
290 lines (264 loc) · 9.24 KB
/
build.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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
name: Build
on:
workflow_dispatch:
pull_request:
push:
tags:
- "v*.*.*"
env:
REGISTRY_IMAGE: stalwartlabs/jmap-server
jobs:
build:
name: Building for ${{ matrix.target }} on ${{ matrix.host_os }}
runs-on: ${{ matrix.host_os }}
if: '!cancelled()'
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
host_os: ubuntu-20.04
- target: x86_64-apple-darwin
host_os: macos-latest
- target: x86_64-pc-windows-msvc
host_os: windows-2022
#- target: aarch64-unknown-linux-gnu
# host_os: ubuntu-20.04
#- target: x86_64-unknown-linux-musl
# host_os: ubuntu-20.04
#- target: aarch64-unknown-linux-musl
# host_os: ubuntu-20.04
#- target: aarch64-apple-darwin
# host_os: macos-latest
#- target: aarch64-pc-windows-msvc
# host_os: windows-2022
#- target: aarch64-pc-windows-msvc
# host_os: windows-2022
#- target: arm-unknown-linux-musleabihf
# host_os: ubuntu-20.04
#- target: arm-unknown-linux-gnueabihf
# host_os: ubuntu-20.04
#- target: armv7-unknown-linux-musleabihf
# host_os: ubuntu-20.04
#- target: armv7-unknown-linux-gnueabihf
# host_os: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
with:
persist-credentials: false
submodules: recursive
- name: Install dependencies (Linux)
if: ${{ contains(matrix.host_os, 'ubuntu') }}
run: |
sudo apt-get update -y
sudo apt-get install -yq protobuf-compiler wget
wget https://github.com/apple/foundationdb/releases/download/7.1.0/foundationdb-clients_7.1.0-1_amd64.deb
sudo dpkg -i --force-architecture foundationdb-clients_7.1.0-1_amd64.deb
- name: Install dependencies (MacOs)
if: ${{ contains(matrix.host_os, 'macos') }}
run: |
brew install protobuf
brew install wget
wget https://github.com/apple/foundationdb/releases/download/7.1.32/FoundationDB-7.1.32_x86_64.pkg
sudo installer -allowUntrusted -dumplog -pkg FoundationDB-7.1.32_x86_64.pkg -target /
- name: Install dependencies (Windows)
if: ${{ contains(matrix.host_os, 'windows') }}
uses: arduino/setup-protoc@v1
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
override: true
target: ${{ matrix.target }}
toolchain: stable
- name: Rust Cache
uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.host_os }}-${{ matrix.target }}-jmap
- name: Building binary (Unix version)
if: ${{ !contains(matrix.host_os, 'windows') }}
run: |
cargo build --target=${{ matrix.target }} --no-default-features --features foundationdb --release
cd target/${{ matrix.target }}/release && tar czvf ../../../stalwart-jmap-foundationdb-${{ matrix.target }}.tar.gz stalwart-jmap && cd -
cargo build --target=${{ matrix.target }} --release
cd target/${{ matrix.target }}/release && tar czvf ../../../stalwart-jmap-sqlite-${{ matrix.target }}.tar.gz stalwart-jmap && cd -
- name: Building binary (Windows version)
if: ${{ contains(matrix.host_os, 'windows') }}
run: |
cargo build --target=${{ matrix.target }} --release
cd target/${{ matrix.target }}/release
7z a ../../../stalwart-jmap-sqlite-${{ matrix.target }}.zip stalwart-jmap.exe
cd -
- name: Publish Release
if: startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v1
with:
files: 'stalwart-*'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
cross_build:
runs-on: ubuntu-latest
name: Building for ${{ matrix.target }} on ${{ matrix.distro }}
if: '!cancelled()'
strategy:
matrix:
include:
- arch: aarch64
distro: ubuntu20.04
target: aarch64-unknown-linux-gnu
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: uraimo/run-on-arch-action@v2
name: Build artifact
id: build
with:
arch: ${{ matrix.arch }}
distro: ${{ matrix.distro }}
# Not required, but speeds up builds
githubToken: ${{ github.token }}
# Create an artifacts directory
setup: |
mkdir -p "${PWD}/artifacts"
# Mount the artifacts directory as /artifacts in the container
dockerRunArgs: |
--volume "${PWD}/artifacts:/artifacts"
# Pass some environment variables to the container
env: |
target: ${{ matrix.target }}
# The shell to run commands with in the container
shell: /bin/sh
install: |
apt-get update -yq
apt-get install -yq build-essential cmake protobuf-compiler wget curl
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable --profile minimal
run: |
export PATH="$HOME/.cargo/bin:$PATH"
cargo build --target=${target} --release
cd target/${target}/release
tar czvf /artifacts/stalwart-jmap-sqlite-${target}.tar.gz stalwart-jmap
cd -
- name: Move packages
run: |
mv ${PWD}/artifacts/* .
- name: Publish Release
if: startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v1
with:
files: 'stalwart-*'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build_docker:
needs:
- build
- cross_build
name: Build Docker image for ${{ matrix.platform }}
runs-on: ubuntu-latest
if: '!cancelled()'
strategy:
fail-fast: false
matrix:
platform:
- linux/amd64
- linux/arm64
steps:
-
name: Prepare
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
-
name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
-
name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY_IMAGE }}
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build and push by digest
id: build
uses: docker/build-push-action@v4
with:
context: .
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
#cache-from: type=registry,ref=${{ env.REGISTRY_IMAGE }}:buildcache-${{ env.PLATFORM_PAIR }}
#cache-to: type=registry,ref=s${{ env.REGISTRY_IMAGE }}:buildcache-${{ env.PLATFORM_PAIR }},mode=max
cache-from: type=gha,scope=build-${{ env.PLATFORM_PAIR }}
cache-to: type=gha,scope=build-${{ env.PLATFORM_PAIR }}
-
name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
-
name: Upload digest
uses: actions/upload-artifact@v3
with:
name: digests
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
merge_docker:
name: Merge and push Docker manifest
runs-on: ubuntu-latest
needs:
- build_docker
steps:
-
name: Download digests
uses: actions/download-artifact@v3
with:
name: digests
path: /tmp/digests
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY_IMAGE }}
-
name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
-
name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}