In my previous post, I discussed how I am hosting this site. As the title of this next article suggests, we will now be focusing on the steps I took to add basic CI/CD functionality to my website using GitHub Actions. The primary benefit of this being that each time I push a new change to the
main branch of my GitHub repository, my website will be automatically updated with the latest content.
In case you’re interested in following along, you will need:
- An existing GitHub account
- An existing GitHub repository for your website (this is where the GitHub Action will live)
- An existing website hosted in AWS (using S3 and CloudFront)
In order to add this automated deployment capability to our website we are really just concerned with two services and making sure they can communicate. In this case, those services are GitHub and AWS. In AWS, all entities are generally assigned some combination of an IAM user/role/policy (i.e. some predefined set of permissions) which determines what resources they can access. With this in mind, I’ve split the general steps I used to create the communication channel between these two services and outlined them below.
- Create new IAM entities in your AWS account to grant appropriate access to the GitHub Actions runner, which will be handling the actual file upload/sync work during the deployments
- IAM User - Create an IAM user, preferably with a descriptive name like “
gitlab-access-runner” (for this implementation to work this user will need an AWS access and secret access key).
- IAM Policy - Create an IAM Policy similar to the one below that will grant access to your S3 bucket (for file sync) and cloudfront distribution (to create invalidations) and attach it to your newly created user:
Once things are configured in AWS you can head back over to GitHub and start creating your new Action!
- Create a new GitHub Action in your GitHub repository
- Add the required IAM values to your Action Secrets
- Add the deployment instructions via
yamlto your Action which will tell the Action exactly what to do with your code and when:
Once you’ve configured the above you should be able to test your CI/CD flow all the way through by either manually triggering your Action or making a simple change to your GitHub repo’s
Congrats! If you weren’t already an expert hopefully this has given you a glimpse into the power provided by tools like GitHub Actions and CI/CD as a whole.
This is just one possible implementation of many and although it worked well for my simple use case, it may need some adaptation to fit your needs.