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:
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user