Skip to content

Commit 9438dae

Browse files
committed
Refactored the Github release action to use the Docker builder
1 parent 7165f12 commit 9438dae

File tree

5 files changed

+194
-177
lines changed

5 files changed

+194
-177
lines changed

.github/workflows/release.yml

Lines changed: 125 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,95 @@ permissions:
1010
packages: write
1111

1212
jobs:
13-
build-binaries:
13+
# Builds the x64 and arm64 binaries for Linux, for all 3 crates, via the Docker builder
14+
build-binaries-linux:
1415
strategy:
1516
matrix:
1617
target:
17-
- x86_64-unknown-linux-gnu
18+
- amd64
19+
- arm64
20+
name:
21+
- commit-boost-cli
22+
- commit-boost-pbs
23+
- commit-boost-signer
24+
include:
25+
- target: amd64
26+
package-suffix: x86-64
27+
- target: arm64
28+
package-suffix: arm64
29+
- name: commit-boost-cli
30+
target-crate: cli
31+
- name: commit-boost-pbs
32+
target-crate: pbs
33+
- name: commit-boost-signer
34+
target-crate: signer
35+
runs-on: ubuntu-latest
36+
steps:
37+
- name: Checkout code
38+
uses: actions/checkout@v4
39+
with:
40+
ref: "stable"
41+
fetch-depth: 0
42+
submodules: true
43+
44+
- name: Log commit hash
45+
run: |
46+
echo "Releasing commit: $(git rev-parse HEAD)"
47+
48+
- name: Set up QEMU
49+
uses: docker/setup-qemu-action@v3
50+
51+
- name: Set up Docker Buildx
52+
uses: docker/setup-buildx-action@v3
53+
54+
- name: Login to GitHub Container Registry
55+
uses: docker/login-action@v3
56+
with:
57+
registry: ghcr.io
58+
username: ${{ github.actor }}
59+
password: ${{ secrets.GITHUB_TOKEN }}
60+
61+
- name: Build binary (Linux)
62+
uses: docker/build-push-action@v6
63+
with:
64+
context: .
65+
push: false
66+
platforms: linux/amd64,linux/arm64
67+
cache-from: type=registry,ref=ghcr.io/commit-boost/buildcache:${{ matrix.target-crate}}
68+
cache-to: type=registry,ref=ghcr.io/commit-boost/buildcache:${{ matrix.target-crate }},mode=max
69+
file: provisioning/build.Dockerfile
70+
outputs: type=local,dest=build
71+
build-args: |
72+
TARGET_CRATE=${{ matrix.name }}
73+
74+
- name: Package binary (Linux)
75+
run: |
76+
cd build/linux_${{ matrix.target }}
77+
tar -czvf ${{ matrix.name }}-${{ github.ref_name }}-linux_${{ matrix.package-suffix }}.tar.gz ${{ matrix.name }}
78+
mv ${{ matrix.name }}-${{ github.ref_name }}-linux_${{ matrix.package-suffix }}.tar.gz ../../
79+
80+
- name: Upload artifact
81+
uses: actions/upload-artifact@v4
82+
with:
83+
name: ${{ matrix.name }}-${{ github.ref_name }}-linux_${{ matrix.package-suffix }}
84+
path: |
85+
${{ matrix.name }}-${{ github.ref_name }}-linux_${{ matrix.package-suffix }}.tar.gz
86+
87+
# Builds the arm64 binaries for Darwin, for all 3 crates, natively
88+
build-binaries-darwin:
89+
strategy:
90+
matrix:
91+
target:
92+
# x64 requires macos-latest-large which is not available in the free tier
1893
# - x86_64-apple-darwin
1994
- aarch64-apple-darwin
2095
name:
2196
- commit-boost-cli
2297
- commit-boost-pbs
2398
- commit-boost-signer
2499
include:
25-
- target: x86_64-unknown-linux-gnu
26-
os: ubuntu-latest
27100
# - target: x86_64-apple-darwin
28-
# os: macos-latest
101+
# os: macos-latest-large
29102
- target: aarch64-apple-darwin
30103
os: macos-latest
31104
runs-on: ${{ matrix.os }}
@@ -41,6 +114,12 @@ jobs:
41114
run: |
42115
echo "Releasing commit: $(git rev-parse HEAD)"
43116
117+
- name: Install Protoc
118+
run:
119+
# Brew's version is much more up to date than the Linux ones, and installing the latest via script runs into curl issues so for now, brew's easier to use
120+
# provisioning/protoc.sh
121+
brew install protobuf
122+
44123
- name: Cache Cargo registry
45124
uses: actions/cache@v3
46125
with:
@@ -63,48 +142,25 @@ jobs:
63142
${{ runner.os }}-cargo-build-${{ matrix.target }}-
64143
${{ runner.os }}-cargo-build-
65144
66-
- name: Install protoc (Ubuntu)
67-
if: runner.os == 'Linux'
68-
run: sudo apt-get install protobuf-compiler
69-
70-
- name: Install protoc (macOS)
71-
if: runner.os == 'macOS'
72-
run: brew install protobuf
73-
74-
- name: Set up Rust
75-
uses: actions-rs/toolchain@v1
76-
with:
77-
profile: minimal
78-
toolchain: stable
79-
override: true
80-
target: ${{ matrix.target }}
81-
82-
- name: Build binary
145+
- name: Build binary (Darwin)
83146
run: cargo build --release --target ${{ matrix.target }} --bin ${{ matrix.name }}
84-
env:
85-
CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER: gcc
86147

