Skip to content

Commit 59164a1

Browse files
authored
Merge pull request #10 from ted-gould/feat/snap-ci-test
Feat/snap ci test
2 parents 3905ddc + ee9eff0 commit 59164a1

File tree

2 files changed

+163
-0
lines changed

2 files changed

+163
-0
lines changed
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# Expected Output for Snap CI Job (`snap-test`)
2+
3+
This document outlines the expected output for the key commands executed in the `snap-test` CI job defined in `ci.yml`. This is intended to help users and developers understand the build and deployment process of the xTeVe snap.
4+
5+
**Note:** The exact output for some commands (like `lxd init` or `snapcraft`) can be verbose and might vary slightly between runner environments or versions. This guide focuses on the key indicators of success.
6+
7+
## 1. Install snapcraft and lxd
8+
9+
Commands:
10+
```
11+
sudo apt-get update
12+
sudo apt-get install -y qemu-kvm
13+
sudo snap install snapcraft --classic
14+
sudo snap install lxd
15+
```
16+
17+
Expected output:
18+
- Standard package installation messages from `apt-get` for `qemu-kvm`.
19+
- Successful installation messages from `snap` for `snapcraft` and `lxd`.
20+
- Example snippet (actual output will be much longer):
21+
```
22+
... (apt output for qemu-kvm) ...
23+
snap "snapcraft" installed
24+
snap "lxd" installed
25+
```
26+
27+
## 2. Configure LXD Group
28+
29+
Commands:
30+
```bash
31+
sudo groupadd --system lxd || true
32+
sudo usermod -a -G lxd $USER || true
33+
```
34+
35+
Expected output:
36+
- These commands typically don't produce output if successful unless the group or user membership is actually changed.
37+
- `groupadd: group 'lxd' already exists` (if it exists, due to `|| true`)
38+
- (No output if user is already in group or successfully added, due to `|| true`)
39+
- A comment in the CI script notes that `sg lxd -c "snapcraft"` handles the new group membership for the build step.
40+
41+
## 3. Initialize LXD
42+
43+
Command: `sudo lxd init --auto`
44+
45+
Expected output:
46+
- Messages indicating successful LXD initialization.
47+
- Example snippet:
48+
```
49+
If you're unsure, go with the defaults.
50+
Would you like to use LXD clustering? (yes/no) [default=no]:
51+
Do you want to configure a new storage pool? (yes/no) [default=yes]:
52+
Name of the new storage pool [default=default]:
53+
Name of the storage backend to use (btrfs, dir, lvm, zfs) [default=zfs]: dir
54+
Would you like to connect to a MAAS server? (yes/no) [default=no]:
55+
Would you like to create a new local network bridge? (yes/no) [default=yes]:
56+
What should the new bridge be called? [default=lxdbr0]:
57+
What IPv4 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]:
58+
What IPv6 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]:
59+
Would you like LXD to be available over the network? (yes/no) [default=no]:
60+
Would you like stale cached images to be updated automatically? (yes/no) [default=yes]:
61+
Would you like a YAML representation of your LXD configuration to be printed? (yes/no) [default=no]:
62+
```
63+
*(Note: `--auto` might produce less interactive output, but should indicate success)*
64+
65+
## 4. Build the snap
66+
67+
Command: `sudo snapcraft --destructive-mode`
68+
*(Note: `--destructive-mode` runs the build process directly on the host machine, not within an LXD container.)*
69+
70+
Expected output:
71+
- `snapcraft` build logs, showing progress.
72+
- Indication of steps like `pull`, `build`, `stage`, `prime`.
73+
- A final message indicating successful snap creation.
74+
- Example snippet of success:
75+
```
76+
...
77+
Snapped <snap-name>_<version>_<arch>.snap
78+
```
79+
For xTeVe, this would look something like:
80+
```
81+
Snapped xteve_X.Y.Z_amd64.snap
82+
```
83+
84+
## 5. Install the snap
85+
86+
Command: `sudo snap install --dangerous xteve*.snap`
87+
88+
Expected output:
89+
- Message indicating the snap was installed.
90+
- Example:
91+
```
92+
xteve <version> installed
93+
```
94+
95+
## 6. Check service status and dump logs
96+
97+
Commands:
98+
```bash
99+
echo "--- Checking xteve service status ---"
100+
snap services xteve
101+
echo "--- Dumping xteve service logs ---"
102+
sudo snap logs xteve || echo "No logs yet or logs not accessible"
103+
echo "--- Verifying xteve service is active ---"
104+
snap services xteve | grep -E "^xteve\.xteve\s+.*active"
105+
```
106+
107+
Expected output:
108+
109+
```
110+
--- Checking xteve service status ---
111+
Service Startup Current Notes
112+
xteve.xteve enabled active -
113+
114+
--- Dumping xteve service logs ---
115+
YYYY-MM-DDTHH:MM:SSZ xteve.daemon[PID]: <Log message 1 from xteve>
116+
YYYY-MM-DDTHH:MM:SSZ xteve.daemon[PID]: <Log message 2 from xteve>
117+
... (more logs) ...
118+
119+
--- Verifying xteve service is active ---
120+
xteve.xteve enabled active -
121+
```
122+
123+
- **`snap services xteve`**: Shows the `xteve.xteve` service as `enabled` and `active`. (Note: `snap services <snapname>` lists services associated with the snap, and for xTeVe, the service is `xteve.xteve`).
124+
- **`sudo snap logs xteve`**: Outputs the logs from the `xteve` snap's services. The exact log content will vary depending on the application's activity. If the service just started, logs might be minimal. The `|| echo "No logs yet or logs not accessible"` part is a fallback in case the logs command fails for some reason.
125+
- **`snap services xteve | grep -E "^xteve\.xteve\s+.*active"`**: This command is used to programmatically check if the `xteve.xteve` service is active. If it's active, it will print the line containing "xteve.xteve" and "active", and the CI step will pass. If it's not active, `grep` will not find a match and will return a non-zero exit code, causing the CI step to fail.
126+
127+
This documentation should help in understanding the CI process for the xTeVe snap.

