-
-
Notifications
You must be signed in to change notification settings - Fork 288
199 lines (147 loc) · 4.93 KB
/
test_set_1.yml
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#
# Copyright (C) 2022-2024 Lin Song <linsongui@gmail.com>
name: test_set_1
on: workflow_call
jobs:
test_set_1:
runs-on: ubuntu-22.04
if: github.repository_owner == 'hwdsl2'
strategy:
matrix:
os_version: ["centos:9s", "rockylinux:8", "almalinux:9", "almalinux:8"]
fail-fast: false
env:
OS_VERSION: ${{ matrix.os_version }}
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Build
run: |
mkdir -p "$GITHUB_WORKSPACE/testing/${OS_VERSION//:}"
cd "$GITHUB_WORKSPACE/testing/${OS_VERSION//:}"
mkdir -p scripts
ls -ld "$GITHUB_WORKSPACE/wireguard-install.sh"
cp -f "$GITHUB_WORKSPACE"/*.sh scripts/
cat > run.sh <<'EOF'
#!/bin/bash
set -eEx
trap 'catch $? $LINENO' ERR
catch() {
echo "Error $1 occurred on line $2."
cat -n -- "$0" | tail -n+"$(($2 - 3))" | head -n7
exit 1
}
cd /opt/src
yum -y -q update
yum -y -q install wget kmod procps-ng net-tools
rm -f /usr/bin/systemd-detect-virt
cp -f /opt/src/scripts/wireguard-install.sh ./wireguard.sh
bash wireguard.sh --auto
netstat -anpu | grep ':51820'
systemctl status wg-quick@wg0
ls -ld ~/client.conf
bash wireguard.sh <<ANSWERS
1
client2
ANSWERS
ls -ld ~/client2.conf
bash wireguard.sh <<ANSWERS
2
ANSWERS
bash wireguard.sh <<ANSWERS | grep -i "2 clients"
2
ANSWERS
bash wireguard.sh <<ANSWERS
3
2
y
ANSWERS
ls -ld ~/client2.conf && exit 1
bash wireguard.sh <<ANSWERS | grep -i "1 client"
2
ANSWERS
bash wireguard.sh <<ANSWERS
4
1
ANSWERS
bash wireguard.sh <<ANSWERS
5
y
ANSWERS
netstat -anpu | grep ':51820' && exit 1
rm -f ~/client*.conf
bash wireguard.sh <<ANSWERS
ANSWERS
netstat -anpu | grep ':51820'
systemctl status wg-quick@wg0
ls -ld ~/client.conf
bash wireguard.sh <<ANSWERS
5
y
ANSWERS
netstat -anpu | grep ':51820' && exit 1
rm -f ~/client*.conf
bash wireguard.sh <<ANSWERS
y
invalidfqdn
vpn.example.com
ANSWERS
netstat -anpu | grep ':51820'
systemctl status wg-quick@wg0
ls -ld ~/client.conf
grep -q 'ENDPOINT vpn.example.com' /etc/wireguard/wg0.conf
grep -q 'Endpoint = vpn.example.com:51820' ~/client.conf
bash wireguard.sh <<ANSWERS
5
y
ANSWERS
netstat -anpu | grep ':51820' && exit 1
rm -f ~/client*.conf
exit 0
EOF
if [ "$OS_VERSION" = "centos:9s" ]; then
echo "FROM quay.io/centos/centos:stream9" > Dockerfile
elif [ "$OS_VERSION" = "centos:8s" ]; then
echo "FROM quay.io/centos/centos:stream8" > Dockerfile
else
echo "FROM $OS_VERSION" > Dockerfile
fi
cat >> Dockerfile <<'EOF'
ENV container docker
WORKDIR /opt/src
EOF
if [ "$OS_VERSION" = "centos:9s" ]; then
echo "RUN yum -y -q install systemd" >> Dockerfile
fi
cat >> Dockerfile <<'EOF'
RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ "$i" = \
systemd-tmpfiles-setup.service ] || rm -f "$i"; done); \
rm -f /lib/systemd/system/multi-user.target.wants/*; \
rm -f /etc/systemd/system/*.wants/*; \
rm -f /lib/systemd/system/local-fs.target.wants/*; \
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
rm -f /lib/systemd/system/basic.target.wants/*; \
rm -f /lib/systemd/system/anaconda.target.wants/*;
COPY scripts/ /opt/src/scripts/
COPY ./run.sh /opt/src/run.sh
RUN chmod 755 /opt/src/run.sh
VOLUME [ "/sys/fs/cgroup" ]
CMD ["/sbin/init"]
EOF
cat Dockerfile
cat run.sh
docker build -t "${OS_VERSION//:}-test" .
- name: Test
run: |
docker run -d --name "${OS_VERSION//:}-test-1" -v /sys/fs/cgroup:/sys/fs/cgroup:ro \
--privileged "${OS_VERSION//:}-test"
sleep 5
docker exec "${OS_VERSION//:}-test-1" /opt/src/run.sh "${OS_VERSION::6}"
- name: Clear
if: always()
run: |
rm -rf "$GITHUB_WORKSPACE/testing/${OS_VERSION//:}"
docker rm -f "${OS_VERSION//:}-test-1" || true
docker rmi "${OS_VERSION//:}-test" || true