Refactor preview deployments to use a single shared Caddy gateway container with subdomain routing (<previewId>.localhost:<port>) instead of one Caddy sidecar and one port per preview. Adds dev/preview modes, git worktree support for branch checkouts, and auto-start on phase:pending_review. - Add GatewayManager for shared Caddy lifecycle + Caddyfile generation - Add git worktree helpers for preview mode branch checkouts - Add dev mode: volume-mount + dev server image instead of build - Remove per-preview Caddy sidecar and port publishing - Use shared cw-preview-net Docker network with container name DNS - Auto-start previews when phase enters pending_review - Delete unused PreviewPanel.tsx - Update all tests (40 pass), docs, events, CLI, tRPC, frontend
54 lines
1.7 KiB
TypeScript
54 lines
1.7 KiB
TypeScript
/**
|
|
* Preview Router — start, stop, list, status for Docker-based preview deployments
|
|
*/
|
|
|
|
import { z } from 'zod';
|
|
import type { ProcedureBuilder } from '../trpc.js';
|
|
import { requirePreviewManager } from './_helpers.js';
|
|
|
|
export function previewProcedures(publicProcedure: ProcedureBuilder) {
|
|
return {
|
|
startPreview: publicProcedure
|
|
.input(z.object({
|
|
initiativeId: z.string().min(1),
|
|
phaseId: z.string().min(1).optional(),
|
|
projectId: z.string().min(1),
|
|
branch: z.string().min(1),
|
|
mode: z.enum(['preview', 'dev']).default('preview'),
|
|
worktreePath: z.string().optional(),
|
|
}))
|
|
.mutation(async ({ ctx, input }) => {
|
|
const previewManager = requirePreviewManager(ctx);
|
|
return previewManager.start(input);
|
|
}),
|
|
|
|
stopPreview: publicProcedure
|
|
.input(z.object({
|
|
previewId: z.string().min(1),
|
|
}))
|
|
.mutation(async ({ ctx, input }) => {
|
|
const previewManager = requirePreviewManager(ctx);
|
|
await previewManager.stop(input.previewId);
|
|
return { success: true };
|
|
}),
|
|
|
|
listPreviews: publicProcedure
|
|
.input(z.object({
|
|
initiativeId: z.string().min(1).optional(),
|
|
}).optional())
|
|
.query(async ({ ctx, input }) => {
|
|
const previewManager = requirePreviewManager(ctx);
|
|
return previewManager.list(input?.initiativeId);
|
|
}),
|
|
|
|
getPreviewStatus: publicProcedure
|
|
.input(z.object({
|
|
previewId: z.string().min(1),
|
|
}))
|
|
.query(async ({ ctx, input }) => {
|
|
const previewManager = requirePreviewManager(ctx);
|
|
return previewManager.getStatus(input.previewId);
|
|
}),
|
|
};
|
|
}
|