Skip to content

Commit ed9d470

Browse files
committed
feat(snap): switch to prebuilt binary model to avoid copying entire repo into LXD
Switch the snapcraft build from 'source: .' (which copies the full 20 GB repo including 18 GB of target/ and build artifacts into LXD) to 'source: ./snap/prebuilt' (~130 MB of only the binaries and metadata that snapcraft needs). The snap-package workflow now downloads the same cli, gateway, and supervisor binaries that other packaging jobs (deb, rpm, tarballs) use. A new 'Prepare snap build directory' step assembles snap/prebuilt/ with the 3 binaries, gateway wrapper script, LICENSE, README.md, and a precomputed version string — everything snapcraft needs without any source tree access. This addresses CI/CD Improvements (issue #1361) by reducing data transferred into the LXD sandbox by ~150x and eliminating the need for snapcraft to traverse the entire repository tree. Signed-off-by: Zygmunt Krynicki <[email protected]>
1 parent e98ea3e commit ed9d470

4 files changed

Lines changed: 77 additions & 26 deletions

File tree

‎.github/workflows/release-dev.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ jobs:
654654

655655
build-snap:
656656
name: Build Snap
657-
needs: [compute-versions]
657+
needs: [compute-versions, build-cli-linux, build-gateway-binary-linux, build-supervisor-binary-linux]
658658
uses: ./.github/workflows/snap-package.yml
659659
with:
660660
checkout-ref: ${{ github.sha }}

‎.github/workflows/release-tag.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ jobs:
690690

691691
build-snap:
692692
name: Build Snap
693-
needs: [compute-versions]
693+
needs: [compute-versions, build-cli-linux, build-gateway-binary-linux, build-supervisor-binary-linux]
694694
uses: ./.github/workflows/snap-package.yml
695695
with:
696696
checkout-ref: ${{ inputs.tag || github.ref }}

‎.github/workflows/snap-package.yml‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,62 @@ jobs:
7676
set -euo pipefail
7777
sudo snap install snapcraft --classic
7878
79+
- name: Download prebuilt CLI binary
80+
uses: actions/download-artifact@3e5f45b2cfb9172054b40e67214ff5f5447ce83dd # v8
81+
with:
82+
name: cli-linux-${{ matrix.arch }}
83+
path: prebuilt/cli
84+
85+
- name: Download prebuilt gateway binary
86+
uses: actions/download-artifact@3e5f45b2cfb9172054b40e67214ff5f5447ce83dd # v8
87+
with:
88+
name: gateway-binary-linux-${{ matrix.arch }}
89+
path: prebuilt/gateway
90+
91+
- name: Download prebuilt sandbox binary
92+
uses: actions/download-artifact@3e5f45b2cfb9172054b40e67214ff5f5447ce83dd # v8
93+
with:
94+
name: supervisor-binary-linux-${{ matrix.arch }}
95+
path: prebuilt/sandbox
96+
97+
- name: Extract prebuilt binaries
98+
run: |
99+
set -euo pipefail
100+
mkdir -p prebuilt/{cli,gateway,sandbox}
101+
102+
for d in cli gateway sandbox; do
103+
for tarball in prebuilt/$d/*.tar.gz; do
104+
if [ -f "$tarball" ]; then
105+
tar -xzf "$tarball" -C "prebuilt/$d"
106+
else
107+
echo "WARNING: no tarball found in prebuilt/$d/" >&2
108+
fi
109+
done
110+
done
111+
ls -laR prebuilt/
112+
113+
- name: Prepare snap build directory
114+
run: |
115+
set -euo pipefail
116+
mkdir -p snap/prebuilt
117+
118+
cp prebuilt/cli/openshell snap/prebuilt/openshell
119+
cp prebuilt/gateway/openshell-gateway snap/prebuilt/openshell-gateway
120+
cp prebuilt/sandbox/openshell-sandbox snap/prebuilt/openshell-sandbox
121+
122+
cp deploy/snap/bin/openshell-gateway-wrapper snap/prebuilt/
123+
cp LICENSE snap/prebuilt/
124+
cp README.md snap/prebuilt/
125+
126+
python3 tasks/scripts/release.py get-version --snap > snap/prebuilt/version
127+
79128
- name: Build snap
80129
run: |
81130
set -euo pipefail
82131
runtime_dir="/run/user/$(id -u)"
83132
sudo install -d -m 0700 -o "$(id -u)" -g "$(id -g)" "$runtime_dir"
84133
export XDG_RUNTIME_DIR="$runtime_dir"
134+
85135
sg lxd -c "XDG_RUNTIME_DIR=${runtime_dir} snapcraft pack -v"
86136
87137
- name: Upload snapcraft logs on failure

‎snapcraft.yaml‎

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -52,39 +52,40 @@ apps:
5252

5353
parts:
5454
openshell:
55-
plugin: rust
56-
rust-channel: "1.95.0"
57-
source: .
58-
build-packages:
59-
- build-essential
60-
- ca-certificates
61-
- clang
62-
- cmake
63-
- git
64-
- libclang-dev
65-
- libssl-dev
66-
- libz3-dev
67-
- pkg-config
68-
- python3
55+
plugin: nil
56+
source: ./snap/prebuilt
6957
override-pull: |
7058
craftctl default
71-
craftctl set version="$(python3 "$CRAFT_PROJECT_DIR/tasks/scripts/release.py" get-version --snap)"
59+
craftctl set version="$(cat "$CRAFT_PART_SRC/version")"
7260
override-build: |
7361
set -euo pipefail
7462
75-
cargo build --release --locked -p openshell-cli --features bundled-z3
76-
cargo build --release --locked -p openshell-server --bin openshell-gateway --features bundled-z3
77-
cargo build --release --locked -p openshell-sandbox --bin openshell-sandbox
63+
MISSING=()
64+
for bin in openshell openshell-gateway openshell-sandbox openshell-gateway-wrapper; do
65+
if [ ! -f "$CRAFT_PART_SRC/$bin" ]; then
66+
MISSING+=("$bin")
67+
fi
68+
done
7869
79-
install -D -m 0755 "$CRAFT_PART_BUILD/target/release/openshell" \
70+
if [ ${#MISSING[@]} -gt 0 ]; then
71+
printf '%s\n' \
72+
"ERROR: snap/prebuilt/ is incomplete:" \
73+
"${MISSING[@]/#/' - '}" \
74+
"" \
75+
"The snap build directory must be populated by CI before snapcraft pack." \
76+
>&2
77+
exit 1
78+
fi
79+
80+
install -D -m 0755 "$CRAFT_PART_SRC/openshell" \
8081
"$CRAFT_PART_INSTALL/bin/openshell"
81-
install -D -m 0755 "$CRAFT_PART_BUILD/target/release/openshell-gateway" \
82+
install -D -m 0755 "$CRAFT_PART_SRC/openshell-gateway" \
8283
"$CRAFT_PART_INSTALL/bin/openshell-gateway"
83-
install -D -m 0755 "$CRAFT_PART_BUILD/target/release/openshell-sandbox" \
84+
install -D -m 0755 "$CRAFT_PART_SRC/openshell-sandbox" \
8485
"$CRAFT_PART_INSTALL/bin/openshell-sandbox"
85-
install -D -m 0755 "$CRAFT_PROJECT_DIR/deploy/snap/bin/openshell-gateway-wrapper" \
86+
install -D -m 0755 "$CRAFT_PART_SRC/openshell-gateway-wrapper" \
8687
"$CRAFT_PART_INSTALL/bin/openshell-gateway-wrapper"
87-
install -D -m 0644 "$CRAFT_PROJECT_DIR/LICENSE" \
88+
install -D -m 0644 "$CRAFT_PART_SRC/LICENSE" \
8889
"$CRAFT_PART_INSTALL/usr/share/doc/openshell/LICENSE"
89-
install -D -m 0644 "$CRAFT_PROJECT_DIR/README.md" \
90+
install -D -m 0644 "$CRAFT_PART_SRC/README.md" \
9091
"$CRAFT_PART_INSTALL/usr/share/doc/openshell/README.md"

0 commit comments

Comments
 (0)