Automated preview environments
One of the largest benefits of Architects framework is that provisioning new environments is always limited to a single step, architect deploy
. No matter how complex the application is or how many dependencies it has, architect deploy
is able to automatically provision it in a new environment.
What this means is that not only can developers run the stack privately, but the stack can also be provisioned automatically whenever there is a new branch or pull request. This automation is perfect for creating previews of impending code changes so that product managers can review and integration tests can be run end to end.
Github Actions
Create preview environment
The workflow below can be pasted into a file in your repository in the .github/workflows
folder to trigger automated preview environments via Architect. These previews will be created whenever a pull request is submitted that targets the master branch. Be sure to set values in Github Secrets for the architect fields: ARCHITECT_EMAIL
and ARCHITECT_PASSWORD
. Replace <account-name>
, <cluster-name>
with the appropriate values.
ARCHITECT_PASSWORD
must be a personal access
token.
Cleaning up the environment
Once your PR is closed, either because it was merged in successfully or closed and rejected, you’ll likely want to clean up the environment so that you don’t incur continued costs. Github Actions and Architect make this easy, and you can just copy and paste the following workflow into another file in your .github/workflows
folder:
Post updates to slack
Depending on the size of your application your PR environment might take a while to first boot up. If you want to receive notifications in slack when the deployments are done, use slacks github action as the last step in your PR workflows. Just replace <slack-webhook-url>
with one you generate from your slack organization settings:
Gitlab CI
Creating and cleaning up preview environments
This job can be pasted into your .gitlab-ci.yml
at the root of your repository. You are welcome to change the stage
to whatever fits your needs to allow you to run
tests before the preview is generated. Please be sure to assign correct values for the variables in the job marked with <set-this-as-a-CI/CD-variable>
as well as the
ones mentioned in the note below.
This configuration takes advantage of GitLab environments in order to give you better control and visibility into what environments exist and what’s deployed to them. On PR creation, both a GitLab and Architect environment will be created. The component specified in the repository will be registered with the Architect Cloud and deployed to the environment. When the PR is either merged or closed, the GitLab environment will be automatically deleted and the component deployed to the environment in the Architect Cloud will be destroyed.
This example assumes that the repo has ARCHITECT_EMAIL
, ARCHITECT_PASSWORD
, ARCHITECT_ACCOUNT
, and ARCHITECT_CLUSTER
set as CI/CD variables.
ARCHITECT_PASSWORD
must be a personal access
token.
BitBucket Pipelines
Creating and cleaning up preview environments
This job can be pasted into your bitbucket-pipelines.yml
at the root of your repository. Be sure to add repository variables for the ones mentioned in the note below.
On pull request creation, an Architect environment will be created. The component specified in the repository will be registered with the Architect Cloud and deployed to the environment. The pipeline provides the option to remove the deployed component and its environment from the Architect Cloud manually, which should be done once the pull request is merged or closed.
This example assumes that the repo has ARCHITECT_EMAIL
, ARCHITECT_PASSWORD
, ARCHITECT_ACCOUNT
, and ARCHITECT_CLUSTER
set as CI/CD variables.
ARCHITECT_PASSWORD
must be a personal access
token.
The --ttl
flag is used here in order to clean up the environment automatically after one day because BitBucket doesn’t have a feature to trigger a pipeline when a pull request is closed.
CircleCI
CircleCI doesn’t have complete features to handle preview environment creation and destruction, but the Trigger CircleCI Pipeline GitHub Action can help to work around that. The CircleCI GitHub Action can be used in combination with GitHub’s event triggers to run a CircleCI workflow.
This example assumes that ARCHITECT_EMAIL
, ARCHITECT_PASSWORD
, ARCHITECT_ACCOUNT
, and ARCHITECT_CLUSTER
are set as project variables in CircleCI.
Also, the variable CCI_TOKEN
must be a CircleCI personal access token and be set as a GitHub Action secret in the GitHub repo.
CCI_TOKEN
should not be set to a CircleCI project-specific API token.
ARCHITECT_PASSWORD
must be a personal access
token.
Preview environment creation trigger
The file circleci-create-preview.yml
will trigger a CircleCI workflow to be run when a pull request is created or updated in GitHub. Note that GHA_Meta
is set to ARC_CREATE_PREVIEW
in order to inform the CircleCI workflow to run only the preview creation job.
Preview environment destruction trigger
The file circleci-destroy-preview.yml
will trigger a CircleCI workflow to be run when a pull request is closed in GitHub. As preview environments are named preview-<pull_request_number>
in the CircleCI workflows, GHA_Meta
is set to the pull request number in order to let the CircleCI preview destruction workflow know which component and environment to destroy.
This is set in the GitHub Action and passed to CircleCI because this number isn’t available in a CircleCI workflow when a pull request is closed.
Preview environment workflows
The CircleCI config file will run the actual Architect preview environment creation and destruction workflows triggered by the GitHub Actions. The workflow conditions are set so that
a preview environment will be created when the workflow is triggered with << pipeline.parameters.GHA_Meta >>
equal to ARC_CREATE_PREVIEW
. A preview environment destruction workflow
will be triggered when << pipeline.parameters.GHA_Meta >>
isn’t equal to ARC_CREATE_PREVIEW
.