-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjustfile
More file actions
224 lines (187 loc) · 7.59 KB
/
justfile
File metadata and controls
224 lines (187 loc) · 7.59 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
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
verify:
cargo fmt --all -- --check
cargo clippy --workspace --all-targets -- -D warnings -W clippy::pedantic
cargo nextest run --workspace
docker-smoke: docker-smoke-probes docker-smoke-ssh-recording
docker-smoke-probes:
#!/usr/bin/env bash
set -euo pipefail
container_name="kino-k0s-ci"
image_tag="kino-k0s:ci"
cleanup() {
docker rm -f "${container_name}" >/dev/null 2>&1 || true
}
wait_for_probes() {
local attempts=0
local max_attempts=180
local http_code
local state
echo "Waiting for /probes readiness..."
while ((attempts < max_attempts)); do
state="$(
docker inspect "${container_name}" 2>/dev/null \
| python3 -c 'import json, sys; print(json.load(sys.stdin)[0]["State"]["Status"])' \
|| echo unknown
)"
if [[ "${state}" == "unknown" ]]; then
echo "Container disappeared before /probes became ready"
docker logs --tail 200 "${container_name}" || true
return 1
fi
if [[ "${state}" == "exited" || "${state}" == "dead" ]]; then
echo "Container is ${state} before /probes became ready"
docker logs --tail 200 "${container_name}" || true
return 1
fi
http_code="$(curl -sS -o /tmp/kino-probes.bin -w '%{http_code}' --max-time 2 http://127.0.0.1:18080/probes || true)"
if [[ "${http_code}" == "200" ]]; then
echo "/probes is ready"
return 0
fi
((attempts += 1))
if ((attempts % 10 == 0)); then
echo "Still waiting (attempt ${attempts}/${max_attempts}, http_code=${http_code})"
fi
sleep 1
done
echo "Timed out waiting for /probes"
docker logs --tail 200 "${container_name}" || true
return 1
}
assert_probe_status() {
local probe_id="$1"
local expected_status="$2"
if ! grep -F -A8 "id: \"${probe_id}\"" /tmp/kino-probes.txt | grep -Fq "status: ${expected_status}"; then
echo "Probe ${probe_id} did not report ${expected_status}"
cat /tmp/kino-probes.txt
return 1
fi
}
trap cleanup EXIT
cleanup
docker build -f docker/smoke/probes.Dockerfile -t "${image_tag}" .
docker run -d --name "${container_name}" --privileged -p 18080:8080 -p 16443:6443 "${image_tag}" >/dev/null
wait_for_probes
protoc --decode=kino.v1.ProbesSnapshotV1 -I proto proto/kino/v1/probes.proto < /tmp/kino-probes.bin >/tmp/kino-probes.txt
cat /tmp/kino-probes.txt
for probe_id in kino_check_pod_running kino_config_exists kino_config_has_server_block kube_api_port_open; do
if ! grep -Fq "id: \"${probe_id}\"" /tmp/kino-probes.txt; then
echo "Missing probe id: ${probe_id}"
exit 1
fi
done
assert_probe_status "kino_config_exists" "PROBE_STATUS_PASS"
assert_probe_status "kino_config_has_server_block" "PROBE_STATUS_PASS"
assert_probe_status "kube_api_port_open" "PROBE_STATUS_PASS"
docker-smoke-ssh-recording:
#!/usr/bin/env bash
set -euo pipefail
container_name="kino-ssh-recording-ci"
image_tag="kino-ssh-recording:ci"
recordings_dir="$(mktemp -d)"
ssh_dir="$(mktemp -d)"
private_key="${ssh_dir}/id_ed25519"
public_key="${ssh_dir}/id_ed25519.pub"
interactive_log="${ssh_dir}/interactive.log"
command_log="${ssh_dir}/command.log"
tty_command_log="${ssh_dir}/tty-command.log"
stdin_command_log="${ssh_dir}/stdin-command.log"
progress_log="${ssh_dir}/progress.log"
cleanup_container() {
docker rm -f "${container_name}" >/dev/null 2>&1 || true
}
cleanup() {
cleanup_container
rm -rf "${recordings_dir}" "${ssh_dir}"
}
wait_for_ssh() {
local attempts=0
local max_attempts=60
local state
echo "Waiting for sshd readiness..."
while ((attempts < max_attempts)); do
state="$(
docker inspect "${container_name}" 2>/dev/null \
| python3 -c 'import json, sys; print(json.load(sys.stdin)[0]["State"]["Status"])' \
|| echo unknown
)"
if [[ "${state}" == "unknown" ]]; then
echo "Container disappeared before sshd became ready"
docker logs --tail 200 "${container_name}" || true
return 1
fi
if [[ "${state}" == "exited" || "${state}" == "dead" ]]; then
echo "Container is ${state} before sshd became ready"
docker logs --tail 200 "${container_name}" || true
return 1
fi
if ssh -i "${private_key}" \
-p 12222 \
-o BatchMode=yes \
-o ConnectTimeout=2 \
-o StrictHostKeyChecking=no \
-o UserKnownHostsFile=/dev/null \
user@127.0.0.1 "true" >/dev/null 2>&1; then
echo "sshd is ready"
return 0
fi
((attempts += 1))
sleep 1
done
echo "Timed out waiting for sshd"
docker logs --tail 200 "${container_name}" || true
return 1
}
trap cleanup EXIT
cleanup_container
chmod 0777 "${recordings_dir}"
ssh-keygen -q -N '' -t ed25519 -f "${private_key}"
docker build -f docker/smoke/ssh-recording.Dockerfile -t "${image_tag}" .
docker run -d \
--name "${container_name}" \
-p 12222:22 \
-v "${recordings_dir}:/recordings" \
-v "${ssh_dir}:/smoke:ro" \
"${image_tag}" >/dev/null
wait_for_ssh
printf 'printf "interactive-smoke\\n"\nexit\n' \
| ssh -tt \
-i "${private_key}" \
-p 12222 \
-o BatchMode=yes \
-o StrictHostKeyChecking=no \
-o UserKnownHostsFile=/dev/null \
user@127.0.0.1 >"${interactive_log}" 2>&1
ssh \
-i "${private_key}" \
-p 12222 \
-o BatchMode=yes \
-o StrictHostKeyChecking=no \
-o UserKnownHostsFile=/dev/null \
user@127.0.0.1 "printf 'command-smoke\n'" >"${command_log}" 2>&1
ssh -tt \
-i "${private_key}" \
-p 12222 \
-o BatchMode=yes \
-o StrictHostKeyChecking=no \
-o UserKnownHostsFile=/dev/null \
user@127.0.0.1 "printf 'tty-command-smoke\n'" >"${tty_command_log}" 2>&1
printf 'stdin-smoke\n' \
| ssh \
-i "${private_key}" \
-p 12222 \
-o BatchMode=yes \
-o StrictHostKeyChecking=no \
-o UserKnownHostsFile=/dev/null \
user@127.0.0.1 "cat >/tmp/stdin-smoke && cat /tmp/stdin-smoke" >"${stdin_command_log}" 2>&1
printf 'printf "Listing... 0%%%%\\r"; sleep 0.1; printf "Listing... Done\\r\\n"; printf "progress-tail-smoke\\n"\nexit\n' \
| ssh -tt \
-i "${private_key}" \
-p 12222 \
-o BatchMode=yes \
-o StrictHostKeyChecking=no \
-o UserKnownHostsFile=/dev/null \
user@127.0.0.1 >"${progress_log}" 2>&1
echo "Recorded files:"
ls -la "${recordings_dir}"
python3 docker/smoke/validate_casts.py "${recordings_dir}"