Skip to content

Commit ac1f123

Browse files
committed
github: Add basic tests
Signed-off-by: Andreas Vögele <andreas@andreasvoegele.com>
1 parent 59e03d9 commit ac1f123

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

.github/workflows/basic-tests.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Basic Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- '*'
7+
tags-ignore:
8+
- '*'
9+
pull_request:
10+
11+
jobs:
12+
basic-tests:
13+
runs-on: ubuntu-24.04
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
python-version: ["3.8", "3.13"]
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- name: Set up Python ${{ matrix.python-version }}
22+
uses: actions/setup-python@v5
23+
with:
24+
python-version: ${{ matrix.python-version }}
25+
26+
- name: Install setuptools
27+
run: python -m pip install setuptools
28+
29+
- name: Install LXC
30+
run: sudo apt-get install -y lxc lxc-dev
31+
32+
- name: Configure LXC
33+
run: |
34+
mkdir -p ~/.config/lxc /var/tmp/lxc
35+
cat >~/.config/lxc/lxc.conf <<EOF
36+
lxc.lxcpath = /var/tmp/lxc
37+
EOF
38+
cat >~/.config/lxc/default.conf <<EOF
39+
lxc.include = /etc/lxc/default.conf
40+
lxc.idmap = u 0 165536 65536
41+
lxc.idmap = g 0 165536 65536
42+
lxc.apparmor.profile = unconfined
43+
EOF
44+
echo "$(id -un) veth lxcbr0 10" | sudo tee -a /etc/lxc/lxc-usernet
45+
46+
- name: Build module
47+
run: python3 setup.py build
48+
49+
- name: Install module
50+
run: pip install .
51+
52+
- name: Enable unprivileged user namespaces
53+
run: sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0
54+
55+
- name: Create container
56+
run: >
57+
python3 -c 'import lxc;exit(0 if lxc.Container("mycontainer").create("download", 0, {"dist": "alpine", "release": "edge", "arch": "amd64"}) else 1)'
58+
59+
- name: Start container
60+
run: python3 -c 'import lxc;exit(0 if lxc.Container("mycontainer").start() else 1)'
61+
62+
- name: Run command inside container
63+
run: python3 -c 'import lxc;exit(lxc.Container("mycontainer").attach_wait(lxc.attach_run_command, ["uname", "-a"]))'
64+
65+
- name: Stop container
66+
if: success() || failure()
67+
run: python3 -c 'import lxc;exit(0 if lxc.Container("mycontainer").stop() else 1)'
68+
69+
- name: Destroy container
70+
if: success() || failure()
71+
run: python3 -c 'import lxc;exit(0 if lxc.Container("mycontainer").destroy() else 1)'

0 commit comments

Comments
 (0)