| 1 | name: CI tests |
| 2 | on: |
| 3 | - push |
| 4 | - pull_request |
| 5 | |
| 6 | jobs: |
| 7 | test: |
| 8 | strategy: |
| 9 | fail-fast: false |
| 10 | matrix: |
| 11 | go: |
| 12 | - oldstable |
| 13 | - stable |
| 14 | os: |
| 15 | - ubuntu-22.04 |
| 16 | - ubuntu-24.04 |
| 17 | runs-on: ${{ matrix.os }} |
| 18 | steps: |
| 19 | - name: Install Go |
| 20 | uses: actions/setup-go@v4 |
| 21 | with: |
| 22 | go-version: ${{ matrix.go }} |
| 23 | |
| 24 | - name: Checkout code |
| 25 | uses: actions/checkout@v2 |
| 26 | |
| 27 | - name: Install dependencies |
| 28 | run: | |
| 29 | sudo add-apt-repository ppa:ubuntu-lxc/daily -y |
| 30 | sudo apt-get install -qq apparmor lxc lxc-dev pkg-config uidmap busybox libdbus-1-dev libseccomp-dev libcap-dev libselinux-dev nftables iptables |
| 31 | |
| 32 | - name: Reset all firewalling |
| 33 | run: | |
| 34 | sudo iptables -F |
| 35 | sudo iptables -P INPUT ACCEPT |
| 36 | sudo iptables -P OUTPUT ACCEPT |
| 37 | sudo iptables -P FORWARD ACCEPT |
| 38 | sudo nft flush ruleset |
| 39 | |
| 40 | - name: Setup test environment |
| 41 | run: | |
| 42 | # Setup uid/gid and veth allocations |
| 43 | echo "${USER}:100000:65536" | sudo tee /etc/subuid |
| 44 | echo "${USER}:100000:65536" | sudo tee /etc/subgid |
| 45 | echo "${USER} veth lxcbr0 10" | sudo tee -a /etc/lxc/lxc-usernet |
| 46 | |
| 47 | # Local user configuration for userns |
| 48 | mkdir -p ~/.config/lxc/ |
| 49 | cp /etc/lxc/default.conf ~/.config/lxc/default.conf |
| 50 | echo "lxc.idmap = u 0 100000 65536" | tee -a ~/.config/lxc/default.conf |
| 51 | echo "lxc.idmap = g 0 100000 65536" | tee -a ~/.config/lxc/default.conf |
| 52 | |
| 53 | # Allow traversal to the containers |
| 54 | mkdir -p ~/.local/share/lxc |
| 55 | chmod +x ~/ ~/.local ~/.local/share ~/.local/share/lxc |
| 56 | |
| 57 | - name: Build the test |
| 58 | run: |
| 59 | go test -c -coverprofile=profile |
| 60 | |
| 61 | - name: Unprivileged tests |
| 62 | env: |
| 63 | DOWNLOAD_KEYSERVER: keyserver.ubuntu.com |
| 64 | run: | |
| 65 | # Make all cgroups writable |
| 66 | if [ ! -e /sys/fs/cgroup/cgroup.controllers ]; then |
| 67 | # CGroup 1 |
| 68 | for d in /sys/fs/cgroup/*; do |
| 69 | [ -f $d/cgroup.clone_children ] && echo 1 | sudo tee $d/cgroup.clone_children |
| 70 | [ -f $d/cgroup.use_hierarchy ] && echo 1 | sudo tee $d/cgroup.use_hierarchy |
| 71 | |
| 72 | sudo mkdir -p $d/lxc-test |
| 73 | sudo chown -R $USER: $d/lxc-test |
| 74 | echo $$ | sudo tee $d/lxc-test/cgroup.procs |
| 75 | done |
| 76 | |
| 77 | # Run the unprivileged tests |
| 78 | ./go-lxc.test -test.v -test.coverprofile=/tmp/unpriv.out |
| 79 | else |
| 80 | # CGroup 2 |
| 81 | sudo mkdir -p /sys/fs/cgroup/lxc-test |
| 82 | sudo chown -R $USER: /sys/fs/cgroup/lxc-test |
| 83 | echo $$ | sudo tee /sys/fs/cgroup/lxc-test/cgroup.procs |
| 84 | |
| 85 | # Run the unprivileged tests |
| 86 | systemd-run --unit=go-lxc-test --user --scope -p "Delegate=yes" ./go-lxc.test -test.v -test.coverprofile=/tmp/unpriv.out |
| 87 | fi |
| 88 | |
| 89 | - name: Privileged tests |
| 90 | env: |
| 91 | DOWNLOAD_KEYSERVER: keyserver.ubuntu.com |
| 92 | run: |
| 93 | sudo -E ./go-lxc.test -test.v -test.coverprofile=/tmp/priv.out |
| 94 | |
| 95 | - name: Code coverage |
| 96 | run: make cover |