package main // Exhibit 8. A push whose ratcloud.conf is wrong is refused whole: the old code and settings keep // running and the error lands in the app's facts (manifest.json). The sample app `zoo-broken` has a // deliberate typo pushed to it. The zoo reads only its own facts, so zoo-broken publishes its own // manifest fact at /manifest.json, from its last good version, and the zoo fetches that over HTTPS. // apps shows the same error on the app's page, to its creator: the check reads it there as the robot, // zoo-broken's creator. Any valid push to zoo-broken clears the error, so the zoo's nightly job puts // the typo back when it is gone (broken.odin). On wasm, a build that does not compile is refused the // same way: the sample zoo-wasm keeps a preview of its branch broken-build refused, with the compiler's // lines, and publishes its manifest fact as zoo-broken does. import "core:encoding/json" import "core:fmt" import "core:strings" import "ratcloud:rc" E08_Data :: struct { ok: json.Value `json:"ok"`, error: string `json:"error"`, at: string `json:"at"`, commit: string `json:"commit"`, apps: string `json:"apps,omitempty"`, wasm: json.Value `json:"wasm,omitempty"`, } e08 :: proc() -> Exhibit { return { n = 8, wing = "Deploy", title = "A bad manifest is shown, not applied", promise = "A mistake in an app's settings file (ratcloud.conf) leaves the old settings running and says what was wrong.", block = "ratcloud.conf is checked before anything is applied. A bad one refuses the push, in the pusher's terminal, in the fact manifest.json and on the app's page at apps; the site keeps running. A wasm app that does not compile is refused the same way.", src = {"e08_bad_manifest.odin", #load("e08_bad_manifest.odin", string)}, files = srcs({"broken.odin", #load("broken.odin", string)}, {"creator.odin", #load("creator.odin", string)}), show = proc(me: ^rc.User) -> string { url := rc.app_url(BROKEN_APP) b := strings.builder_make() night := "" if v, ok := meta("broken.nightly"); ok { n: Broken json.unmarshal_string(v, &n) night = fmt.tprintf(`

The nightly job, %s: %s%s.

`, ago(n.at), h(n.result), " (a valid push had cleared the error)" if n.result == "put back" else "") } d, s, found := stored_data(8, E08_Data) if !found || s.data == "null" { rc.render_to(&b, `

The sample app zoo-broken has not been checked yet.

{{2}}`, {{"1", url}, {"2", rc.raw(night)}}) return strings.to_string(b) } rc.render_to(&b, `

The sample app {{2}} is up, and its last push was refused:

{{3}}
`, {{"1", url}, {"2", domain_host(url)}, {"3", d.error}}) rc.render_to(&b, `

Refused {{1}}, commit {{2}}. It still serves its last good version.`, {{"1", rc.raw(ago(parse_time(d.at)))}, {"2", short(d.commit, 7)}}) if d.apps != "" do rc.render_to(&b, ` Its creator sees the same on its page at apps: {{3}}.`, {{"1", rc.app_url("apps")}, {"2", BROKEN_APP}, {"3", d.apps}}) strings.write_string(&b, "

") if ok, isb := jget(d.wasm, "ok").(json.Boolean); isb && !ok { rc.render_to(&b, `

On wasm, a build that does not compile is refused the same way: the preview of zoo-wasm's branch broken-build keeps what it had, and says why:

{{2}}
`, {{"1", rc.app_url("zoo-wasm")}, {"2", jstr(d.wasm, "error")}}) } strings.write_string(&b, night) return strings.to_string(b) }, check = proc() -> Check { url := rc.app_url(BROKEN_APP) if r := get(new_browser(), cat(url, "/")); r.status != 200 do return fail(fmt.tprintf("the sample app is down (%d): a bad manifest must not take it down", r.status)) mr := get(new_browser(), cat(url, "/manifest.json")) m: E08_Data if mr.status != 200 || json.unmarshal_string(mr.body, &m) != nil do return fail(fmt.tprintf("the sample app's manifest fact did not load (%d)", mr.status)) if ok, isb := m.ok.(json.Boolean); !isb || ok do return fail("the sample app's typo was accepted, or is gone: no error to show (a valid push to zoo-broken clears it; the zoo's nightly job puts it back)") if strings.trim_space(m.error) == "" do return fail("the push was refused but no error was recorded") // Where its creator looks: the app's page at apps, read as the robot (zoo-broken's creator). b, err := robot_at("apps") if err != "" do return fail(err, m) a := get(b, fmt.tprintf("%s/api/app/%s", rc.app_url("apps"), BROKEN_APP)) e := env().env if a.status != 200 || a.j == nil do return fail(fmt.tprintf("apps does not show zoo-broken's page to its creator (%d)", a.status), m) if ok, isb := jget(a.j, "manifest", e, "ok").(json.Boolean); !isb || ok || jstr(a.j, "manifest", e, "error") != m.error { return fail(fmt.tprintf("apps's page for zoo-broken does not show the refused manifest on %s: %s", e, to_json(jget(a.j, "manifest", e))), m) } att := make([dynamic]string) for x in jarr(a.j, "attention") do if s, ok := x.(json.String); ok do append(&att, string(s)) m.apps = strings.join(att[:], ", ") if len(att) > 0 else "the refused manifest" // The wasm line: zoo-wasm's preview of broken-build, refused with the compiler's lines. if wr := get(new_browser(), cat(rc.app_url("zoo-wasm"), "/manifest.json")); wr.status == 200 do m.wasm = jget(wr.j, "build", "preview") return pass(fmt.tprintf("zoo-broken is up on its last good version; its typo was refused with: %s (apps shows it on the app's page: %s)", m.error, m.apps), m) }, } }