-
Notifications
You must be signed in to change notification settings - Fork 17
286 lines (234 loc) · 8.42 KB
/
release.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
name: Release
on:
release:
types: [created]
defaults:
run:
shell: bash
env:
tag_name: ${{ github.event.release.tag_name }}
package_resources: >-
README.md LICENSE-APACHE LICENSE-MIT
docs lang res tmpl
config.toml.dist
jobs:
release-linux:
strategy:
fail-fast: false
matrix:
# These are tags for rust-musl-cross.
# NOTE: Packages are named after the first component of the target,
# so these must be unique.
# NOTE: On Linux, we are limited mostly by arch support in Ring.
# See: https://github.com/briansmith/ring/blob/main/mk/cargo.sh
target:
- aarch64-musl
- x86_64-musl
runs-on: ubuntu-latest
container: "ghcr.io/rust-cross/rust-musl-cross:${{ matrix.target }}"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install GitHub CLI
run: |
curl -Lo gh.deb https://github.com/cli/cli/releases/download/v1.11.0/gh_1.11.0_linux_amd64.deb
dpkg -i gh.deb
rm gh.deb
- name: Build
run: cargo build --release --locked
- name: Package
env:
matrix_target: ${{ matrix.target }}
run: |
rm docs/build.md # Not useful for binaries
mkdir release-packages
broker_executable=target/*-unknown-linux-musl*/release/portier-broker
basename="Portier-Broker-${tag_name}-Linux-${matrix_target/-*/}"
mkdir $basename
cp $broker_executable $basename/
cp -r $package_resources $basename/
tar -czf "release-packages/$basename.tgz" $basename
- name: Upload
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Workaround for wonky ownership because we build in docker.
git config --global --add safe.directory "$PWD"
gh release upload "$tag_name" release-packages/*
release-macos:
runs-on: macos-latest
env:
build_targets: |
aarch64-apple-darwin
x86_64-apple-darwin
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Add targets
run: |
rustup target add $build_targets
- name: Build
run: |
for target in $build_targets; do
echo "::group::Building for $target"
if ! cargo build --release --locked --target $target; then
echo "::warning::Build for $target failed"
fi
echo "::endgroup::"
done
- name: Package
run: |
rm docs/build.md # Not useful for binaries
rm -r docs/systemd # Linux-specific
mkdir release-packages
basename="Portier-Broker-${tag_name}-Darwin"
mkdir $basename
lipo -create -output $basename/portier-broker ./target/*/release/portier-broker
codesign --force -s - $basename/portier-broker
cp -r $package_resources $basename/
tar -czf "release-packages/$basename.tgz" $basename
- name: Upload
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release upload "$tag_name" release-packages/*
release-windows:
runs-on: windows-latest
env:
# NOTE: Packages are named after the first component of the triple, so
# these must be unique.
build_targets: |
i686-pc-windows-msvc
x86_64-pc-windows-msvc
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
# Required for building AWS Libcrypto
- name: Install NASM
uses: ilammy/setup-nasm@v1
- name: Add targets
run: |
rustup target add $build_targets
- name: Build
run: |
for target in $build_targets; do
echo "::group::Building for $target"
if ! cargo build --release --locked --target $target; then
echo "::warning::Build for $target failed"
fi
echo "::endgroup::"
done
- name: Package
run: |
rm docs/build.md # Not useful for binaries
rm -r docs/systemd # Linux-specific
mkdir release-packages
for target in $build_targets; do
broker_executable="./target/$target/release/portier-broker.exe"
if [ ! -f "$broker_executable" ]; then
continue
fi
echo "::group::Packaging for $target"
basename="Portier-Broker-${tag_name}-Windows-${target/-*/}"
mkdir $basename
cp $broker_executable $basename/
cp -r $package_resources $basename/
7z a -tzip "release-packages/$basename.zip" $basename
echo "::endgroup::"
done
- name: Upload
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release upload "$tag_name" release-packages/*
release-linux-docker:
needs: release-linux
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
services:
# Scratch registry for building multiarch images.
registry:
image: registry:2
ports:
- 5000:5000
env:
scratch_repo: "localhost:5000/scratch"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: arm64
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
# Need network=host for the builder to contact our scratch registry.
driver: docker-container
driver-opts: network=host
- name: Build
run: |
# Map Docker arch to package name
declare -A build_targets
build_targets['amd64']='x86_64'
build_targets['arm64/v8']='aarch64'
declare -a scratch_tags
for docker_arch in "${!build_targets[@]}"; do
pkg_arch="${build_targets[$docker_arch]}"
# This download may fail if the release build failed for this
# platform. Continue without the platform, in that case.
echo "::group::Downloading package for $pkg_arch"
basename="Portier-Broker-${tag_name}-Linux-${pkg_arch}"
if ! wget "https://github.com/portier/portier-broker/releases/download/${tag_name}/${basename}.tgz"; then
echo "::endgroup::"
continue
fi
tar -xzf $basename.tgz
echo "::endgroup::"
echo "::group::Building image for $docker_arch"
# Reuse the Dockerfile base system, but copy in the release instead
# of rebuilding. This ensures we use the same binaries everywhere.
cp Dockerfile Dockerfile-release
echo "FROM base AS release" >> Dockerfile-release
echo "COPY ./$basename /opt/portier-broker" >> Dockerfile-release
scratch_tag="$scratch_repo:$pkg_arch"
docker buildx build \
--platform linux/$docker_arch \
--push --tag "$scratch_tag" \
-f Dockerfile-release .
scratch_tags+=( "$scratch_tag" )
echo "::endgroup::"
done
# Create a combined 'latest' tag with the multiarch image list.
docker buildx imagetools create -t "$scratch_repo" "${scratch_tags[@]}"
- name: Upload
run: |
# We used to use skopeo to copy the final multiarch image, but the
# current version installed on the GitHub runner is too old. Here we
# setup regclient.
curl -L https://github.com/regclient/regclient/releases/latest/download/regctl-linux-amd64 > "/tmp/regctl"
sudo install -t /usr/local/bin -o root -g root -m 0755 "/tmp/regctl"
# Setup the scratch registry.
regctl registry set --tls=disabled localhost:5000
# Login to GitHub Container Registry.
docker login --password-stdin \
--username '${{ github.actor }}' \
ghcr.io <<< '${{ secrets.GITHUB_TOKEN }}'
# Login to Docker Hub.
docker login --password-stdin \
--username '${{ secrets.DOCKERHUB_USERNAME }}' \
<<< '${{ secrets.DOCKERHUB_TOKEN }}'
# Publish a version-specific tag.
regctl image copy "$scratch_repo" "ghcr.io/portier/portier-broker:$tag_name"
regctl image copy "$scratch_repo" "docker.io/portier/broker:$tag_name"
# Publish a 'latest' tag.
if ! grep -q "test" <<< "$tag_name"; then
regctl image copy "$scratch_repo" "ghcr.io/portier/portier-broker:latest"
regctl image copy "$scratch_repo" "docker.io/portier/broker:latest"
fi