
Workflows as Code with CodeCatalyst-Blueprints
You do not need custom blueprints enabled to generate CodeCatalyst workflows as code - Blueprint hack
blueprint.ts
file, developers can succinctly express workflows as code, promoting readability and collaboration without CodeCatalyst Enterprise tier.projenrc.ts
as ProjenBlueprintProjenBlueprint
1
2
3
4
5
➜ projen new typescript --no-git --projenrc-ts --github false --dev-deps "@amazon-codecatalyst/blueprint-util.projen-blueprint" "@amazon-codecatalyst/blueprint-util.cli"
👾 Project definition file was created at /private/tmp/blueprint/.projenrc.ts
👾 Installing dependencies...
👾 install | yarn install --check-files
yarn install v1.22.19
.projenrc.ts
with the following code1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { ProjenBlueprint } from '@amazon-codecatalyst/blueprint-util.projen-blueprint';
const project = new ProjenBlueprint({
name: 'cdk-todo-web-app',
defaultReleaseBranch: 'main',
projenrcTs: true,
sampleCode: false,
github: false,
tsconfig: {
compilerOptions: {
esModuleInterop: true,
noImplicitAny: false,
},
},
deps: [
'projen',
'@amazon-codecatalyst/blueprints.blueprint',
'@amazon-codecatalyst/blueprint-component.workflows',
'@amazon-codecatalyst/blueprint-component.source-repositories',
'@amazon-codecatalyst/blueprint-component.dev-environments',
'@amazon-codecatalyst/blueprint-component.environments',
],
devDeps: [
'ts-node@^10',
'typescript',
'@amazon-codecatalyst/blueprint-util.projen-blueprint',
'@amazon-codecatalyst/blueprint-util.cli',
],
});
project.synth();
projen
to update the package.json
, .projen
, and other files managed by Projen1
2
3
4
5
➜ projen
👾 default | ts-node --project tsconfig.dev.json .projenrc.ts
👾 Installing dependencies...
👾 install | yarn install --check-files
yarn install v1.22.19
blueprint.ts
` file encompasses the following elements:1
2
3
const repository = new SourceRepository(this, {
title: "cdk-todo-web-app",
});
1
2
3
4
5
6
7
8
9
10
const environment = new Environment(this, {
name: "default_environment",
environmentType: "DEVELOPMENT",
description: "Blueprint environment",
awsAccount: {
cdkRole: { name: CDK_DEFAULT_ROLE },
id: CDK_DEFAULT_ACCOUNT,
name: CDK_DEFAULT_ACCOUNT,
},
});
1
2
3
4
5
6
7
8
9
export interface ActionProps {
actionName: string;
identifier: string;
steps: string[];
environment?: WorkflowEnvironment;
dependancies?: string[];
inputs?: { [key: string]: any[] };
outputs?: { [key: string]: any };
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/**
* Generate an action for the workflow
* @param props ActionProps
* @returns Action
*/
export function GenerateAction(props: ActionProps) {
return {
[props.actionName]: {
Identifier: props.identifier,
Inputs: props.inputs ? props.inputs : { Sources: ["WorkflowSource"] },
Outputs: props.outputs
? props.outputs
: {
AutoDiscoverReports: {
IncludePaths: ["**/*"],
ExcludePaths: ["*/.codecatalyst/workflows/*"],
ReportNamePrefix: "AutoDiscovered",
Enabled: true,
},
},
Configuration: {
Steps: props.steps.map((step) => ({ Run: step })),
},
Environment: props.environment,
DependsOn: (props.dependancies) ? props.dependancies : undefined,
},
};
}
1.
FrontendBuildAndPackage
2.
FrontendTest
3.
CDKBootstrapAction
4.
CDKDeploy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const workflowBuilder = new WorkflowBuilder(this, {
Name: "main_fullstack_workflow",
Compute: {
Type: ComputeType.EC2,
Fleet: ComputeFleet.LINUX_X86_64_LARGE,
},
Triggers: [
{
Branches: ["main"],
Type: TriggerType.PUSH,
},
],
Actions: {
...frontendBuildAndPackage,
...frontendTest,
...cdkBootstrapAction,
...cdkDeploy,
},
});
1
new Workflow(this, repository, workflowBuilder.getDefinition());
yarn blueprint:synth
(This script is from `package.json
`)1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
➜ cdk-todo-web-app git:(main) ✗ yarn blueprint:synth
yarn run v1.22.19
$ blueprint drive-synth --blueprint ./ --outdir ./synth --default-options ./src/defaults.json --additional-options ./src/wizard-configurations $*
[1706372494181] INFO (5048 on Daos-MBP): Running in quick mode. Run this command with --cache to emulate the wizard
[1706372494192] INFO (5048 on Daos-MBP): ==========================================
[1706372494192] INFO (5048 on Daos-MBP): [00.synth.defaults.json]
[1706372494192] INFO (5048 on Daos-MBP): npx blueprint synth --options merge[./src/defaults.json,./src/defaults.json] --blueprint ./ --outdir synth/00.synth.defaults.json/proposed-bundle
[1706372494192] INFO (5048 on Daos-MBP): ==========================================
===== Starting synthesis =====
options: {}
outputDir: synth/00.synth.defaults.json/proposed-bundle
Instantiations location not specified
running synthesis into /codecatalyst/cdk-todo-web-app/synth/00.synth.defaults.json/proposed-bundle/src/cdk-todo-web-app
===== Ending synthesis =====
✨ Done in 2.10s.
synth/00.synth.defaults.json/proposed-bundle
` and we have our workflow YAML file is located at `synth/00.synth.defaults.json/proposed-bundle/src/cdk-todo-web-app/.codecatalyst/workflows/main_fullstack_workflow.yaml
`1
2
3
4
5
6
➜ cdk-todo-web-app git:(main) ✗ tree synth/00.synth.defaults.json/proposed-bundle/src/cdk-todo-web-app/.codecatalyst
synth/00.synth.defaults.json/proposed-bundle/src/cdk-todo-web-app/.codecatalyst
└── workflows
└── main_fullstack_workflow.yaml
2 directories, 1 file
1
➜ cdk-todo-web-app git:(main) ✗ cp synth/00.synth.defaults.json/proposed-bundle/src/cdk-todo-web-app/.codecatalyst/workflows/main_fullstack_workflow.yaml .codecatalyst/workflows/main_fullstack_workflow.yaml