87148
- name: Package binary (Unix)
88-
if: runner.os != 'Windows'
89149
run: |
90150
cd target/${{ matrix.target }}/release
91151
tar -czvf ${{ matrix.name }}-${{ github.ref_name }}-${{ matrix.target }}.tar.gz ${{ matrix.name }}
92152
mv ${{ matrix.name }}-${{ github.ref_name }}-${{ matrix.target }}.tar.gz ../../../
93153
94-
- name: Package binary (Windows)
95-
if: runner.os == 'Windows'
96-
run: |
97-
7z a ${{ matrix.name }}-${{ github.ref_name }}-${{ matrix.target }}.zip target\${{ matrix.target }}\release\${{ matrix.name }}.exe
98-
99154
- name: Upload artifact
100155
uses: actions/upload-artifact@v4
101156
with:
102157
name: ${{ matrix.name }}-${{ github.ref_name }}-${{ matrix.target }}
103158
path: |
104-
${{ matrix.name }}-${{ github.ref_name }}-${{ matrix.target }}.${{ runner.os == 'Windows' && 'zip' || 'tar.gz' }}
159+
${{ matrix.name }}-${{ github.ref_name }}-${{ matrix.target }}.tar.gz
105160
161+
# Builds the PBS Docker image
106162
build-and-push-pbs-docker:
107-
needs: [build-binaries]
163+
needs: [build-binaries-linux]
108164
runs-on: ubuntu-latest
109165
steps:
110166
- name: Checkout code
@@ -114,6 +170,20 @@ jobs:
114170
fetch-depth: 0
115171
submodules: true
116172

173+
- name: Download binary archives
174+
uses: actions/download-artifact@v4
175+
with:
176+
path: ./artifacts
177+
pattern: "commit-boost-*"
178+
179+
- name: Extract binaries
180+
run: |
181+
mkdir -p ./artifacts/bin
182+
tar -xzf ./artifacts/commit-boost-pbs-${{ github.ref_name }}-linux_x86-64/commit-boost-pbs-${{ github.ref_name }}-linux_x86-64.tar.gz -C ./artifacts/bin
183+
mv ./artifacts/bin/commit-boost-pbs ./artifacts/bin/commit-boost-pbs-linux-amd64
184+
tar -xzf ./artifacts/commit-boost-pbs-${{ github.ref_name }}-linux_arm64/commit-boost-pbs-${{ github.ref_name }}-linux_arm64.tar.gz -C ./artifacts/bin
185+
mv ./artifacts/bin/commit-boost-pbs ./artifacts/bin/commit-boost-pbs-linux-arm64
186+
117187
- name: Set up QEMU
118188
uses: docker/setup-qemu-action@v3
119189

@@ -133,15 +203,18 @@ jobs:
133203
context: .
134204
push: true
135205
platforms: linux/amd64,linux/arm64
206+
build-args: |
207+
BINARIES_PATH=./artifacts/bin
136208
tags: |
137209
ghcr.io/commit-boost/pbs:${{ github.ref_name }}
138210
${{ !contains(github.ref_name, 'rc') && 'ghcr.io/commit-boost/pbs:latest' || '' }}
139211
cache-from: type=registry,ref=ghcr.io/commit-boost/pbs:buildcache
140212
cache-to: type=registry,ref=ghcr.io/commit-boost/pbs:buildcache,mode=max
141213
file: provisioning/pbs.Dockerfile
142214

