google-labs-jules[bot] 752bfcf03e Refactor infra/setup/cli.ts into smaller command and prompt modules
Decomposes the monolith `infra/setup/cli.ts` into clean `infra/setup/prompts/` and `infra/setup/commands/` directories while adhering to Cliffy idiomatic modularity. Validated via `deno check`, tests, and format.

Co-authored-by: mrteye <1945243+mrteye@users.noreply.github.com>
2026-08-26 04:37:41 +00:00

236 lines
7.0 KiB
TypeScript

import { Command } from "jsr:@cliffy/command@1.0.0-rc.7";
import * as colors from "jsr:@std/fmt@0.225.2/colors";
import { AuthSetupConfig, DEFAULT_AUTH_CONFIG, readEnv } from "../env.ts";
import {
downloadWorkloadProto,
executeBuildImage,
executeProtobufCompilation,
generateBuildCommands,
} from "../build.ts";
export const compileProtoCommand = new Command()
.description("Compile Protobuf Definitions")
.action(async () => {
try {
await downloadWorkloadProto();
await executeProtobufCompilation();
console.log(colors.green("\n✓ Successfully compiled protobufs!\n"));
} catch (error) {
if (error instanceof Error) {
console.log(
colors.red(`\n✗ Protobuf compilation failed: ${error.message}\n`),
);
} else {
console.log(colors.red(`\n✗ Protobuf compilation failed: ${error}\n`));
}
Deno.exit(1);
}
});
export const buildCommand = new Command()
.description("Build and Push Auth Image")
.action(async () => {
try {
const loadedEnv = await readEnv();
const currentConfig: AuthSetupConfig = {
...DEFAULT_AUTH_CONFIG,
...loadedEnv,
};
const commands = generateBuildCommands(currentConfig.reg);
await executeBuildImage(commands);
console.log(
colors.green("\n✓ Successfully built and pushed auth image!"),
);
console.log(
colors.green("You may now deploy your stack by running:\n"),
);
console.log(
colors.cyan(
"podman-compose --project-name auth-yes --env-file infra/stack.env -f infra/compose.yml up -d\n",
),
);
} catch (error) {
if (error instanceof Error) {
console.log(
colors.red(`\n✗ Build process failed: ${error.message}\n`),
);
} else {
console.log(colors.red(`\n✗ Build process failed: ${error}\n`));
}
Deno.exit(1);
}
});
export const releaseCommand = new Command()
.description(
"Run complete build & release pipeline with copy-paste deployment instructions",
)
.action(async () => {
console.log(
colors.bold(
colors.blue(
"\n================================================================",
),
),
);
console.log(
colors.bold(
colors.green(
" Auth-Yes Infrastructure Build & Release Pipeline",
),
),
);
console.log(
colors.bold(
colors.blue(
"================================================================\n",
),
),
);
// 1. Quality Gates
console.log(colors.cyan("[1/4] Running Quality Gates & Test Suite..."));
const testCmd = new Deno.Command("deno", {
args: ["task", "test"],
stdout: "inherit",
stderr: "inherit",
});
const testRes = await testCmd.output();
if (testRes.code !== 0) {
console.error(
colors.red("\n✗ Quality gates failed. Aborting release."),
);
Deno.exit(1);
}
// 2. Compile Protobufs
console.log(
colors.cyan("\n[2/4] Downloading & Compiling Protobufs..."),
);
await downloadWorkloadProto();
await executeProtobufCompilation();
// 3. Build & Push Images
console.log(
colors.cyan(
"\n[3/4] Building and Pushing Custom Container Images...",
),
);
const loadedEnv = await readEnv();
const currentConfig: AuthSetupConfig = {
...DEFAULT_AUTH_CONFIG,
...loadedEnv,
};
const commands = generateBuildCommands(currentConfig.reg);
await executeBuildImage(commands);
console.log(
colors.green(
"\n✓ Successfully built and pushed all stack images to " +
currentConfig.reg + "!",
),
);
// 4. Output Copy-Paste Guides
console.log(
colors.cyan(
"\n[4/4] Release Complete. Deployment & Configuration Guides:\n",
),
);
console.log(
colors.bold(
colors.yellow(
"┌──────────────────────────────────────────────────────────────┐",
),
),
);
console.log(
colors.bold(
colors.yellow(
"│ A. FOR NEW SYSTEM INSTALLATIONS │",
),
),
);
console.log(
colors.bold(
colors.yellow(
"└──────────────────────────────────────────────────────────────┘",
),
),
);
console.log(
colors.gray("# 1. Inspect environment variables and secrets:"),
);
console.log(colors.cyan("deno task setup dump_env"));
console.log(
colors.gray("\n# 2. Inspect generated Docker Compose files:"),
);
console.log(colors.cyan("deno task setup dump_compose"));
console.log(
colors.gray("\n# 3. Create persistent storage paths on host:"),
);
console.log(
colors.cyan(
`mkdir -p ${currentConfig.spireDataPath} ${currentConfig.dbDataPath}`,
),
);
console.log(colors.gray("\n# 4. Deploy fresh stacks:"));
console.log(
colors.cyan(
"podman-compose --project-name spire --env-file infra/.env.spire -f infra/compose.spire.yml up -d",
),
);
console.log(
colors.cyan(
"podman-compose --project-name auth-yes --env-file infra/stack.env -f infra/compose.yml up -d",
),
);
console.log(
colors.bold(
colors.yellow(
"\n┌──────────────────────────────────────────────────────────────┐",
),
),
);
console.log(
colors.bold(
colors.yellow(
"│ B. FOR EXISTING SYSTEM UPDATES (ROLLING RESTART) │",
),
),
);
console.log(
colors.bold(
colors.yellow(
"└──────────────────────────────────────────────────────────────┘",
),
),
);
console.log(
colors.gray(
"# Pull newly pushed custom images and restart containers:",
),
);
console.log(
colors.cyan(
"podman-compose --project-name spire --env-file infra/.env.spire -f infra/compose.spire.yml pull",
),
);
console.log(
colors.cyan(
"podman-compose --project-name spire --env-file infra/.env.spire -f infra/compose.spire.yml up -d\n",
),
);
console.log(
colors.cyan(
"podman-compose --project-name auth-yes --env-file infra/stack.env -f infra/compose.yml pull",
),
);
console.log(
colors.cyan(
"podman-compose --project-name auth-yes --env-file infra/stack.env -f infra/compose.yml up -d\n",
),
);
});