CI/CD Staging Deployment
We initially deployed to AWS using the cdk deploy
CLI commands to get our infrastructure up and running. That was essential for the first deployment and setup.
Going forward, whenever we make changes to our code, we can just commit and push like usual. Thanks to our CI/CD pipeline, these updates will automatically trigger a deployment to our AWS infrastructure.
We've already configured the necessary secrets and variables in GitHub Actions, so our main.yml
will take care of the rest—deploying everything for you as soon as you push your changes.
Deployment Trigger:
- Staging: Deploys when you commit and push to the
staging
branch.
⚠️ Make sure that you have cloned the AWSLaunchGOAT-Backend
repository and have your own GitHub repository prepared.
Step-by-Step
- Create a new branch
staging
from themain
branch.
Ensure that you are working on staging
branch.
- Let's update our code in
src/app.ts
by adding three exclamation marks:!!!
- Commit and sync changes (push). You can also do this via the command line.
- Go to GitHub Actions, and you will see that your workflow is now running.
- Click on the updated app.ts workflow, and you will notice that it is running the
test
step first.
⚠️ At the testing stage, docker-compose.test.yml
is used in our CI/CD pipeline for staging. It loads Dockerfile.staging
, replicating the staging environment to ensure that your changes are thoroughly tested before deployment.
- Apply the migration file to populate the tables and columns.
- After a few minutes, the entire workflow will fail because it encountered an error during the
test
stage.
- Let's update the test script. Go to
tests/endpoints.test.ts
and add three exclamation marks. Commit and push again. Go back to the GitHub Actions.
- Your
test
stage should now be successful, and the workflow will proceed toDeploy to Staging
.
- Once completed, let's check our endpoint. Go to
Load balancers
from the AWS Management Console.
- Copy the
DNS name
and paste it into the browser.
- If you see three exclamation marks, then you're right on! (Make sure you are on http, not https)
- Lastly, since the migration file has been applied and the user table is populated, we can check if the
/users
endpoint is working.
404, Users not found is the message we want to see.