Skip to content

Commit d2a522d

Browse files
authored
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>
1 parent c4ca283 commit d2a522d

4 files changed

Lines changed: 82 additions & 28 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: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,59 @@ 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+
mkdir -p snap/prebuilt/meta/gui
127+
cp snap/local/term.desktop snap/prebuilt/meta/gui/term.desktop
128+
cp snap/local/icon.png snap/prebuilt/meta/gui/icon.png
129+
130+
python3 tasks/scripts/release.py get-version --snap > snap/prebuilt/version
131+
79132
- name: Build snap
80133
run: |
81134
set -euo pipefail

snapcraft.yaml

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -69,43 +69,44 @@ apps:
6969

7070
parts:
7171
openshell:
72-
plugin: rust
73-
rust-channel: "1.95.0"
74-
source: .
75-
build-packages:
76-
- build-essential
77-
- ca-certificates
78-
- clang
79-
- cmake
80-
- git
81-
- libclang-dev
82-
- libssl-dev
83-
- libz3-dev
84-
- pkg-config
85-
- python3
72+
plugin: nil
73+
source: ./snap/prebuilt
8674
override-pull: |
8775
craftctl default
88-
craftctl set version="$(python3 "$CRAFT_PROJECT_DIR/tasks/scripts/release.py" get-version --snap)"
76+
craftctl set version="$(cat "$CRAFT_PART_SRC/version")"
8977
override-build: |
9078
set -euo pipefail
9179
92-
cargo build --release --locked -p openshell-cli --features bundled-z3
93-
cargo build --release --locked -p openshell-server --bin openshell-gateway --features bundled-z3
94-
cargo build --release --locked -p openshell-sandbox --bin openshell-sandbox
80+
MISSING=()
81+
for bin in openshell openshell-gateway openshell-sandbox openshell-gateway-wrapper; do
82+
if [ ! -f "$CRAFT_PART_SRC/$bin" ]; then
83+
MISSING+=("$bin")
84+
fi
85+
done
9586
96-
install -D -m 0755 "$CRAFT_PART_BUILD/target/release/openshell" \
87+
if [ ${#MISSING[@]} -gt 0 ]; then
88+
printf '%s\n' \
89+
"ERROR: snap/prebuilt/ is incomplete:" \
90+
"${MISSING[@]/#/' - '}" \
91+
"" \
92+
"The snap build directory must be populated by CI before snapcraft pack." \
93+
>&2
94+
exit 1
95+
fi
96+
97+
install -D -m 0755 "$CRAFT_PART_SRC/openshell" \
9798
"$CRAFT_PART_INSTALL/bin/openshell"
98-
install -D -m 0755 "$CRAFT_PART_BUILD/target/release/openshell-gateway" \
99+
install -D -m 0755 "$CRAFT_PART_SRC/openshell-gateway" \
99100
"$CRAFT_PART_INSTALL/bin/openshell-gateway"
100-
install -D -m 0755 "$CRAFT_PART_BUILD/target/release/openshell-sandbox" \
101+
install -D -m 0755 "$CRAFT_PART_SRC/openshell-sandbox" \
101102
"$CRAFT_PART_INSTALL/bin/openshell-sandbox"
102-
install -D -m 0755 "$CRAFT_PROJECT_DIR/tasks/scripts/snap-gateway-wrapper.sh" \
103+
install -D -m 0755 "$CRAFT_PART_SRC/openshell-gateway-wrapper" \
103104
"$CRAFT_PART_INSTALL/bin/openshell-gateway-wrapper"
104-
install -D -m 0644 "$CRAFT_PROJECT_DIR/snap/local/term.desktop" \
105+
install -D -m 0644 "$CRAFT_PART_SRC/meta/gui/term.desktop" \
105106
"$CRAFT_PART_INSTALL/meta/gui/term.desktop"
106-
install -D -m 0644 "$CRAFT_PROJECT_DIR/snap/local/icon.png" \
107+
install -D -m 0644 "$CRAFT_PART_SRC/meta/gui/icon.png" \
107108
"$CRAFT_PART_INSTALL/meta/gui/icon.png"
108-
install -D -m 0644 "$CRAFT_PROJECT_DIR/LICENSE" \
109+
install -D -m 0644 "$CRAFT_PART_SRC/LICENSE" \
109110
"$CRAFT_PART_INSTALL/usr/share/doc/openshell/LICENSE"
110-
install -D -m 0644 "$CRAFT_PROJECT_DIR/README.md" \
111+
install -D -m 0644 "$CRAFT_PART_SRC/README.md" \
111112
"$CRAFT_PART_INSTALL/usr/share/doc/openshell/README.md"

0 commit comments

Comments
 (0)