6. A push is a deploy
Pushing to main puts the code live within a minute.
git push is the deploy. What is running, and since when, is in the fact deploy.json (rc.fact), written by root, readable by the app.
This is the code serving the zoo right now: the bytes this very program was built from (each file is embedded when the zoo is compiled), at commit
55c71513c5 (staging). The zoo's own self-check fetches this page and compares it byte for byte with the file it runs.
e06_push_is_deploy.odin sha256 c1256b53e1f4 · raw
1package main 2 3// Exhibit 6. Root records every deploy in the app's own facts: deploy.json has the live and staging 4// commit, when it arrived and who pushed it. The footer of this page reads it. 5 6import "core:fmt" 7import "core:strings" 8import "ratcloud:rc" 9 10e06 :: proc() -> Exhibit { 11 return { 12 n = 6, wing = "Deploy", 13 title = "A push is a deploy", 14 promise = "Pushing to main puts the code live within a minute.", 15 block = "git push is the deploy. What is running, and since when, is in the fact deploy.json (rc.fact), written by root, readable by the app.", 16 src = {"e06_push_is_deploy.odin", #load("e06_push_is_deploy.odin", string)}, 17 show = proc(me: ^rc.User) -> string { 18 d := fact("deploy.json") 19 b := strings.builder_make() 20 strings.write_string(&b, `<ul class="list">`) 21 for env_ in ([]string{"live", "staging"}) { 22 x := jget(d, env_) 23 if x == nil {rc.render_to(&b, `<li><span class="tag {{1}}">{{2}}</span>nothing yet</li>`, {{"1", env_}, {"2", env_}}); continue} 24 rc.render_to(&b, `<li><span class="tag {{1}}">{{2}}</span><code>{{3}}</code> by {{4}}, {{5}}</li>`, {{"1", env_}, {"2", env_}, {"3", short(jstr(x, "commit"), 10)}, {"4", jstr(x, "by")}, {"5", rc.raw(ago(parse_time(jstr(x, "at"))))}}) 25 } 26 strings.write_string(&b, "</ul>") 27 return strings.to_string(b) 28 }, 29 // The commit running here must be the newest one pushed to this environment's branch. 30 check = proc() -> Check { 31 e := env().env 32 running := jget(fact("deploy.json"), e) 33 pushes := jarr(fact("pushes.json")) 34 if running == nil || pushes == nil do return fail("the facts have no deploy.json or pushes.json") 35 for p in pushes { 36 if jstr(p, "env") != e || !strings.has_prefix(jstr(p, "result"), "deployed") do continue 37 if jstr(p, "commit") != jstr(running, "commit") do return fail(fmt.tprintf("running %s but the last push to %s was %s", short(jstr(running, "commit"), 10), e, short(jstr(p, "commit"), 10))) 38 lag := parse_time(jstr(running, "at")) - parse_time(jstr(p, "at")) 39 if lag > 60 do return fail(fmt.tprintf("the last push took %ds to go live", lag)) 40 return pass(fmt.tprintf("running %s, the last push to %s, live %ds after the push", short(jstr(running, "commit"), 10), e, lag)) 41 } 42 return fail(fmt.tprintf("no successful push to %s is recorded", e)) 43 }, 44 } 45}