feat: Add seed command support to preview deployments

Run project-specific initialization commands (DB migrations, fixture
loading, etc.) automatically after containers are healthy, before the
preview is marked ready. Configured via per-service `seed` arrays in
.cw-preview.yml.
This commit is contained in:
Lukas May
2026-03-05 12:39:02 +01:00
parent 3913aa2e28
commit 714262fb83
8 changed files with 158 additions and 2 deletions

View File

@@ -25,6 +25,7 @@ import {
isDockerAvailable,
composeUp,
composeDown,
execInContainer,
composePs,
listPreviewProjects,
getContainerLabels,
@@ -230,7 +231,10 @@ export class PreviewManager {
);
}
// 10. Success
// 10. Run seed commands
await this.runSeeds(projectName, config);
// 11. Success
const url = `http://${id}.localhost:${gatewayPort}`;
log.info({ id, url }, 'preview deployment ready');
@@ -477,6 +481,21 @@ export class PreviewManager {
);
}
/**
* Run seed commands for each service that has them configured.
* Executes after health checks pass, before the preview is marked ready.
*/
private async runSeeds(projectName: string, config: PreviewConfig): Promise<void> {
for (const [serviceName, svc] of Object.entries(config.services)) {
if (!svc.seed?.length) continue;
log.info({ projectName, service: serviceName, count: svc.seed.length }, 'running seed commands');
for (const cmd of svc.seed) {
log.info({ service: serviceName, cmd }, 'executing seed');
await execInContainer(projectName, serviceName, cmd);
}
}
}
/**
* Build gateway routes from a preview config.
*/