-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(spread): add support for spread tests
- Loading branch information
Showing
7 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[submodule "tools/external"] | ||
path = tools/external | ||
url = https://github.com/snapcore/snapd-testing-tools.git | ||
branch = main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
project: snapcraft-rocks | ||
|
||
# note: the `path` is inside /root because the docker snap has issues | ||
# mounting directories that are outside the user's home | ||
path: /root/snapcraft-rocks | ||
environment: | ||
PROJECT_PATH: /root/snapcraft-rocks | ||
SNAPD_TESTING_TOOLS: $PROJECT_PATH/tools/external/tools | ||
PATH: /snap/bin:$PATH:$SNAPD_TESTING_TOOLS:$PROJECT_PATH/tools/spread | ||
# This variable is used to set the base in multi-base projects | ||
SNAPCRAFT_BASE: core22 | ||
|
||
include: | ||
- tests/ | ||
- tools/ | ||
|
||
backends: | ||
google: | ||
key: '$(HOST: echo "$SPREAD_GOOGLE_KEY")' | ||
location: snapd-spread/us-east1-b | ||
halt-timeout: 2h | ||
systems: | ||
- ubuntu-20.04-64: | ||
workers: 2 | ||
storage: 40G | ||
- ubuntu-22.04-64: | ||
workers: 2 | ||
storage: 40G | ||
- fedora-37-64: | ||
workers: 2 | ||
storage: 40G | ||
|
||
prepare: | | ||
# if the 'tools' directory inside the submodule does not exist, then assume the submodule is empty | ||
if [[ ! -d "$SNAPD_TESTING_TOOLS" ]]; then | ||
echo "Cannot run spread because submodule 'snapd-testing-tools' is empty. Fetch with 'git submodule update --init' and rerun spread." | ||
exit 1 | ||
fi | ||
if os.query is-ubuntu; then | ||
tempfile="$(mktemp)" | ||
if ! apt-get update > "$tempfile" 2>&1; then | ||
cat "$tempfile" | ||
exit 1 | ||
fi | ||
fi | ||
tests.pkgs install snapd | ||
snap wait system seed.loaded | ||
# The /snap directory does not exist in some environments | ||
[ ! -d /snap ] && ln -s /var/lib/snapd/snap /snap | ||
# Hold snap refreshes for 24h. | ||
snap set system refresh.hold="$(date --date=tomorrow +%Y-%m-%dT%H:%M:%S%:z)" | ||
if ! snap watch --last=auto-refresh?; then | ||
journalctl -xe | ||
fi | ||
if ! snap watch --last=install?; then | ||
journalctl -xe | ||
fi | ||
if [ "$SPREAD_SYSTEM" = "fedora-37-64" ]; then | ||
# Latest docker snap needs a more recent version of snapd than Fedora ships | ||
# https://github.com/canonical/rockcraft/pull/277 | ||
snap install docker --channel=core18/stable | ||
else | ||
snap install docker | ||
fi | ||
# make sure docker is working | ||
retry -n 10 --wait 2 sh -c 'docker run --rm hello-world' | ||
# install rockcraft just to use its bundled skopeo | ||
snap install --classic --stable rockcraft | ||
load_snapcraft_rock | ||
restore-each: | | ||
# Cleanup after each task. | ||
rm -f *.snap | ||
suites: | ||
tests/spread/general/: | ||
summary: general tests that should work on all bases and Snapcraft versions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: hello-world | ||
version: "1.0" | ||
summary: test | ||
description: hello-world | ||
grade: devel | ||
confinement: strict | ||
base: SNAPCRAFT_BASE | ||
|
||
parts: | ||
hello-world: | ||
plugin: nil | ||
stage-packages: ["hello"] | ||
|
||
apps: | ||
hello-world: | ||
command: usr/bin/hello |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
summary: build & run a basic "hello world" snap | ||
|
||
execute: | | ||
# pack the snap | ||
run_snapcraft pack | ||
# install & run it | ||
snap install --dangerous hello-world_1.0_amd64.snap | ||
hello-world -g "hello-from-snap" | MATCH "hello-from-snap" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash | ||
|
||
# load_snapcraft_rock: helper to load the Snapcraft rock into docker. | ||
# | ||
# The rock is always loaded as "snapcraft-rock", regardless of supported base. | ||
|
||
if stat ${PROJECT_PATH}/tests/*.rock 2>/dev/null; then | ||
rockname=$(ls ${PROJECT_PATH}/tests/*.rock) | ||
/snap/rockcraft/current/bin/skopeo --insecure-policy copy oci-archive:${rockname} docker-daemon:snapcraft-rock:latest | ||
else | ||
echo "Expected a rock to exist in ${PROJECT_PATH}/tests/" | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
|
||
# run_snapcraft: helper to run Snapcraft inside a container. | ||
|
||
# replace the SNAPCRAFT_BASE token with the correct base for our Snapcraft image | ||
sed --in-place=.bak "s/SNAPCRAFT_BASE/$SNAPCRAFT_BASE/" snap/snapcraft.yaml | ||
docker run --rm -v `pwd`:/project snapcraft-rock:latest "$@" |