-
Notifications
You must be signed in to change notification settings - Fork 7
278 lines (262 loc) · 10.7 KB
/
build-packages.yaml
File metadata and controls
278 lines (262 loc) · 10.7 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
name: Build packages.
on:
push:
tags:
- "v*.*.*"
workflow_dispatch:
permissions:
contents: read
jobs:
verify-version:
name: Verify tag version matches Cargo.toml
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Verify version
run: |
# Extract version from Cargo.toml
CARGO_VERSION=$(grep '^version =' Cargo.toml | head -1 | cut -d '"' -f2)
# Extract version from git tag (remove 'v' prefix)
TAG_VERSION=${GITHUB_REF_NAME#v}
echo "Cargo.toml version: $CARGO_VERSION"
echo "Git tag version: $TAG_VERSION"
# Compare versions
if [ "$CARGO_VERSION" != "$TAG_VERSION" ]; then
echo "Error: Version mismatch between Cargo.toml ($CARGO_VERSION) and git tag ($TAG_VERSION)"
exit 1
else
echo "Version verification successful: $CARGO_VERSION matches $TAG_VERSION"
fi
vendor:
name: Release vendor.tar.gz.
needs: [verify-version]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Create vendor.tar.gz
run: |
make vendor.tar.gz &&
make vendor-licenses.txt &&
sha256sum vendor.tar.gz > vendor-sha256sum.txt
- name: Release vendor.tar.gz
if: startsWith(github.ref, 'refs/tags/')
run: |
gh release upload ${{ github.ref_name }} ./vendor.tar.gz &&
gh release upload ${{ github.ref_name }} ./vendor-sha256sum.txt &&
gh release upload ${{ github.ref_name }} ./vendor-licenses.txt
env:
GITHUB_TOKEN: ${{ github.TOKEN }}
deb:
strategy:
matrix:
image: ["ubuntu:22.04", "ubuntu:24.04", "debian:12"]
name: Build deb packages.
needs: [verify-version]
runs-on: ubuntu-latest
container:
image: ${{ matrix.image }}
env:
DEBIAN_FRONTEND: noninteractive
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Install packages
run: |
apt-get update && apt-get install git cmake wget build-essential pkg-config libssl-dev clang g++ -y --option=Dpkg::Options::=--force-confdef &&
wget -q https://static.rust-lang.org/dist/rust-1.87.0-x86_64-unknown-linux-gnu.tar.gz -O /tmp/rust.tar.gz &&
cd /tmp && tar xf rust.tar.gz && ./rust-*-x86_64-unknown-linux-gnu/install.sh
- name: Build binaries in release mode
run: JEMALLOC_SYS_WITH_MALLOC_CONF="dirty_decay_ms:30000,muzzy_decay_ms:30000,background_thread:true,metadata_thp:auto" cargo build --release
- name: Prepare output dir
run: mkdir -p ./build_package/usr/bin && install ./target/release/pg_doorman ./build_package/usr/bin && install ./target/release/patroni_proxy ./build_package/usr/bin && mkdir -p ./out/
- name: Check versions
run: ./build_package/usr/bin/pg_doorman --version && ./build_package/usr/bin/patroni_proxy --version && cat /etc/debian_version
- name: Fix package name
run: |
export PACKAGE_NAME=pg_doorman-${{ matrix.image }}.deb &&
export PACKAGE_NAME=$(echo $PACKAGE_NAME | sed 's|:|-|g') &&
echo PACKAGE_NAME=$PACKAGE_NAME >> $GITHUB_ENV
- name: Package
uses: bpicode/github-action-fpm@7502b06a5a58390398d4002bd284f8cb3caae6eb
with:
fpm_opts: "--chdir ./build_package/ --deb-no-default-config-files --depends openssl --name pg-doorman --version ${{ github.ref_name }} -t deb -s dir"
- name: Prepare package
run: mkdir -p ./package/ && mv *.deb ./package/${{ env.PACKAGE_NAME }} && ls -lah ./package/
- name: Test package
run: dpkg -c ./package/${{ env.PACKAGE_NAME }} && dpkg -i ./package/${{ env.PACKAGE_NAME }} && pg_doorman --version
- name: Upload package
uses: actions/upload-artifact@v4
with:
name: ${{ env.PACKAGE_NAME }}
path: ./package/${{ env.PACKAGE_NAME }}
rpm:
strategy:
matrix:
image: ["rockylinux:9", "rockylinux:8", "almalinux:9"]
name: Build rpm packages.
needs: [verify-version]
runs-on: ubuntu-latest
container:
image: ${{ matrix.image }}
env:
DEBIAN_FRONTEND: noninteractive
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Install packages
run: |
yum install -y @"Development Tools" openssl-devel wget &&
wget -q https://static.rust-lang.org/dist/rust-1.87.0-x86_64-unknown-linux-gnu.tar.gz -O /tmp/rust.tar.gz &&
cd /tmp && tar xf rust.tar.gz && ./rust-*-x86_64-unknown-linux-gnu/install.sh
- name: Build binaries in release mode
run: JEMALLOC_SYS_WITH_MALLOC_CONF="dirty_decay_ms:30000,muzzy_decay_ms:30000,background_thread:true,metadata_thp:auto" cargo build --release
- name: Prepare output dir
run: mkdir -p ./build_package/usr/bin && install ./target/release/pg_doorman ./build_package/usr/bin && install ./target/release/patroni_proxy ./build_package/usr/bin && mkdir -p ./out/
- name: Check versions
run: ./build_package/usr/bin/pg_doorman --version && ./build_package/usr/bin/patroni_proxy --version && cat /etc/system-release
- name: Fix package name
run: |
export PACKAGE_NAME=pg_doorman-${{ matrix.image }}.rpm &&
export PACKAGE_NAME=$(echo $PACKAGE_NAME | sed 's|:|-|g') &&
echo PACKAGE_NAME=$PACKAGE_NAME >> $GITHUB_ENV
- name: Package
uses: bpicode/github-action-fpm@7502b06a5a58390398d4002bd284f8cb3caae6eb
with:
fpm_opts: "--chdir ./build_package/ --depends openssl --name pg-doorman --version ${{ github.ref_name }} -t rpm -s dir"
- name: Prepare package
run: mkdir -p ./package/ && mv *.rpm ./package/${{ env.PACKAGE_NAME }} && ls -lah ./package/
- name: Test package
run: rpm -qlp ./package/${{ env.PACKAGE_NAME }} && rpm -i ./package/${{ env.PACKAGE_NAME }} && pg_doorman --version
- name: Upload package
uses: actions/upload-artifact@v4
with:
name: ${{ env.PACKAGE_NAME }}
path: ./package/${{ env.PACKAGE_NAME }}
static-binary:
name: Build static musl binary.
needs: [verify-version]
runs-on: ubuntu-latest
container:
image: rust:1.87.0-alpine
env:
JEMALLOC_SYS_WITH_MALLOC_CONF: "dirty_decay_ms:30000,muzzy_decay_ms:30000,background_thread:true,metadata_thp:auto"
OPENSSL_STATIC: "1"
PKG_CONFIG_ALL_STATIC: "1"
steps:
- name: Install dependencies
run: apk add --no-cache musl-dev openssl-dev openssl-libs-static pkgconfig perl make git file
- name: Checkout Repository
uses: actions/checkout@v4
- name: Build static binary
run: cargo build --release --target x86_64-unknown-linux-musl
- name: Verify static linking
run: |
file target/x86_64-unknown-linux-musl/release/pg_doorman
file target/x86_64-unknown-linux-musl/release/patroni_proxy
file target/x86_64-unknown-linux-musl/release/pg_doorman | grep -E "static(-pie)? linked"
file target/x86_64-unknown-linux-musl/release/patroni_proxy | grep -E "static(-pie)? linked"
- name: Check versions
run: |
target/x86_64-unknown-linux-musl/release/pg_doorman --version
target/x86_64-unknown-linux-musl/release/patroni_proxy --version
- name: Prepare artifacts
run: |
mkdir -p ./artifacts
cp target/x86_64-unknown-linux-musl/release/pg_doorman ./artifacts/pg_doorman-linux-amd64-static
cp target/x86_64-unknown-linux-musl/release/patroni_proxy ./artifacts/patroni_proxy-linux-amd64-static
- name: Upload pg_doorman static binary
uses: actions/upload-artifact@v4
with:
name: pg_doorman-linux-amd64-static
path: ./artifacts/pg_doorman-linux-amd64-static
- name: Upload patroni_proxy static binary
uses: actions/upload-artifact@v4
with:
name: patroni_proxy-linux-amd64-static
path: ./artifacts/patroni_proxy-linux-amd64-static
release-packages:
name: Release packages.
needs: ['deb', 'rpm']
runs-on: ubuntu-latest
permissions:
contents: write
strategy:
matrix:
package:
- "pg_doorman-rockylinux-9.rpm"
- "pg_doorman-rockylinux-8.rpm"
- "pg_doorman-almalinux-9.rpm"
- "pg_doorman-ubuntu-22.04.deb"
- "pg_doorman-ubuntu-24.04.deb"
- "pg_doorman-debian-12.deb"
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Download package
uses: actions/download-artifact@v4
with:
name: "${{ matrix.package }}"
path: "./packages/"
- name: Release package
if: startsWith(github.ref, 'refs/tags/')
run: gh release upload ${{ github.ref_name }} ./packages/${{ matrix.package }}
env:
GITHUB_TOKEN: ${{ github.TOKEN }}
release-static-binaries:
name: Release static binaries.
needs: ['static-binary']
runs-on: ubuntu-latest
permissions:
contents: write
strategy:
matrix:
package:
- "pg_doorman-linux-amd64-static"
- "patroni_proxy-linux-amd64-static"
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Download package
uses: actions/download-artifact@v4
with:
name: "${{ matrix.package }}"
path: "./packages/"
- name: Release package
if: startsWith(github.ref, 'refs/tags/')
run: gh release upload ${{ github.ref_name }} ./packages/${{ matrix.package }}
env:
GITHUB_TOKEN: ${{ github.TOKEN }}
docker-image:
name: Build docker image and push to registry
needs: [verify-version]
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.TOKEN }}
- name: Build and push
id: docker-build
uses: docker/build-push-action@v6
with:
push: true
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
tags: |
ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:latest
ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ github.ref_name }}