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

@@ -120,6 +120,23 @@ export async function composeDown(projectName: string): Promise<void> {
});
}
/**
* Execute a command inside a running service container.
* Used for seed commands (migrations, fixture loading, etc.) after health checks pass.
*/
export async function execInContainer(
projectName: string,
serviceName: string,
command: string,
): Promise<{ stdout: string; stderr: string }> {
const result = await execa('docker', [
'compose', '-p', projectName,
'exec', '-T', serviceName,
'sh', '-c', command,
], { timeout: 300000 }); // 5 min per seed command
return { stdout: result.stdout, stderr: result.stderr };
}
/**
* Get service statuses for a compose project.
*/