-
Notifications
You must be signed in to change notification settings - Fork 0
94 lines (81 loc) · 2.83 KB
/
Copy pathci.yml
File metadata and controls
94 lines (81 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
name: CI
on:
push:
branches: [master]
pull_request:
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
jobs:
# Everything that needs nothing from the kernel: the unit tests, and the
# integration tests that drive the real binary's configuration handling.
# Formatting and lints have workflows of their own.
test:
name: build and test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
run: |
rustup update stable --no-self-update
rustup default stable
rustc --version
- name: Cache cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: cargo-${{ runner.os }}-${{ hashFiles('Cargo.lock') }}
restore-keys: cargo-${{ runner.os }}-
- name: Build
run: cargo build --locked --all-targets
- name: Test
run: cargo test --locked --all-targets
# The end-to-end test: the exporter running against a real kernel, in a user
# + network namespace. It needs the conntrack modules loaded and unprivileged
# user namespaces permitted, neither of which is a given on a runner.
e2e:
name: end-to-end (namespace)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
run: |
rustup update stable --no-self-update
rustup default stable
rustc --version
- name: Cache cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: cargo-e2e-${{ runner.os }}-${{ hashFiles('Cargo.lock') }}
restore-keys: cargo-e2e-${{ runner.os }}-
- name: Install nftables
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends nftables iproute2
- name: Prepare the kernel
run: |
# A user namespace can use a module but cannot load one.
sudo modprobe nf_conntrack
sudo modprobe nf_nat
sudo modprobe nf_tables
sudo modprobe nft_chain_nat
# Ubuntu 24.04 restricts unprivileged user namespaces through
# AppArmor, which is exactly the privilege this test relies on.
if [ -e /proc/sys/kernel/apparmor_restrict_unprivileged_userns ]; then
sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0
fi
# Fail the job now rather than skipping quietly later.
unshare --user --map-root-user --net true
- name: End-to-end test
# Without this the harness would skip on a runner that cannot provide
# the namespaces, and report a green build that tested nothing.
env:
E2E_REQUIRE: 1
run: cargo test --locked -- --ignored --nocapture