import { Workflow } from 'cdkactions';
import { DjangoProject, ReactProject, IntegrationTestsJob, DeployJob } from '@pennlabs/kraken';
const workflow = new Workflow(this, 'workflow', {
name: 'Build, Test, and Deploy',
on: 'push',
});
// Build backend without publishing (for testing)
const backend = new DjangoProject(workflow, {
projectName: 'myapp',
path: 'backend',
imageName: 'myapp-backend',
publishProps: {
noPublish: true, // Don't publish yet, wait for tests
},
});
// Build frontend without publishing (for testing)
const frontend = new ReactProject(workflow, {
path: 'frontend',
imageName: 'myapp-frontend',
publishProps: {
noPublish: true, // Don't publish yet, wait for tests
},
});
// Run integration tests and publish if they pass
const integrationTests = new IntegrationTestsJob(
workflow,
{
testCommand: `
docker-compose -f docker-compose.test.yaml exec -T backend python manage.py test integration
docker-compose -f docker-compose.test.yaml exec -T frontend yarn test:e2e
`,
dockerBuildIds: [
'build-backend',
'build-frontend',
],
dockerImages: [
backend.dockerImageName,
frontend.dockerImageName,
],
createPostIntegrationPublishJob: true, // Publish after tests pass
},
{
needs: [backend.publishJobId, frontend.publishJobId],
}
);
// Deploy after images are published
new DeployJob(
workflow,
{},
{
needs: integrationTests.finalJobId, // Wait for publish job
}
);