215+
# Builds the Signer Docker image
143216
build-and-push-signer-docker:
144-
needs: [build-binaries]
217+
needs: [build-binaries-linux]
145218
runs-on: ubuntu-latest
146219
steps:
147220
- name: Checkout code
@@ -151,6 +224,20 @@ jobs:
151224
fetch-depth: 0
152225
submodules: true
153226

227+
- name: Download binary archives
228+
uses: actions/download-artifact@v4
229+
with:
230+
path: ./artifacts
231+
pattern: "commit-boost-*"
232+
233+
- name: Extract binaries
234+
run: |
235+
mkdir -p ./artifacts/bin
236+
tar -xzf ./artifacts/commit-boost-signer-${{ github.ref_name }}-linux_x86-64/commit-boost-signer-${{ github.ref_name }}-linux_x86-64.tar.gz -C ./artifacts/bin
237+
mv ./artifacts/bin/commit-boost-signer ./artifacts/bin/commit-boost-signer-linux-amd64
238+
tar -xzf ./artifacts/commit-boost-signer-${{ github.ref_name }}-linux_arm64/commit-boost-signer-${{ github.ref_name }}-linux_arm64.tar.gz -C ./artifacts/bin
239+
mv ./artifacts/bin/commit-boost-signer ./artifacts/bin/commit-boost-signer-linux-arm64
240+
154241
- name: Set up QEMU
155242
uses: docker/setup-qemu-action@v3
156243

@@ -170,16 +257,20 @@ jobs:
170257
context: .
171258
push: true
172259
platforms: linux/amd64,linux/arm64
260+
build-args: |
261+
BINARIES_PATH=./artifacts/bin
173262
tags: |
174263
ghcr.io/commit-boost/signer:${{ github.ref_name }}
175264
${{ !contains(github.ref_name, 'rc') && 'ghcr.io/commit-boost/signer:latest' || '' }}
176265
cache-from: type=registry,ref=ghcr.io/commit-boost/signer:buildcache
177266
cache-to: type=registry,ref=ghcr.io/commit-boost/signer:buildcache,mode=max
178267
file: provisioning/signer.Dockerfile
179268

269+
# Creates a draft release on GitHub with the binaries
180270
finalize-release:
181271
needs:
182-
- build-binaries
272+
- build-binaries-linux
273+
- build-binaries-darwin
183274
- build-and-push-pbs-docker
184275
- build-and-push-signer-docker
185276
runs-on: ubuntu-latest

