Using Github Actions for Automated Testing and Deployment
Background
The source code of tracfee.com is hosted on Github Private.
At a High level, Tracfee’s Architecture involves,
- Single Page Application using VueJS, deployed on Netlify
- API in Go, deployed on Oracle Cloud
So far, API testing has been automated and we were looking at ways to automate deployment of both UI and API. Steps required to deploy API are less since we are using Docker to run it on VM. However, in case of Netlify, it is required to build and then upload the output folder on Netlify.
Accordingly, it was decided to explore Github actions to automate deployment.
Using Github actions
As per Github,
GitHub Actions makes it easy to automate all your software workflows, now with world-class CI/CD. Build, test, and deploy your code right from GitHub. Make code reviews, branch management, and issue triaging work the way you want.
GitHub actions work by provisioning Virtual machine to run an Event based workflow. It provides option to provision Linux/MacOS/Windows based Virtual machines. Steps in Workflow will have to be configured in YAML file. Trigger for Workflow can be (but not limited to) wide variety of events like on Push or commit on branch and so on.
Post trigger, set of action(s) can be configured like,
- Checkout the branch
- Setup environment (Install Node.JS)
- Perform build
- Deployment
Github has Marketplace which has many pre-built actions available. My requirement was to,
- Provision Linux (i.e. ubuntu-latest) Virtual Machine
- Checkout the code (using actions/checkout@v2)
- Setup Node.js (using actions/setup-node)
- perform Build and test using NPM
- Deploy to Netlify using netlify/actions/cli@master
- Any secrets required as part of Workflow can be maintained using Github secrets
Above workflow needs to be maintained in .github\workflows
folder in the repository.
build.yml for tracfee.com looks like,
Refer Gist here.
Testing the Build Workflow
After configuring the workflow steps, next question is to check whether it is possible to test it locally? Luckily, there is tool available to do this. Enter Act , which is a tool to Run your GitHub Actions locally
. Local testing is useful for Faster feedback. In Nutshell, Act uses local docker setup to provision container and then runs workflow steps in it. Give it a try !!
As a next step, Plan is to automate deployment of API on Oracle Cloud using OCI CLI interface.
Useful References,
- Build with GitHub Actions, host on Netlify
- Adventures in CI/CD [#4]: Deploying A Microservice To The Oracle Cloud With GitHub Actions [OCI CLI Edition]
Happy Coding !!