auth-yes/infra/setup/build.ts
google-labs-jules[bot] 779f890b2f Refactored the 1,000+ line setup.ts into sub-modules
- Extracted CLI commands into infra/setup/cli.ts
- Extracted docker compose configuration to infra/setup/compose.ts
- Extracted env variable generation to infra/setup/env.ts
- Extracted build commands to infra/setup/build.ts
- Retained infra/setup.ts as a simple entrypoint orchestrator

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

74 lines
2.5 KiB
TypeScript

import * as colors from "jsr:@std/fmt@0.225.2/colors";
export function generateProtobufCompilationCommands(): string[] {
return [
"deno",
"run",
"-A",
"npm:@bufbuild/buf",
"generate",
"server/auth.proto",
"--template",
'{"version":"v1","plugins":[{"plugin":"buf.build/bufbuild/es:v1.10.0","out":"sdk/gen","opt":"target=ts,import_extension=.ts"},{"plugin":"buf.build/connectrpc/es:v1.4.0","out":"sdk/gen","opt":"target=ts,import_extension=.ts"}]}',
];
}
// SIDE EFFECT: Runs the protoc compilation
export async function executeProtobufCompilation(): Promise<void> {
const commands = generateProtobufCompilationCommands();
const cmd = new Deno.Command(commands[0], {
args: commands.slice(1),
stdout: "inherit",
stderr: "inherit",
});
const { code } = await cmd.output();
if (code !== 0) {
throw new Error("Failed to compile protobuf definitions.");
}
}
export async function downloadWorkloadProto(): Promise<void> {
console.log(colors.blue("\nDownloading workload.proto..."));
const res = await fetch(
"https://raw.githubusercontent.com/spiffe/go-spiffe/main/proto/spiffe/workload/workload.proto",
);
if (!res.ok) {
throw new Error(`Failed to download workload.proto: ${res.statusText}`);
}
const text = await res.text();
await Deno.mkdir("spire_ffi/proto", { recursive: true });
await Deno.writeTextFile("spire_ffi/proto/workload.proto", text);
console.log(colors.green("✓ workload.proto downloaded successfully."));
}
export function generateBuildCommands(reg: string): string[] {
return [
`podman build -t ${reg}/library/auth-yes-api:latest -f Dockerfile .`,
`podman push ${reg}/library/auth-yes-api:latest`,
`podman build -t ${reg}/library/spire-server:latest -f spire/Dockerfile.server spire/`,
`podman push ${reg}/library/spire-server:latest`,
`podman build -t ${reg}/library/spire-agent:latest -f spire/Dockerfile.agent spire/`,
`podman push ${reg}/library/spire-agent:latest`,
];
}
// SIDE EFFECT: Executes docker build and push commands to the host system
export async function executeBuildImage(commands: string[]): Promise<void> {
for (const cmd of commands) {
console.log(colors.cyan(`\nExecuting: ${cmd}`));
const args = cmd.split(" ");
const process = new Deno.Command(args[0], {
args: args.slice(1),
stdout: "inherit",
stderr: "inherit",
stdin: "inherit",
});
const { code } = await process.output();
if (code !== 0) {
throw new Error(`Command failed with exit code ${code}: ${cmd}`);
}
}
}