| 1 | // Deploys the web server. The site is built here, where the fonts are and |
| 2 | // with a fresh copy of production's databases. The source and the build's |
| 3 | // cache are then copied over. The server builds from that cache when it |
| 4 | // starts, which leaves it nothing to do but serve. |
| 5 | const remote = "paperclover.net"; |
| 6 | /** the server's node.js, a link to the version that builds here run on */ |
| 7 | const node = "~/.local/node/bin"; |
| 8 | const cwd = Path.resolve("."); |
| 9 | |
| 10 | export async function main(graph: incremental.Graph) { |
| 11 | // a cache is only kept by the node.js that wrote it, and a server that |
| 12 | // builds without one would need the fonts |
| 13 | const stdout = await subprocess.execute(["ssh", remote, `${node}/node --version`]); |
| 14 | ASSERT( |
| 15 | stdout.trim() === process.version, |
| 16 | `${remote} runs node.js ${stdout.trim()}, and this build's cache is for ${process.version}`, |
| 17 | ); |
| 18 | |
| 19 | // a site that is down can't hand out its databases, and a deploy may be what brings it back |
| 20 | await downloadDb.main().catch((error) => console.warn("building with the local databases:", error)); |
| 21 | |
| 22 | // any error stops the deploy, including the ones a build can still be served with |
| 23 | await graph.incrementalBuild({ progress, buildAndWriteOutput: (b) => buildAndWriteOutput(b, "local build") }); |
| 24 | |
| 25 | await rsync.spawn({ |
| 26 | cwd, |
| 27 | args: [ |
| 28 | "-a", |
| 29 | "-r", |
| 30 | "--delete", |
| 31 | "--exclude=node_modules", |
| 32 | "cspell.json", |
| 33 | "run.js", |
| 34 | "package.json", |
| 35 | "package-lock.json", |
| 36 | "src", |
| 37 | "framework", |
| 38 | "lib", |
| 39 | `${remote}:~/paperclover.net/`, |
| 40 | ], |
| 41 | progress: progress.start("copy site files"), |
| 42 | }); |
| 43 | await subprocess.spawn([ |
| 44 | "ssh", |
| 45 | "-t", |
| 46 | remote, |
| 47 | "cd paperclover.net && " |
| 48 | + `PATH=${node}:$PATH npm i && ` |
| 49 | + node + "/node run trigger-live-rebuild http://localhost:10000" |
| 50 | ], { stdin: "inherit" }).wait(); |
| 51 | } |
| 52 | |
| 53 | import { Path } from "#sitegen/path"; |
| 54 | import { ASSERT } from "@clo/lib/assert"; |
| 55 | import type * as incremental from "@clo/lib/incremental"; |
| 56 | import * as progress from "@clo/lib/progress"; |
| 57 | import * as subprocess from "@clo/lib/subprocess"; |
| 58 | import * as rsync from "../file-viewer/rsync.ts"; |
| 59 | import { buildAndWriteOutput } from "../paperclover.net.ts"; |
| 60 | import * as downloadDb from "./download-db.ts"; |