-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
build: CDK for infrastructure management and deployment #2576
base: master
Are you sure you want to change the base?
build: CDK for infrastructure management and deployment #2576
Conversation
- name: Run Semantic Release | ||
id: semantic_release | ||
run: | | ||
npx semantic-release --ci | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should work because it's not a PR coming in from a fork. semantic-release
needs write access to make a commit (update version
in package.json
) and create a tag.
strategy: | ||
matrix: | ||
target: | ||
- development | ||
- production |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will create 2 parallel jobs but both require manual approval before starting so development can be deployed first. We could have a deploy_dev
and deploy_prod
job that needs the dev one instead.
463335e
to
3af9871
Compare
export class BootstrapStack extends cdk.Stack { | ||
constructor(scope: Construct, id: string, props?: cdk.StackProps) { | ||
super(scope, id, props); | ||
|
||
const pipeline = new Pipeline(this, 'Pipeline', { | ||
githubRepositories: ['dekkerglen/CubeCobra'], | ||
}); | ||
|
||
new ssm.StringParameter(this, 'GitHubActionsRoleArnParameter', { | ||
parameterName: '/cdk/bootstrap/github-actions-role-arn', | ||
stringValue: pipeline.githubRole.roleArn, | ||
}); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need this role so that GitHub can deploy CDK. It needs to be one once before anything else. @dekkerglen can create it locally on his machine with:
npx cdk deploy --context environment=development --context bootstrap=true
npx cdk deploy --context environment=production --context bootstrap=true
then the role should be stored in environment secrets on GitHub as CDK_IAM_ROLE
.
Build and Release
Goals
How it works
On manual input, the workflow should do the following:
Manual input will be needed for the deployments to actually go through. This has to be enabled in the environment settings on the repository:
I'm bringing semantic versioning. It's used for a few things but primarily to keep the package.json's version field up-to-date. It'll also create the tags and generate a CHANGELOG.md file. A lot of this depends on conventional commits so if it's too involved then we can just drop it. I know that @dekkerglen publishes a blog on the website for bigger releases so the automated change log might be useful.
Deployment
Adding a workflow to deploy CDK changes. It can be used manually to deploy or be called by another workflow (like the app release) to trigger a deployment of the infrastructure with CDK.
The values picked there are passed as context values to CDK to determine which environment to deploy into.
It requires a role which can be created by CDK so this will require one last manual run by @dekkerglen to get the role created. Then, it needs to be added as a secret on the repository (
CDK_IAM_ROLE
). There are also a couple more secrets to add, mostly the values that are taken from the environment variables.Scheduled Jobs
Creating a Fargate cluster and a reusable way for us to deploy scheduled jobs to it. For a given job it will create:
All we need to do afterwards is push an image to the ECR repository and Fargate will take care of the rest. There is a bit of a chicken-and-egg situation where we need the repository created to be able to push to it but the task definition needs a repository. What would happen now is this:
From this point on the job will run on schedule but fail immediately (can't pull the image because it doesn't exist). I think we're fine with this? It means very minimal costs because nothing runs. Once we push the image to the repository the next scheduled run will execute as expected.
A bit of restructuring
The goal was to reorganize the code a bit so that the main stack file didn't grow too wildly. I wanted to make sure that the generated CloudFormation template was the same so I generated both and diffed them: