Skip to content

Commit c3f429b

Browse files
SDAChesselezar
andauthored
ci(snap): build the snap in the snapcraft container instead of LXD (#5893)
The snap build launched an LXD instance, which first downloads its Ubuntu base image. That download can hang: a Release Dev run sat at "Creating new base instance from remote" for 49 minutes until it was cancelled, against the usual 3 to 6 minutes, and Pre-release builds the snap too. Build with Canonical's snapcraft image instead, on the same runners. It runs `snapcraft pack` on the container itself (SNAPCRAFT_BUILD_ENVIRONMENT=host), so no LXD or snapd setup is needed. The inputs are copied into a Docker volume, packed there, and the .snap and .comp files copied back out. Snapcraft's logs are bind-mounted to the workspace for the failure upload, which is now named per architecture. The pack step times out after 20 minutes. Refs #4554 Signed-off-by: Simon Scatton <sscatton@nvidia.com> Co-authored-by: Evan Lezar <elezar@nvidia.com>
1 parent 68b1796 commit c3f429b

1 file changed

Lines changed: 33 additions & 33 deletions

File tree

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

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -37,33 +37,6 @@ jobs:
3737
ref: ${{ inputs.checkout-ref }}
3838
fetch-depth: 0
3939

40-
- name: Install snapd
41-
run: |
42-
set -euo pipefail
43-
if ! command -v snapd >/dev/null 2>&1; then
44-
sudo apt-get update
45-
sudo apt-get install -y snapd
46-
fi
47-
sudo systemctl enable --now snapd.socket
48-
sudo systemctl start snapd
49-
sudo snap wait system seed.loaded
50-
51-
- name: Install LXD
52-
run: |
53-
set -euo pipefail
54-
sudo snap install lxd
55-
sudo usermod -aG lxd "$USER"
56-
sudo lxd waitready
57-
sudo lxd init --auto
58-
sudo iptables -P FORWARD ACCEPT
59-
sudo chgrp lxd /var/snap/lxd/common/lxd/unix.socket
60-
sudo chmod 660 /var/snap/lxd/common/lxd/unix.socket
61-
62-
- name: Install snapcraft
63-
run: |
64-
set -euo pipefail
65-
sudo snap install snapcraft --classic
66-
6740
- name: Download prebuilt CLI binary
6841
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
6942
with:
@@ -117,20 +90,47 @@ jobs:
11790
11891
python3 tasks/scripts/release.py get-version --snap > snap/prebuilt/version
11992
93+
# Canonical's snapcraft image builds on the container itself
94+
# (SNAPCRAFT_BUILD_ENVIRONMENT=host) and runs `snapcraft pack` in
95+
# /project, so no LXD instance or base image download is involved.
12096
- name: Build snap
97+
timeout-minutes: 20
98+
env:
99+
ARCH: ${{ matrix.arch }}
100+
SNAPCRAFT_IMAGE: ghcr.io/canonical/snapcraft:8_core24@sha256:f51fc5081f844bece0bb69d7b19a9c543f4666685da630dd9f9f7d0fb74e08f5
121101
run: |
122102
set -euo pipefail
123-
runtime_dir="/run/user/$(id -u)"
124-
sudo install -d -m 0700 -o "$(id -u)" -g "$(id -g)" "$runtime_dir"
125-
export XDG_RUNTIME_DIR="$runtime_dir"
126-
sg lxd -c "XDG_RUNTIME_DIR=${runtime_dir} snapcraft pack -v"
103+
volume="openshell-snap-${GITHUB_RUN_ID}-${ARCH}"
104+
docker volume create "${volume}" >/dev/null
105+
mkdir -p snapcraft-logs
106+
docker run --rm --platform "linux/${ARCH}" \
107+
--volume "${PWD}:/input:ro" \
108+
--volume "${volume}:/project" \
109+
--entrypoint /bin/sh \
110+
"${SNAPCRAFT_IMAGE}" \
111+
-c 'cp -a /input/snapcraft.yaml /input/snap /project/'
112+
docker run --rm --platform "linux/${ARCH}" \
113+
--volume "${volume}:/project" \
114+
--volume "${PWD}/snapcraft-logs:/root/.local/state/snapcraft/log" \
115+
"${SNAPCRAFT_IMAGE}"
116+
docker run --rm --platform "linux/${ARCH}" \
117+
--volume "${volume}:/project:ro" \
118+
--volume "${PWD}:/output" \
119+
--entrypoint /bin/sh \
120+
"${SNAPCRAFT_IMAGE}" \
121+
-c 'set -eu
122+
for artifact in /project/*.snap /project/*.comp; do
123+
[ -e "${artifact}" ] || continue
124+
cp "${artifact}" /output/
125+
chown "$1" "/output/${artifact##*/}"
126+
done' sh "$(id -u):$(id -g)"
127127
128128
- name: Upload snapcraft logs on failure
129129
if: failure()
130130
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
131131
with:
132-
name: snapcraft-logs
133-
path: "~/.local/state/snapcraft/log/snapcraft-*.log"
132+
name: snapcraft-logs-${{ matrix.arch }}
133+
path: snapcraft-logs/snapcraft-*.log
134134
retention-days: 7
135135

136136
- name: Capture snap filename

0 commit comments

Comments
 (0)