// Build (and optionally push) the Quantum container image, stamping OCI version // metadata from ChronVer + git so the registry shows real project info. // // deno task image # build atcr.io/graham.systems/quantum: + :latest // deno task image --push # build, then `docker push` both tags // deno task image -- --no-cache # extra flags after `--` go to docker build import { currentVersion } from "./version.ts"; const IMAGE = "atcr.io/graham.systems/quantum"; async function tryGit(...args: string[]): Promise { try { const { code, stdout } = await new Deno.Command("git", { args, stdout: "piped", stderr: "null", }).output(); return code === 0 ? new TextDecoder().decode(stdout).trim() : ""; } catch { return ""; } } async function run(cmd: string, args: string[]): Promise { const { code } = await new Deno.Command(cmd, { args, stdout: "inherit", stderr: "inherit", }).output(); return code; } const version = await currentVersion(); const revision = await tryGit("rev-parse", "--short", "HEAD"); const created = new Date().toISOString(); const push = Deno.args.includes("--push"); // Anything after a literal `--` is forwarded verbatim to `docker build`. const passthroughAt = Deno.args.indexOf("--"); const extra = passthroughAt === -1 ? [] : Deno.args.slice(passthroughAt + 1); const tags = [`${IMAGE}:${version}`, `${IMAGE}:latest`]; console.log( `Building ${IMAGE}:${version} (revision ${ revision || "unknown" }, created ${created})`, ); const buildArgs = [ "build", "--build-arg", `VERSION=${version}`, "--build-arg", `CREATED=${created}`, "--build-arg", `REVISION=${revision}`, ...tags.flatMap((t) => ["-t", t]), ...extra, ".", ]; let code = await run("docker", buildArgs); if (code === 0 && push) { for (const t of tags) { console.log(`Pushing ${t}`); code = await run("docker", ["push", t]); if (code !== 0) break; } } Deno.exit(code);