logo
Menu
Workflows as Code with CodeCatalyst-Blueprints

Workflows as Code with CodeCatalyst-Blueprints

You do not need custom blueprints enabled to generate CodeCatalyst workflows as code - Blueprint hack

Published Jan 30, 2024
Last Modified Jul 24, 2024

Abstract

This blog introduces how to optimize workflow management within the Amazon ecosystem using codecatalyst-blueprints. By employing a blueprint.ts file, developers can succinctly express workflows as code, promoting readability and collaboration without CodeCatalyst Enterprise tier

Blueprints introduction

Blueprints are code generators used to create and maintain projects in Amazon CodeCatalyst. You can build your own blueprint (Custom Blueprints) today by upgrading to the CodeCatalyst Enterprise tier. An integral aspect of Blueprints involves workflow generation. Disregarding the CodeCatalyst Enterprise tier, we can utilize this feature to create CodeCatalyst workflows as code, utilizing the preferred programming language, such as Typescript.

Init Blueprint project using Projen

We cannot use Projen to init a blueprint project as AWS CDK or CDK8S, but we can do a trick by init TypeScript project and then update .projenrc.ts as ProjenBlueprint
While we cannot directly use Projen to initialize a blueprint project such as AWS CDK or CDK8S, we can employ a workaround. Initialize a TypeScript project first, and then update the `.projenrc.ts` file using ProjenBlueprint
To initialize a TypeScript project using Projen, you can use the following command
Override the .projenrc.ts with the following code
Then run projen to update the package.json, .projen, and other files managed by Projen

Write blueprint.ts to build worksflow

If you've utilized CodeCatalyst custom blueprints, you are likely familiar with blueprint.ts, which contains code for generating UI options, environment settings, source repository configurations, and workflows. When creating a custom blueprint, these elements are automatically generated. However, if your goal is to leverage the CI/CD capabilities of the CodeCatalyst workspace without requiring all components, you specifically need the workflow generation part.
In short, the `blueprint.ts` file encompasses the following elements:
1. Source repository - serves as a reference point for workflow configurations
2. Environment - Where we define the CI/CD environment, including the connection to the AWS account.
3. Workflow Actions
- An Action includes the following major components
- A wrapper function that generates a workflow Action based on the interface
- We will have following actions
1. FrontendBuildAndPackage
2. FrontendTest
3. CDKBootstrapAction
4. CDKDeploy
4. WorkflowBuilder - Responsible for defining the workflow name, compute type, trigger type, and the required actions
5. Workflow - Collects all WorkflowBuilder instances and incorporates them into the source code repository

Generate workflow yaml file

Run yarn blueprint:synth (This script is from `package.json`)
We have the generated files in `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`
Copy the YAML file
Now we can push the code to the repository and check the workflow run

Conclusion

Congratulations! You have successfully generated CodeCatalyst workflows as code using codecatalyst-blueprints without enabling the CodeCatalyst Enterprise tier.
You can create an Action to automatically generate and update the workflow YAML file by pushing a new commit to the main branch, reflecting changes from the `blueprint.ts` file.
 

Comments