-
Notifications
You must be signed in to change notification settings - Fork 193
Expand file tree
/
Copy pathbootc_testlib.nu
More file actions
110 lines (94 loc) · 3.8 KB
/
bootc_testlib.nu
File metadata and controls
110 lines (94 loc) · 3.8 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
# A simple nushell "library" for the
# This is a workaround for what must be a systemd bug
# that seems to have appeared in C10S
# TODO diagnose and fill in here
export def reboot [] {
# Allow more delay for bootc to settle
sleep 120sec
tmt-reboot
}
# True if we're running in bcvk with `--bind-storage-ro` and
# we can expect to be able to pull container images from the host.
# See xtask.rs
export def have_hostexports [] {
$env.BCVK_EXPORT? == "1"
}
# Parse the kernel commandline into a list.
# This is not a proper parser, but good enough
# for what we need here.
export def parse_cmdline [] {
open /proc/cmdline | str trim | split row " "
}
# cstor-dist configuration for authenticated registry testing
# cstor-dist serves images from containers-storage via an authenticated OCI registry endpoint
# https://github.com/ckyrouac/cstor-dist
const CSTOR_DIST_IMAGE = "ghcr.io/ckyrouac/cstor-dist:latest"
const CSTOR_DIST_USER = "testuser"
const CSTOR_DIST_PASS = "testpass"
const CSTOR_DIST_PORT = 8000
# The registry address for cstor-dist
export const CSTOR_DIST_REGISTRY = $"localhost:($CSTOR_DIST_PORT)"
# Start cstor-dist with basic auth on localhost
# Fails if cstor-dist cannot be started
export def start_cstor_dist [] {
print "Starting cstor-dist with basic auth..."
# Pull test images that cstor-dist will serve
print "Pulling test images for cstor-dist to serve..."
podman pull docker.io/library/alpine:latest
podman pull docker.io/library/busybox:latest
# Run cstor-dist container with auth enabled
# Mount the local containers storage so cstor-dist can serve images from it
let storage_path = if ("/var/lib/containers/storage" | path exists) {
"/var/lib/containers/storage"
} else {
$"($env.HOME)/.local/share/containers/storage"
}
(podman run --privileged --rm -d --name cstor-dist-auth
-p $"($CSTOR_DIST_PORT):8000"
-v $"($storage_path):/var/lib/containers/storage"
$CSTOR_DIST_IMAGE --username $CSTOR_DIST_USER --password $CSTOR_DIST_PASS)
# Wait for cstor-dist to be ready by testing HTTP connection
# Loop for up to 20 seconds
print "Waiting for cstor-dist to be ready..."
let auth_header = $"($CSTOR_DIST_USER):($CSTOR_DIST_PASS)" | encode base64
mut ready = false
for i in 1..20 {
let result = do { curl -sf -H $"Authorization: Basic ($auth_header)" $"http://($CSTOR_DIST_REGISTRY)/v2/" } | complete
if $result.exit_code == 0 {
$ready = true
break
}
print $"Attempt ($i)/20: cstor-dist not ready yet..."
sleep 1sec
}
if not $ready {
# Show container logs for debugging
print "cstor-dist failed to start. Container logs:"
podman logs cstor-dist-auth
error make { msg: "cstor-dist failed to become ready within 20 seconds" }
}
print $"cstor-dist running on ($CSTOR_DIST_REGISTRY)"
}
# Get cstor-dist auth config
export def get_cstor_auth [] {
# Base64 encode the credentials for auth.json
let auth_b64 = $"($CSTOR_DIST_USER):($CSTOR_DIST_PASS)" | encode base64
{
registry: $CSTOR_DIST_REGISTRY,
auth_b64: $auth_b64
}
}
# Configure insecure registry for cstor-dist (no TLS)
export def setup_insecure_registry [] {
mkdir /etc/containers/registries.conf.d
(echo $"[[registry]]\nlocation=\"($CSTOR_DIST_REGISTRY)\"\ninsecure=true"
| save -f /etc/containers/registries.conf.d/99-cstor-dist.conf)
}
# Set up auth.json on the running system with cstor-dist credentials
export def setup_system_auth [] {
mkdir /run/ostree
let cstor = get_cstor_auth
print $"Setting up system auth for cstor-dist at ($cstor.registry)"
let auth_json = $'{"auths": {"($cstor.registry)": {"auth": "($cstor.auth_b64)"}}}'
echo $auth_json | save -f /run/ostree/auth.json
}