crosscode: install and add Accounts; agent: Accounts installs and add-product
crosscode install takes --products accounts (one product per install); crosscode add <church> <product> installs a product next to a church's others, as its app user, undoing only its own folder, database, PM2 and site if a step fails. install_events/install_accounts share the checks, ports and nginx site. Agent 1.1.0: install jobs for Accounts, and add-product jobs (behind frp, with the Hub's ports and release). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@crosscode/agent",
|
||||
"version": "1.0.1",
|
||||
"version": "1.1.0",
|
||||
"private": true,
|
||||
"description": "The server agent: runs the crosscode script for signed jobs from Cross Code Hub, reports stats (docs/AGENT-1.0-PLAN.md)",
|
||||
"license": "UNLICENSED",
|
||||
|
||||
+17
-11
@@ -11,21 +11,27 @@ export function crosscodeArgs(job: agent.AgentJob, opts: { exportFile?: string }
|
||||
switch (job.type) {
|
||||
case "install": {
|
||||
const a = job.args;
|
||||
if (a.products.length !== 1 || a.products[0] !== "events") throw new Error("This agent can only install Events so far.");
|
||||
const domain = a.domains.events;
|
||||
const ports = a.ports.events;
|
||||
if (!domain || !ports) throw new Error("An Events install needs its domain and ports.");
|
||||
// The church's address: the Events domain without "events." (crosscode uses it for the
|
||||
// church.env ADDRESS; the domain itself goes in --events-domain).
|
||||
const address = domain.startsWith("events.") ? domain.slice("events.".length) : domain;
|
||||
const out = ["install", a.church, "--products", "events", "--domain", address, "--events-domain", domain,
|
||||
const product = a.products[0];
|
||||
if (a.products.length !== 1 || (product !== "events" && product !== "accounts")) throw new Error("This agent installs one product at a time: Events or Accounts.");
|
||||
const domain = a.domains[product];
|
||||
const ports = a.ports[product];
|
||||
if (!domain || !ports) throw new Error(`An install of ${product} needs its domain and ports.`);
|
||||
// The church's address: the product's domain without "<product>." (crosscode keeps it in
|
||||
// church.env ADDRESS for the products added later; the domain itself goes in --<product>-domain).
|
||||
const address = domain.startsWith(`${product}.`) ? domain.slice(product.length + 1) : domain;
|
||||
const out = ["install", a.church, "--products", product, "--domain", address, `--${product}-domain`, domain,
|
||||
"--api-port", String(ports.api), "--web-port", String(ports.web), "--frp"];
|
||||
const v = a.versions?.events;
|
||||
const v = a.versions?.[product];
|
||||
if (v) out.push("--version", v);
|
||||
return out;
|
||||
}
|
||||
case "add-product":
|
||||
return ["add", job.args.church, job.args.product];
|
||||
case "add-product": {
|
||||
// A product next to the church's others (phase 3: Accounts next to Events), behind frp.
|
||||
const a = job.args;
|
||||
const out = ["add", a.church, a.product, "--domain", a.domain, "--api-port", String(a.ports.api), "--web-port", String(a.ports.web), "--frp"];
|
||||
if (a.version) out.push("--version", a.version);
|
||||
return out;
|
||||
}
|
||||
case "deploy": {
|
||||
const out = ["deploy", job.args.church, ...job.args.products];
|
||||
for (const v of job.args.versions ?? []) out.push("--version", v);
|
||||
|
||||
@@ -12,6 +12,21 @@ describe("crosscode arguments for each job", () => {
|
||||
}))).toEqual(["install", "hope", "--products", "events", "--domain", "hope.co.za", "--events-domain", "events.hope.co.za", "--api-port", "20011", "--web-port", "20010", "--frp", "--version", "events@2.4.1"]);
|
||||
});
|
||||
|
||||
it("install: Accounts as a church's first product", () => {
|
||||
expect(crosscodeArgs(parsed({
|
||||
type: "install",
|
||||
args: { church: "grace", products: ["accounts"], domains: { accounts: "accounts.grace.crosscode.co.za" }, ports: { accounts: { web: 20020, api: 20021 } } },
|
||||
}))).toEqual(["install", "grace", "--products", "accounts", "--domain", "grace.crosscode.co.za", "--accounts-domain", "accounts.grace.crosscode.co.za", "--api-port", "20021", "--web-port", "20020", "--frp"]);
|
||||
expect(() => crosscodeArgs(parsed({ type: "install", args: { church: "grace", products: ["website"], domains: { website: "www.grace.co.za" }, ports: { website: { web: 20030, api: 20031 } } } }))).toThrow(/one product at a time/);
|
||||
});
|
||||
|
||||
it("add-product: Accounts next to Events, behind frp", () => {
|
||||
expect(crosscodeArgs(parsed({
|
||||
type: "add-product",
|
||||
args: { church: "hope", product: "accounts", version: "accounts@1.0.0", domain: "accounts.hope.co.za", ports: { web: 20012, api: 20013 } },
|
||||
}))).toEqual(["add", "hope", "accounts", "--domain", "accounts.hope.co.za", "--api-port", "20013", "--web-port", "20012", "--frp", "--version", "accounts@1.0.0"]);
|
||||
});
|
||||
|
||||
it("deploy, adopt, restart, uninstall, purge, status", () => {
|
||||
expect(crosscodeArgs(parsed({}))).toEqual(["deploy", "hope", "events", "--version", "events@2.4.1"]);
|
||||
expect(crosscodeArgs(parsed({ args: { church: "hope", products: ["events"], check: true } }))).toEqual(["deploy", "hope", "events", "--check"]);
|
||||
|
||||
Reference in New Issue
Block a user