Add CICD pipeline for automated deployment #234
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What I'm adding
This PR adds automated deployments of the project. It implements the following deployment strategies:
main
are deployed to thedev
stageprod
stageThis provides us a multi-step workflow, as such:
Once merged to
main
, it will also add a dropdown similar to this within the Actions UI:How I did it
This deployment follows what I understand to be best practice for deploying to AWS from Github Actions and follows the strategy outlined in Configuring OpenID Connect in Amazon Web Services. It basically works as follows:
arn:aws:iam::830244800171:oidc-provider/token.actions.githubusercontent.com
arn:aws:iam::830244800171:role/animl-api-dev-cicd-role
arn:aws:iam::830244800171:role/animl-api-prod-cicd-role
Currently, these IAM roles are configured with Trust Relationships that only allow them to be assumed by the Github identity provider from workflows within the
tnc-ca-geo/animl-api
repo (see JSON here).Caution
These roles are granted with
AdministratorAccess
, which basically allows them to do anything with the AWS account. I recommend tightening these permissions to only grant the roles with minimal permissions necessary to deploy to each respective environment. This can be achieved by running a deployment and then using AWS IAM Access Analyzer to determine which permissions were used.dev
DEPLOYMENT_ROLE_ARN
:arn:aws:iam::830244800171:role/animl-api-dev-cicd-role
prod
DEPLOYMENT_ROLE_ARN
:arn:aws:iam::830244800171:role/animl-api-prod-cicd-role
.github/workflows/deploy.yml
) to model our deployment process. This workflow will fetch temporary AWS credentials from AWS via the official aws-actions/configure-aws-credentials step. We set the username of the user who kicks off the repo as the session name for betting logging with the AWS account.This updated workflow comes with a few features:
main
. This is a departure from our current functionality.Important
Currently, any user with
WRITE
permissions on the repo can take this action. If we want to make an allowlist for manual deployments, this can be done in theif:
clause of the manual deployment job (see this discussion for more details).While setting this up, I put together this example rep to demonstrate the system: https://github.com/alukach/example-github-actions-deployment-workflow/
How to use it
To make this work, the following GitHub environments must be made in settings (I do not possess these permissions):
dev
DEPLOYMENT_ROLE_ARN
:arn:aws:iam::830244800171:role/animl-api-dev-cicd-role
prod
DEPLOYMENT_ROLE_ARN
:arn:aws:iam::830244800171:role/animl-api-prod-cicd-role
Warning
I haven't had a chance to test the actual deployment via GitHub, however I feel that this PR gets us pretty close to complete.
Closes #204