code wiki / _hdl_build / nx_deploy.nx
nx_deploy.nx source
↩ module page · 55 lines · 2748 B
1// nx_deploy.nx -- the team's SOVEREIGN deploy-with-rollback capability (operator: pushing site updates
2// with rollback must be a bits-up Nishi capability, layer 8 up, NO 3rd party, S-class-EXCEED practices).
3// The transfer is the sovereign ssh_put_file (proven live on the NAS, no scp); this module encodes the
4// SAFE-DEPLOY decision logic that wraps it, the practices a production deploy must follow:
5// 1. BACKUP the current artifact BEFORE any swap (never deploy without a rollback point)
6// 2. ATOMIC SWAP (write .new, then rename -- never a half-written live file)
7// 3. HEALTH-CHECK after swap (is the service actually up + serving?)
8// 4. ROLLBACK automatically if the health-check fails (restore the backup)
9// 5. SOVEREIGN TRANSFER (ssh_put_file over CHANNEL_DATA, not scp)
10// A deploy NEVER touches production unless a backup exists AND the transfer verified. license_tier: ORIGINAL
11
12import "nx_syscalls.nx"
13
14const DEP_ABORTED: i64 = 0 // pre-conditions failed -> production never touched
15const DEP_DEPLOYED: i64 = 1 // swapped + healthy
16const DEP_ROLLED_BACK: i64 = 2 // swapped but unhealthy -> backup restored
17
18// SAFETY GATE: only proceed to swap if a backup exists AND the new artifact transferred intact.
19func dep_ready(backup_taken: i64, transfer_ok: i64) -> i64 {
20 if backup_taken != 1 { return 0 }
21 if transfer_ok != 1 { return 0 }
22 return 1
23}
24
25// the deploy verdict.
26func dep_verdict(backup_taken: i64, transfer_ok: i64, health_ok: i64) -> i64 {
27 if dep_ready(backup_taken, transfer_ok) == 0 { return DEP_ABORTED } // never touched prod
28 if health_ok == 1 { return DEP_DEPLOYED }
29 return DEP_ROLLED_BACK // swapped, unhealthy -> restore
30}
31
32// after a failed health-check, the rollback must actually restore the backup (clean rollback).
33func dep_rollback_clean(verdict: i64, restored: i64) -> i64 {
34 if verdict == DEP_ROLLED_BACK { if restored == 1 { return 1 } return 0 }
35 return 1
36}
37
38// did production survive (still serving)? DEPLOYED = new is healthy; ROLLED_BACK = old restored; ABORTED = untouched.
39func dep_prod_alive(verdict: i64, restored: i64) -> i64 {
40 if verdict == DEP_DEPLOYED { return 1 }
41 if verdict == DEP_ABORTED { return 1 }
42 if verdict == DEP_ROLLED_BACK { if restored == 1 { return 1 } }
43 return 0
44}
45
46// S-class practices checklist: all five present?
47func dep_practice_score(backup: i64, atomic_swap: i64, healthcheck: i64, rollback: i64, sovereign_transfer: i64) -> i64 {
48 var s: i64 = 0
49 if backup == 1 { s = s + 1 }
50 if atomic_swap == 1 { s = s + 1 }
51 if healthcheck == 1 { s = s + 1 }
52 if rollback == 1 { s = s + 1 }
53 if sovereign_transfer == 1 { s = s + 1 }
54 return s
55}