In one of my projects we are using GitHub flow. The branching model follows:
- A ticket is created on Jira (OSCS-103)
- A branch is created from
master
, calledOSCS-103
. - A PR is created on this branch as soon as it's created, with a custom environment where it can be tested, where the UI is located at
oscs-103.x.com
. - Once the PR is closed, the environmet is deleted (using Terraform).
- Everything in
master
is consideredint
and is ready for release, this can be accessed viaint.x.com
. - Once a release is created, everything in
master
is pushed to the prod envronment,x.com
Currently, the process of creating different envs per brach is 'manual', we run the following command:
$ terraform init
$ terraform workspace new OSCS-103
$ terraform apply -var="source_branch=OSCS-203" -var="token=$GITHUB_TOKEN"
This spins up a new environment in Terraform where we use the source_branch
to create a pipeline.
Once we are done with this environment, we perform:
$ terraform init
$ terraform workspace select OSCS-103
$ terraform destroy -var="source_branch=OSCS-203" -var="token=$GITHUB_TOKEN"
However, I would like to automate this process, so that whenever a PR is created, an env is automatically created (ideally using AWS CodePipeline or AWS CodeBuild), and when the PR is closed/merged, the env is destroyed.
Does anyone have any examples of them doing this?
Edit:
Just to clarify, the terraform
commands above are creating a pipeline, this pipeline "listens" to changes on the source_branch
and runs a script that checks for infra changes (with terraform and makes changes if necessary), rebuilds and deploys the UI, rebuilds and deploys the API, as well as running flyway
to migrate DB changes.