feat(snap): switch to prebuilt binaries shared with other packages (#1651)

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 <zygmunt.krynicki@canonical.com>
This commit is contained in:
Zygmunt Krynicki
2026-06-09 18:40:42 -07:00
committed by GitHub
parent c4ca283c1a
commit d2a522dd34
4 changed files with 82 additions and 28 deletions
+1 -1
View File
@@ -654,7 +654,7 @@ jobs:
build-snap:
name: Build Snap
needs: [compute-versions]
needs: [compute-versions, build-cli-linux, build-gateway-binary-linux, build-supervisor-binary-linux]
uses: ./.github/workflows/snap-package.yml
with:
checkout-ref: ${{ github.sha }}
+1 -1
View File
@@ -690,7 +690,7 @@ jobs:
build-snap:
name: Build Snap
needs: [compute-versions]
needs: [compute-versions, build-cli-linux, build-gateway-binary-linux, build-supervisor-binary-linux]
uses: ./.github/workflows/snap-package.yml
with:
checkout-ref: ${{ inputs.tag || github.ref }}
+53
View File
@@ -76,6 +76,59 @@ jobs:
set -euo pipefail
sudo snap install snapcraft --classic
- name: Download prebuilt CLI binary
uses: actions/download-artifact@3e5f45b2cfb9172054b40e67214ff5f5447ce83dd # v8
with:
name: cli-linux-${{ matrix.arch }}
path: prebuilt/cli
- name: Download prebuilt gateway binary
uses: actions/download-artifact@3e5f45b2cfb9172054b40e67214ff5f5447ce83dd # v8
with:
name: gateway-binary-linux-${{ matrix.arch }}
path: prebuilt/gateway
- name: Download prebuilt sandbox binary
uses: actions/download-artifact@3e5f45b2cfb9172054b40e67214ff5f5447ce83dd # v8
with:
name: supervisor-binary-linux-${{ matrix.arch }}
path: prebuilt/sandbox
- name: Extract prebuilt binaries
run: |
set -euo pipefail
mkdir -p prebuilt/{cli,gateway,sandbox}
for d in cli gateway sandbox; do
for tarball in prebuilt/$d/*.tar.gz; do
if [ -f "$tarball" ]; then
tar -xzf "$tarball" -C "prebuilt/$d"
else
echo "WARNING: no tarball found in prebuilt/$d/" >&2
fi
done
done
ls -laR prebuilt/
- name: Prepare snap build directory
run: |
set -euo pipefail
mkdir -p snap/prebuilt
cp prebuilt/cli/openshell snap/prebuilt/openshell
cp prebuilt/gateway/openshell-gateway snap/prebuilt/openshell-gateway
cp prebuilt/sandbox/openshell-sandbox snap/prebuilt/openshell-sandbox
cp deploy/snap/bin/openshell-gateway-wrapper snap/prebuilt/
cp LICENSE snap/prebuilt/
cp README.md snap/prebuilt/
mkdir -p snap/prebuilt/meta/gui
cp snap/local/term.desktop snap/prebuilt/meta/gui/term.desktop
cp snap/local/icon.png snap/prebuilt/meta/gui/icon.png
python3 tasks/scripts/release.py get-version --snap > snap/prebuilt/version
- name: Build snap
run: |
set -euo pipefail
+27 -26
View File
@@ -69,43 +69,44 @@ apps:
parts:
openshell:
plugin: rust
rust-channel: "1.95.0"
source: .
build-packages:
- build-essential
- ca-certificates
- clang
- cmake
- git
- libclang-dev
- libssl-dev
- libz3-dev
- pkg-config
- python3
plugin: nil
source: ./snap/prebuilt
override-pull: |
craftctl default
craftctl set version="$(python3 "$CRAFT_PROJECT_DIR/tasks/scripts/release.py" get-version --snap)"
craftctl set version="$(cat "$CRAFT_PART_SRC/version")"
override-build: |
set -euo pipefail
cargo build --release --locked -p openshell-cli --features bundled-z3
cargo build --release --locked -p openshell-server --bin openshell-gateway --features bundled-z3
cargo build --release --locked -p openshell-sandbox --bin openshell-sandbox
MISSING=()
for bin in openshell openshell-gateway openshell-sandbox openshell-gateway-wrapper; do
if [ ! -f "$CRAFT_PART_SRC/$bin" ]; then
MISSING+=("$bin")
fi
done
install -D -m 0755 "$CRAFT_PART_BUILD/target/release/openshell" \
if [ ${#MISSING[@]} -gt 0 ]; then
printf '%s\n' \
"ERROR: snap/prebuilt/ is incomplete:" \
"${MISSING[@]/#/' - '}" \
"" \
"The snap build directory must be populated by CI before snapcraft pack." \
>&2
exit 1
fi
install -D -m 0755 "$CRAFT_PART_SRC/openshell" \
"$CRAFT_PART_INSTALL/bin/openshell"
install -D -m 0755 "$CRAFT_PART_BUILD/target/release/openshell-gateway" \
install -D -m 0755 "$CRAFT_PART_SRC/openshell-gateway" \
"$CRAFT_PART_INSTALL/bin/openshell-gateway"
install -D -m 0755 "$CRAFT_PART_BUILD/target/release/openshell-sandbox" \
install -D -m 0755 "$CRAFT_PART_SRC/openshell-sandbox" \
"$CRAFT_PART_INSTALL/bin/openshell-sandbox"
install -D -m 0755 "$CRAFT_PROJECT_DIR/tasks/scripts/snap-gateway-wrapper.sh" \
install -D -m 0755 "$CRAFT_PART_SRC/openshell-gateway-wrapper" \
"$CRAFT_PART_INSTALL/bin/openshell-gateway-wrapper"
install -D -m 0644 "$CRAFT_PROJECT_DIR/snap/local/term.desktop" \
install -D -m 0644 "$CRAFT_PART_SRC/meta/gui/term.desktop" \
"$CRAFT_PART_INSTALL/meta/gui/term.desktop"
install -D -m 0644 "$CRAFT_PROJECT_DIR/snap/local/icon.png" \
install -D -m 0644 "$CRAFT_PART_SRC/meta/gui/icon.png" \
"$CRAFT_PART_INSTALL/meta/gui/icon.png"
install -D -m 0644 "$CRAFT_PROJECT_DIR/LICENSE" \
install -D -m 0644 "$CRAFT_PART_SRC/LICENSE" \
"$CRAFT_PART_INSTALL/usr/share/doc/openshell/LICENSE"
install -D -m 0644 "$CRAFT_PROJECT_DIR/README.md" \
install -D -m 0644 "$CRAFT_PART_SRC/README.md" \
"$CRAFT_PART_INSTALL/usr/share/doc/openshell/README.md"