-
Notifications
You must be signed in to change notification settings - Fork 177
Expand file tree
/
Copy paths3-minio.nu
More file actions
131 lines (117 loc) · 5.12 KB
/
s3-minio.nu
File metadata and controls
131 lines (117 loc) · 5.12 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
#!/usr/bin/env nu
# Paths
let tmp = ($env.RUNNER_TEMP? | default $env.TEMP? | default "/tmp")
let bin_dir = $tmp
let data_dir = $"($tmp)/minio-data"
let log_file = $"($tmp)/minio.log"
let pid_file = $"($tmp)/minio.pid"
let bucket_name = $"tmp-(random int 0..1000000)"
let config_path = $"($tmp)/rattler.toml"
# Create directories
mkdir $bin_dir $data_dir
# Create rattler config with S3 options for MinIO (path-style addressing)
let config_content = $"[s3-options.($bucket_name)]
endpoint-url = \"http://localhost:9000\"
force-path-style = true
region = \"us-east-1\"
"
$config_content | save $config_path
# Credentials
let root_user = ($env.MINIO_ACCESS_KEY? | default "minio")
let root_password = ($env.MINIO_SECRET_KEY? | default "minio123")
# Start MinIO in background as a job
print "== Starting Minio server..."
let minio_job = job spawn {
with-env {
MINIO_ROOT_USER: $root_user
MINIO_ROOT_PASSWORD: $root_password
} {
^minio server $data_dir --address ":9000" out+err> $log_file
}
}
# wait up to 120s (60 × 2s) for MinIO to be ready
if not (seq 0 59 | any {|_|
try { http get http://localhost:9000/minio/health/live | ignore; true } catch { sleep 2sec; false }
}) {
error make {msg: "MinIO failed to start within 120 seconds"}
}
print "Minio server is up and running..."
# Configure mc client and bucket
print $"== Configuring bucket ($bucket_name)..."
^mc alias set minio http://localhost:9000 $root_user $root_password
^mc mb $"minio/($bucket_name)"
^mc anonymous set download $"minio/($bucket_name)"
print "== Upload packages to Minio"
(^rattler
upload s3
--channel $"s3://($bucket_name)"
--access-key-id $root_user
--secret-access-key $root_password
--region "us-east-1"
--endpoint-url "http://localhost:9000"
--addressing-style path
test-data/packages/empty-0.1.0-h4616a5c_0.conda
)
print "== Index the channel"
(^rattler-index
s3
$"s3://($bucket_name)"
--config $config_path
--access-key-id $root_user
--secret-access-key $root_password
)
print "== Verify cache control headers are set correctly"
# Check repodata.json has 5-minute cache (300 seconds)
let repodata_headers = (curl -I -s $"http://localhost:9000/($bucket_name)/noarch/repodata.json")
let repodata_cache = ($repodata_headers | grep -i "cache-control" | str trim | split row ": " | get 1 | str trim)
if $repodata_cache != "public, max-age=300" {
print $"DEBUG: Full headers for repodata.json:\n($repodata_headers)"
print $"DEBUG: Extracted cache value type: ($repodata_cache | describe)"
print $"DEBUG: Extracted cache value bytes: ($repodata_cache | into binary | encode hex)"
error make {msg: $"Expected repodata.json to have 'public, max-age=300' but got '($repodata_cache)'"}
}
print "✓ repodata.json has correct cache control (5 minutes)"
# Check repodata.json.zst has 5-minute cache (300 seconds)
let repodata_zst_headers = (curl -I -s $"http://localhost:9000/($bucket_name)/noarch/repodata.json.zst")
let repodata_zst_cache = ($repodata_zst_headers | grep -i "cache-control" | str trim | split row ": " | get 1 | str trim)
if $repodata_zst_cache != "public, max-age=300" {
print $"DEBUG: Full headers for repodata.json.zst:\n($repodata_zst_headers)"
error make {msg: $"Expected repodata.json.zst to have 'public, max-age=300' but got '($repodata_zst_cache)'"}
}
print "✓ repodata.json.zst has correct cache control (5 minutes)"
# Check shard index has 5-minute cache
let shard_index_headers = (curl -I -s $"http://localhost:9000/($bucket_name)/noarch/repodata_shards.msgpack.zst")
let shard_index_cache = ($shard_index_headers | grep -i "cache-control" | str trim | split row ": " | get 1 | str trim)
if $shard_index_cache != "public, max-age=300" {
print $"DEBUG: Full headers for repodata_shards.msgpack.zst:\n($shard_index_headers)"
error make {msg: $"Expected repodata_shards.msgpack.zst to have 'public, max-age=300' but got '($shard_index_cache)'"}
}
print "✓ repodata_shards.msgpack.zst has correct cache control (5 minutes)"
# Check individual shard files have immutable cache (1 year)
let shard_files = (^mc ls --json $"minio/($bucket_name)/noarch/shards/" | lines | each { |line| $line | from json | get key })
if ($shard_files | length) > 0 {
let first_shard = ($shard_files | first)
let shard_headers = (curl -I -s $"http://localhost:9000/($bucket_name)/noarch/shards/($first_shard)")
let shard_cache = ($shard_headers | grep -i "cache-control" | str trim | split row ": " | get 1 | str trim)
if $shard_cache != "public, max-age=31536000, immutable" {
print $"DEBUG: Full headers for shard:\n($shard_headers)"
error make {msg: $"Expected shard files to have 'public, max-age=31536000, immutable' but got '($shard_cache)'"}
}
print "✓ Shard files have correct cache control (immutable, 1 year)"
} else {
print "⚠ No shard files found to check"
}
print "== Test package can be installed from the channel ==="
with-env {
AWS_ACCESS_KEY_ID: $root_user
AWS_SECRET_ACCESS_KEY: $root_password
AWS_REGION: "us-east-1"
} {
(^rattler
create
--dry-run
--config $config_path
-c $"s3://($bucket_name)"
empty==0.1.0
)
}