provisioning/build.Dockerfile

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,6 @@ RUN test -n "$TARGET_CRATE" || (echo "TARGET_CRATE must be set to the service /
1414
ENV BUILD_VAR_SCRIPT=/tmp/env.sh
1515
COPY --from=planner /app/recipe.json recipe.json
1616

17-
# Get the latest Protoc since the one in the Debian repo is incredibly old
18-
RUN apt update && apt install -y unzip curl ca-certificates && \
19-
PROTOC_VERSION=$(curl -s "https://api.github.com/repos/protocolbuffers/protobuf/releases/latest" | grep -Po '"tag_name": "v\K[0-9.]+') && \
20-
if [ "$BUILDPLATFORM" = "linux/amd64" ]; then \
21-
PROTOC_ARCH=x86_64; \
22-
elif [ "$BUILDPLATFORM" = "linux/arm64" ]; then \
23-
PROTOC_ARCH=aarch_64; \
24-
else \
25-
echo "${BUILDPLATFORM} is not supported."; \
26-
exit 1; \
27-
fi && \
28-
curl -Lo protoc.zip https://github.com/protocolbuffers/protobuf/releases/latest/download/protoc-$PROTOC_VERSION-linux-$PROTOC_ARCH.zip && \
29-
unzip -q protoc.zip bin/protoc -d /usr && \
30-
unzip -q protoc.zip "include/google/*" -d /usr && \
31-
chmod a+x /usr/bin/protoc && \
32-
rm -rf protoc.zip
33-
3417
# Set up the build environment for cross-compilation if needed
3518
RUN if [ "$BUILDPLATFORM" = "linux/amd64" -a "$TARGETARCH" = "arm64" ]; then \
3619
# We're on x64, cross-compiling for arm64
@@ -90,6 +73,10 @@ RUN if [ -f ${BUILD_VAR_SCRIPT} ]; then \
9073
export GIT_HASH=$(git rev-parse HEAD) && \
9174
cargo chef cook ${TARGET_FLAG} --release --recipe-path recipe.json ${FEATURE_OPENSSL_VENDORED}
9275

76+
# Get the latest Protoc since the one in the Debian repo is incredibly old
77+
COPY provisioning/protoc.sh provisioning/protoc.sh
78+
RUN provisioning/protoc.sh
79+
9380
# Now we can copy the source files - chef cook wants to run before this step
9481
COPY . .
9582

provisioning/cli.Dockerfile

Whitespace-only changes.

provisioning/protoc.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/sh
2+
3+
# This script installs the latest version of protoc (Protocol Buffers Compiler) from the official GitHub repository.
4+
5+
# Print a failure message to stderr and exit
6+
fail() {
7+
MESSAGE=$1
8+
RED='\033[0;31m'
9+
RESET='\033[;0m'
10+
>&2 echo -e "\n${RED}**ERROR**\n$MESSAGE${RESET}\n"
11+
exit 1
12+
}
13+
14+
# Get the OS
15+
case "$(uname)" in
16+
Darwin*)
17+
PROTOC_OS="osx" ;
18+
TARGET_DIR="/opt/homebrew" ; # Emulating a homebrew install so we don't need elevated permissions
19+
# Darwin comes with unzip and curl already
20+
brew install jq ;;
21+
Linux*)
22+
PROTOC_OS="linux" ;
23+
TARGET_DIR="/usr" ; # Assumes the script is run as root or the user can do it manually
24+
apt update && apt install -y unzip curl ca-certificates jq ;;
25+
*)
26+
echo "Unsupported OS: $(uname)" ;
27+
exit 1 ;;
28+
esac
29+
30+
# Get the architecture
31+
case "$(uname -m)" in
32+
x86_64) PROTOC_ARCH="x86_64" ;;
33+
aarch64) PROTOC_ARCH="aarch_64" ;;
34+
arm64) PROTOC_ARCH="aarch_64" ;;
35+
*) echo "Unsupported architecture: [$(uname -m)]"; exit 1 ;;
36+
esac
37+
38+
# Get the latest version
39+
PROTOC_RAW_VERSION=$(curl --retry 10 --retry-delay 2 --retry-all-errors -fsL "https://api.github.com/repos/protocolbuffers/protobuf/releases/latest" | jq -r .tag_name) || fail "Failed to get the latest version of protoc"
40+
if [ "$PROTOC_RAW_VERSION" = "null" ]; then
41+
fail "Failed to get the latest version of protoc"
42+
fi
43+
echo "Latest version of protoc: [$PROTOC_RAW_VERSION]"
44+
PROTOC_VERSION=$(echo $PROTOC_RAW_VERSION | sed 's/^v//') || fail "Failed to parse the latest version of protoc"
45+
if [ -z "$PROTOC_VERSION" ]; then
46+
fail "Latest version of protoc was empty"
47+
fi
48+
49+
echo "Installing protoc: $PROTOC_VERSION-$PROTOC_OS-$PROTOC_ARCH"
50+
51+
# Download and install protoc
52+
curl --retry 10 --retry-delay 2 --retry-all-errors -fsLo protoc.zip https://github.com/protocolbuffers/protobuf/releases/latest/download/protoc-$PROTOC_VERSION-$PROTOC_OS-$PROTOC_ARCH.zip || fail "Failed to download protoc"
53+
unzip -q protoc.zip bin/protoc -d $TARGET_DIR || fail "Failed to unzip protoc"
54+
unzip -q protoc.zip "include/google/*" -d $TARGET_DIR || fail "Failed to unzip protoc includes"
55+
chmod a+x $TARGET_DIR/bin/protoc || fail "Failed to set executable permissions for protoc"
56+
rm -rf protoc.zip || fail "Failed to remove protoc zip file"
57+
echo "protoc ${PROTOC_VERSION} installed successfully for ${PROTOC_OS} ${PROTOC_ARCH}"

0 commit comments

Comments
 (0)