Add CICD pipeline for automated deployment#234
Open
alukach wants to merge 1 commit into
Open
Conversation
cfdb772 to
88d2b97
Compare
88d2b97 to
a7aac31
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
mainare deployed to thedevstageprodstageThis 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.comarn:aws:iam::830244800171:role/animl-api-dev-cicd-rolearn:aws:iam::830244800171:role/animl-api-prod-cicd-roleCurrently, 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-apirepo (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.devDEPLOYMENT_ROLE_ARN:arn:aws:iam::830244800171:role/animl-api-dev-cicd-roleprodDEPLOYMENT_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
WRITEpermissions 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):
devDEPLOYMENT_ROLE_ARN:arn:aws:iam::830244800171:role/animl-api-dev-cicd-roleprodDEPLOYMENT_ROLE_ARN:arn:aws:iam::830244800171:role/animl-api-prod-cicd-roleWarning
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