Skip to content
This repository was archived by the owner on Sep 10, 2024. It is now read-only.

Commit 533415f

Browse files
authored
Remove macOS binaries build in CI and remove cargo-zigbuild from Docker image (#2966)
* Upgrade Zig to 0.13.0 * Remove macOS builds & rework archives collection * dockerfile: stop using zig
1 parent 078939d commit 533415f

File tree

2 files changed

+75
-98
lines changed

2 files changed

+75
-98
lines changed

.github/workflows/build.yaml

Lines changed: 43 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ name: Build
22

33
on:
44
push:
5-
branches: [ main ]
5+
branches: [main]
66
tags:
7-
- 'v*'
7+
- "v*"
88

99
# Only run for pull requests if relevant files were changed
1010
pull_request:
11-
branches: [ main ]
11+
branches: [main]
1212
paths:
1313
- Dockerfile
1414
- docker-bake.hcl
@@ -33,9 +33,6 @@ jobs:
3333
name: Build binaries
3434
runs-on: ubuntu-22.04
3535

36-
env:
37-
SDKROOT: /opt/MacOSX11.3.sdk
38-
3936
permissions:
4037
contents: read
4138

@@ -54,22 +51,17 @@ jobs:
5451
targets: |
5552
x86_64-unknown-linux-gnu
5653
aarch64-unknown-linux-gnu
57-
x86_64-apple-darwin
58-
aarch64-apple-darwin
5954
6055
- name: Setup sccache
6156
uses: mozilla-actions/[email protected]
6257

6358
- name: Install zig
6459
uses: goto-bus-stop/setup-zig@v2
6560
with:
66-
version: 0.11.0
61+
version: 0.13.0
6762

6863
- name: Install cargo-zigbuild
69-
run: curl -L https://github.com/rust-cross/cargo-zigbuild/releases/download/v0.18.4/cargo-zigbuild-v0.18.4.x86_64-unknown-linux-musl.tar.gz | tar -z -x -C /usr/local/bin
70-
71-
- name: Download the macOS SDK
72-
run: curl -L "https://github.com/phracker/MacOSX-SDKs/releases/download/11.3/MacOSX11.3.sdk.tar.xz" | tar -J -x -C /opt
64+
run: curl -L https://github.com/rust-cross/cargo-zigbuild/releases/download/v0.19.1/cargo-zigbuild-v0.19.1.x86_64-unknown-linux-musl.tar.gz | tar -z -x -C /usr/local/bin
7365

7466
- name: Install frontend Node
7567
uses: actions/[email protected]
@@ -88,44 +80,45 @@ jobs:
8880
working-directory: ./policies
8981
run: make
9082

91-
- name: Force Cargo to create the target directory
92-
# Run `cargo clean` with an empty package name to force it to create the target directory
93-
# This fails because there is no package with an empty name, but the target directory is created
94-
# See https://github.com/rust-lang/cargo/issues/12441
95-
# This is needed because `cargo-zigbuild` sometimes (wrongly) creates the target directory
96-
# See https://github.com/rust-cross/cargo-zigbuild/issues/165
97-
run: |
98-
cargo clean -p '' \
99-
--target x86_64-unknown-linux-gnu \
100-
--target aarch64-unknown-linux-gnu \
101-
--target x86_64-apple-darwin \
102-
--target aarch64-apple-darwin \
103-
|| true
104-
10583
- name: Build the binary
10684
run: |
10785
cargo zigbuild \
10886
--release \
10987
--target x86_64-unknown-linux-gnu.2.17 \
11088
--target aarch64-unknown-linux-gnu.2.17 \
111-
--target x86_64-apple-darwin \
112-
--target aarch64-apple-darwin \
11389
--no-default-features \
11490
--features dist \
11591
-p mas-cli
11692
93+
- name: Create one archive per architecture
94+
run: |
95+
for arch in x86_64 aarch64; do
96+
# Create one directory per architecture
97+
mkdir -p dist/${arch}/share/
98+
# Copy the artifacts to the right place
99+
cp policies/policy.wasm dist/${arch}/share/policy.wasm
100+
cp frontend/dist/manifest.json dist/${arch}/share/manifest.json
101+
cp -r frontend/dist/ dist/${arch}/share/assets
102+
cp -r templates/ dist/${arch}/share/templates
103+
cp -r translations/ dist/${arch}/share/translations
104+
cp LICENSE dist/${arch}/LICENSE
105+
chmod -R u=rwX,go=rX dist/${arch}/
106+
107+
# Copy the binary to the right place
108+
cp target/${arch}-unknown-linux-gnu/release/mas-cli dist/${arch}/
109+
chmod u=rwx,go=rx dist/${arch}/mas-cli
110+
111+
# Create the archive
112+
tar -czvf mas-cli-${arch}-linux.tar.gz --owner=0 --group=0 -C dist/${arch}/ .
113+
done
114+
117115
- name: Upload the artifacts
118116
uses: actions/[email protected]
119117
with:
120118
name: binaries
121119
path: |
122-
target/*/release/mas-cli
123-
frontend/dist/
124-
policies/policy.wasm
125-
templates/
126-
translations/
127-
LICENSE
128-
120+
mas-cli-aarch64-linux.tar.gz
121+
mas-cli-x86_64-linux.tar.gz
129122
130123
build-image:
131124
name: Build and push Docker image
@@ -261,7 +254,6 @@ jobs:
261254
"${{ env.IMAGE }}@${{ fromJSON(steps.output.outputs.metadata).regular.digest }}" \
262255
"${{ env.IMAGE }}@${{ fromJSON(steps.output.outputs.metadata).debug.digest }}" \
263256
"${{ env.IMAGE_SYN2MAS }}@${{ fromJSON(steps.output.outputs.metadata).syn2mas.digest }}"
264-
265257
266258
syn2mas:
267259
name: Release syn2mas on NPM
@@ -291,7 +283,6 @@ jobs:
291283
provenance: true
292284
dry-run: ${{ !startsWith(github.ref, 'refs/tags/') }}
293285

294-
295286
release:
296287
name: Release
297288
if: startsWith(github.ref, 'refs/tags/')
@@ -307,38 +298,15 @@ jobs:
307298
name: binaries
308299
path: artifacts
309300

310-
- name: Prepare the archive directory
311-
run: |
312-
mkdir -p dist/share/
313-
mv artifacts/policies/policy.wasm dist/share/policy.wasm
314-
mv artifacts/frontend/dist/manifest.json dist/share/manifest.json
315-
mv artifacts/frontend/dist/ dist/share/assets
316-
mv artifacts/templates/ dist/share/templates
317-
mv artifacts/translations/ dist/share/translations
318-
mv artifacts/LICENSE dist/LICENSE
319-
chmod -R u=rwX,go=rX dist/
320-
321-
- name: Create the archives
322-
run: |
323-
for arch in x86_64 aarch64; do
324-
mv artifacts/target/${arch}-unknown-linux-gnu/release/mas-cli dist/mas-cli
325-
chmod u=rwx,go=rx dist/mas-cli
326-
tar -czvf mas-cli-${arch}-linux.tar.gz --owner=0 --group=0 -C dist/ .
327-
328-
mv artifacts/target/${arch}-apple-darwin/release/mas-cli dist/mas-cli
329-
chmod u=rwx,go=rx dist/mas-cli
330-
tar -czvf mas-cli-${arch}-macos.tar.gz --owner=0 --group=0 -C dist/ .
331-
done
332-
333301
- name: Prepare a release
334302
uses: softprops/action-gh-release@v2
335303
with:
336304
body: |
337305
### Docker image
338-
339-
Regular image:
340-
341-
- Digest:
306+
307+
Regular image:
308+
309+
- Digest:
342310
```
343311
${{ env.IMAGE }}@${{ fromJSON(needs.build-image.outputs.metadata).regular.digest }}
344312
```
@@ -347,10 +315,10 @@ jobs:
347315
${{ join(fromJSON(needs.build-image.outputs.metadata).regular.tags, '
348316
') }}
349317
```
350-
351-
Debug variant:
352-
353-
- Digest:
318+
319+
Debug variant:
320+
321+
- Digest:
354322
```
355323
${{ env.IMAGE }}@${{ fromJSON(needs.build-image.outputs.metadata).debug.digest }}
356324
```
@@ -359,10 +327,10 @@ jobs:
359327
${{ join(fromJSON(needs.build-image.outputs.metadata).debug.tags, '
360328
') }}
361329
```
362-
363-
`syn2mas` migration tool:
364-
365-
- Digest:
330+
331+
`syn2mas` migration tool:
332+
333+
- Digest:
366334
```
367335
${{ env.IMAGE_SYN2MAS }}@${{ fromJSON(needs.build-image.outputs.metadata).syn2mas.digest }}
368336
```
@@ -373,8 +341,6 @@ jobs:
373341
```
374342
375343
files: |
376-
mas-cli-aarch64-linux.tar.gz
377-
mas-cli-aarch64-macos.tar.gz
378-
mas-cli-x86_64-linux.tar.gz
379-
mas-cli-x86_64-macos.tar.gz
344+
artifacts/mas-cli-aarch64-linux.tar.gz
345+
artifacts/mas-cli-x86_64-linux.tar.gz
380346
draft: true

Dockerfile

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,10 @@
99
ARG DEBIAN_VERSION=12
1010
ARG DEBIAN_VERSION_NAME=bookworm
1111
ARG RUSTC_VERSION=1.80.0
12-
# XXX: Upgrade to 0.10.0 blocked by https://github.com/ziglang/zig/issues/10915#issuecomment-1354548110
13-
# XXX: Upgrade to 0.11.0 blocked by https://github.com/rust-cross/cargo-zigbuild/issues/162
14-
ARG ZIG_VERSION=0.9.1
15-
ARG NODEJS_VERSION=20.12.2
12+
ARG NODEJS_VERSION=20.15.0
1613
ARG OPA_VERSION=0.64.1
17-
ARG CARGO_AUDITABLE_VERSION=0.6.3
18-
ARG CARGO_CHEF_VERSION=0.1.66
19-
ARG CARGO_ZIGBUILD_VERSION=0.18.4
14+
ARG CARGO_AUDITABLE_VERSION=0.6.4
15+
ARG CARGO_CHEF_VERSION=0.1.67
2016

2117
##########################################
2218
## Build stage that builds the frontend ##
@@ -67,27 +63,18 @@ FROM --platform=${BUILDPLATFORM} docker.io/library/rust:${RUSTC_VERSION}-${DEBIA
6763

6864
ARG CARGO_AUDITABLE_VERSION
6965
ARG CARGO_CHEF_VERSION
70-
ARG CARGO_ZIGBUILD_VERSION
7166
ARG RUSTC_VERSION
72-
ARG ZIG_VERSION
7367

7468
# Make cargo use the git cli for fetching dependencies
7569
ENV CARGO_NET_GIT_FETCH_WITH_CLI=true
7670

77-
# Install pinned versions of cargo-chef, cargo-zigbuild and cargo-auditable
71+
# Install pinned versions of cargo-chef and cargo-auditable
7872
# Network access: to fetch dependencies
7973
RUN --network=default \
8074
cargo install --locked \
8175
cargo-chef@=${CARGO_CHEF_VERSION} \
82-
cargo-zigbuild@=${CARGO_ZIGBUILD_VERSION} \
8376
cargo-auditable@=${CARGO_AUDITABLE_VERSION}
8477

85-
# Download zig compiler for cross-compilation
86-
# Network access: to download zig
87-
RUN --network=default \
88-
curl -L "https://ziglang.org/download/${ZIG_VERSION}/zig-linux-$(uname -m)-${ZIG_VERSION}.tar.xz" | tar -J -x -C /usr/local && \
89-
ln -s "/usr/local/zig-linux-$(uname -m)-${ZIG_VERSION}/zig" /usr/local/bin/zig
90-
9178
# Install all cross-compilation targets
9279
# Network access: to download the targets
9380
RUN --network=default \
@@ -96,6 +83,31 @@ RUN --network=default \
9683
x86_64-unknown-linux-gnu \
9784
aarch64-unknown-linux-gnu
9885

86+
RUN --network=none \
87+
dpkg --add-architecture arm64 && \
88+
dpkg --add-architecture amd64
89+
90+
ARG BUILDPLATFORM
91+
92+
# Install cross-compilation toolchains for all supported targets
93+
# Network access: to install apt packages
94+
RUN --network=default \
95+
apt-get update && apt-get install -y \
96+
$(if [ "${BUILDPLATFORM}" != "linux/arm64" ]; then echo "g++-aarch64-linux-gnu"; fi) \
97+
$(if [ "${BUILDPLATFORM}" != "linux/amd64" ]; then echo "g++-x86-64-linux-gnu"; fi) \
98+
libc6-dev-amd64-cross \
99+
libc6-dev-arm64-cross \
100+
g++
101+
102+
# Setup the cross-compilation environment
103+
ENV \
104+
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc \
105+
CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc \
106+
CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++ \
107+
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-linux-gnu-gcc \
108+
CC_x86_64_unknown_linux_gnu=x86_64-linux-gnu-gcc \
109+
CXX_x86_64_unknown_linux_gnu=x86_64-linux-gnu-g++
110+
99111
# Set the working directory
100112
WORKDIR /app
101113

@@ -118,7 +130,6 @@ COPY --from=planner /app/recipe.json recipe.json
118130
# Network access: cargo-chef cook fetches the dependencies
119131
RUN --network=default \
120132
cargo chef cook \
121-
--zigbuild \
122133
--bin mas-cli \
123134
--release \
124135
--recipe-path recipe.json \
@@ -134,7 +145,7 @@ COPY ./crates /app/crates
134145
ENV SQLX_OFFLINE=true
135146
# Network access: cargo auditable needs it
136147
RUN --network=default \
137-
cargo auditable zigbuild \
148+
cargo auditable build \
138149
--locked \
139150
--release \
140151
--bin mas-cli \
@@ -162,7 +173,7 @@ COPY ./translations/ /share/translations
162173
##################################
163174
## Runtime stage, debug variant ##
164175
##################################
165-
FROM --platform=${TARGETPLATFORM} gcr.io/distroless/base-nossl-debian${DEBIAN_VERSION}:debug-nonroot AS debug
176+
FROM --platform=${TARGETPLATFORM} gcr.io/distroless/cc-debian${DEBIAN_VERSION}:debug-nonroot AS debug
166177

167178
ARG TARGETARCH
168179
COPY --from=builder /usr/local/bin/mas-cli-${TARGETARCH} /usr/local/bin/mas-cli
@@ -174,7 +185,7 @@ ENTRYPOINT ["/usr/local/bin/mas-cli"]
174185
###################
175186
## Runtime stage ##
176187
###################
177-
FROM --platform=${TARGETPLATFORM} gcr.io/distroless/base-nossl-debian${DEBIAN_VERSION}:nonroot
188+
FROM --platform=${TARGETPLATFORM} gcr.io/distroless/cc-debian${DEBIAN_VERSION}:nonroot
178189

179190
ARG TARGETARCH
180191
COPY --from=builder /usr/local/bin/mas-cli-${TARGETARCH} /usr/local/bin/mas-cli

0 commit comments

Comments
 (0)