.github/workflows/ci.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,39 @@ jobs:
5858
# For example:
5959
# - name: Lint code
6060
# run: golangci-lint run
61+
62+
snap-test:
63+
runs-on: ubuntu-latest
64+
needs: build
65+
steps:
66+
- name: Checkout code
67+
uses: actions/checkout@v3
68+
- name: Install snapcraft and lxd
69+
run: |
70+
sudo apt-get update
71+
sudo apt-get install -y qemu-kvm
72+
sudo snap install snapcraft --classic
73+
sudo snap install lxd
74+
- name: Initialize LXD
75+
run: sudo lxd init --auto
76+
- name: Add user to lxd group
77+
run: |
78+
sudo groupadd --system lxd || true
79+
sudo usermod -a -G lxd $USER || true
80+
# The new session part is tricky in CI. sg lxd -c "command" will be used later for snapcraft.
81+
# Re-login or newgrp is not feasible in most CI script flows.
82+
# We rely on `sg lxd -c "snapcraft"` for the build step to use the new group membership.
83+
- name: Build the snap
84+
run: sudo snapcraft --destructive-mode
85+
- name: Install the snap
86+
run: sudo snap install --dangerous xteve*.snap
87+
- name: Wait for service startup
88+
run: sleep 10
89+
- name: Check service status and dump logs
90+
run: |
91+
echo "--- Checking xteve service status ---"
92+
snap services xteve
93+
echo "--- Dumping xteve service logs ---"
94+
sudo snap logs xteve || echo "No logs yet or logs not accessible"
95+
echo "--- Verifying xteve service is active ---"
96+
snap services xteve | grep -E "^xteve\.xteve\s+.*active"

0 commit comments

Comments
 (0)