In this post, I’ll outline the tools I used to automate Continuous Integration and Continuous Delivery of a web application so that every team member can focus on what’s important: writing code.
1. Continuous Deployment of front-end
With Git/Github driving continuous integration, how can we automate the process of building the source from last commit and deploying it to the live website (for the production/master branch)? My previous tools of choice were Github pages + Travis, but Yihang introduced to me a more feature-rich solution, Netlify:
Netlify is an all-in-one platform for deploying and automating modern web projects.
Simply push and Netlify provides everything—servers, CDN, continuous delivery, HTTPS, staging environments, prerendering, asset post processing, DNS, and more.
Any project, big or small, can perform instantly on a global scale.
With Netlify, every time you make a commit to the production branch, the configured build command will automatically be executed and the build folder will be deployed to a subdomain provided by Netlify (eg. vis.netlify.com).
2. Continuous Deployment of back-end
I host my back-end (which serves RESTful API to the front-end) on AWS EC2. I make use of Travis CI to build the source (not needed for NodeJS apps not using transpiler) and upload it to Amazon S3, and trigger new deployment on AWS CodeDeploy whenever a new commit is pushed to Github. Lastly, for NodeJS apps, I run pm2 with the command
pm2 start ./bin/www --log-date-format='YYYY-MM-DD HH:mm:ss' --watch
for logging and to automatically restarting the server when CodeDeploy uploads new build files to the EC2 instance.
3. Custom domain
The domain name registrar I’m using is namecheap. For the back-end, I make use of AWS ELB‘s Certificate Manager for provision of the SSL/TLS certificate.
As ELB does not have a static IP address, we cannot use A record to point namecheap domain to the ELB directly.
The solution is to set namecheap’s name servers to AWS Route 53‘s to use it as the custom DNS manager and give AWS complete control over the domain. Then, I create an A record in Route 53 to point to the ELB target, which forwards traffic to the EC2 instances.
For the front-end, I created CNAME records in Route 53 to point the custom domain to the subdomain provided by Netlify.
My final Route 53 Hosted zone configurations:
As Route 53 is not completely free (though it’s dirt cheap), a workaround to avoid using Route 53 is to create a subdomain (eg. www.example.com) to point to the ELB with a CNAME record (which root domains are not allowed to have), then use domain forwarding to forward example.com traffic to www.example.com. The disadvantage of this approach is that it makes your website URL slightly longer (“www” is enforced).
4. Forced HTTPS
Netlify supports automatic TLS certificates with Let’s Encrypt.
To redirect HTTP traffic to HTTPS for the front-end, we can simply configure it under Netlify’s domain management HTTPS settings:
Leave a Reply
You must be logged in to post a comment.