feat(infra): dist:prune to delete superseded golden snapshots
Incremental rebuilds accumulate snapshots (~$0.40/mo each). dist:prune keeps the newest N (default 2: current + one rollback); dist:image reminds you to run it. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
d9588f8c80
commit
0c50c04b4c
1 changed files with 15 additions and 0 deletions
|
|
@ -52,6 +52,7 @@ cmd_dist() {
|
||||||
Distributed test/train fleet (DigitalOcean). Set TF_VAR_do_token first.
|
Distributed test/train fleet (DigitalOcean). Set TF_VAR_do_token first.
|
||||||
./run dist:check offline: fmt + validate + mocked test (no token/spend)
|
./run dist:check offline: fmt + validate + mocked test (no token/spend)
|
||||||
./run dist:image [--cold] (re)build golden image — incremental by default (~3-8min vs ~20 cold)
|
./run dist:image [--cold] (re)build golden image — incremental by default (~3-8min vs ~20 cold)
|
||||||
|
./run dist:prune [keep=2] delete superseded golden snapshots (~$0.40/mo each)
|
||||||
./run dist:up <workers> [size] [region] e.g. ./run dist:up 10
|
./run dist:up <workers> [size] [region] e.g. ./run dist:up 10
|
||||||
./run dist:sim <games> [turn_limit] [--destroy-after]
|
./run dist:sim <games> [turn_limit] [--destroy-after]
|
||||||
./run dist:train <total_steps> [--destroy-after]
|
./run dist:train <total_steps> [--destroy-after]
|
||||||
|
|
@ -106,6 +107,20 @@ cmd_dist_image() {
|
||||||
fi
|
fi
|
||||||
export PKR_VAR_base_image="$base"
|
export PKR_VAR_base_image="$base"
|
||||||
( cd "$root/infra/packer" && packer init golden-image.pkr.hcl >/dev/null && packer build golden-image.pkr.hcl )
|
( cd "$root/infra/packer" && packer init golden-image.pkr.hcl >/dev/null && packer build golden-image.pkr.hcl )
|
||||||
|
echo "tip: each rebuild leaves a snapshot (~\$0.40/mo) — './run dist:prune' deletes superseded ones."
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd_dist_prune() {
|
||||||
|
# Delete superseded golden snapshots, keeping the newest N (default 2).
|
||||||
|
local keep="${1:-2}" pat old id
|
||||||
|
pat="$(cat ~/.vault/do_pat_mc 2>/dev/null)"
|
||||||
|
[ -n "$pat" ] || { echo "no ~/.vault/do_pat_mc" >&2; return 1; }
|
||||||
|
old="$(curl -s -H "Authorization: Bearer $pat" "https://api.digitalocean.com/v2/snapshots?resource_type=droplet&per_page=200" \
|
||||||
|
| python3 -c "import sys,json;s=[x for x in json.load(sys.stdin)['snapshots'] if x['name'].startswith('mc-golden')];s.sort(key=lambda x:x['created_at']);[print(x['id']) for x in s[:-${keep}]]" 2>/dev/null)"
|
||||||
|
[ -n "$old" ] || { echo "nothing to prune (<= $keep golden snapshots)"; return 0; }
|
||||||
|
for id in $old; do
|
||||||
|
curl -s -o /dev/null -w " pruned golden snapshot $id: http %{http_code}\n" -X DELETE -H "Authorization: Bearer $pat" "https://api.digitalocean.com/v2/snapshots/$id"
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd_dist_up() {
|
cmd_dist_up() {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue