Reddico 'R' Symbol

Automate your codebase: Using tools to save time when developing

Ainsley Clark

Posted by Ainsley Clark

16 September 2021

Over the last few months we’ve been looking at how to deploy websites, resources and apps in a more efficient way.

After looking at various CI/CD tools and CLI applications, we found that Github actions was the most coherent tool, as it’s baked directly into the repository. There are thousands of actions available on the marketplace to help you deploy and manage your codebase.

Source: https://github.com/features/actions

A few examples of our automations using actions are below.

Deploying multiple repositories to a centralised website

When creating a resource for a client and setting up a staging environment, we used to have to pull a repo from a VM, set up an A record, SSH key, the list continues... To help streamline this process, we decided to have a centralised repository for all resources for staging environments:

  • Developer merges a branch into staging.

  • Github action loads .env file containing the URL.

  • Theme is built using Hugo with the correct path.

  • The built theme (a public directory) is copied over to the central repository.

  • The site is then automatically deployed to Google’s Cloud Run using an nginx docker container.

This shaves hours off our workflow and deployment becomes a breeze.

Using CI/CD to run tests and calculate code coverage

Our home-grown GoLang CMS platform, Verbis, needed a way to run tests in different environments and calculate code coverage using Codecov on each pull request. Our pipeline is below.

  • Build script runs on each pull request into the master branch.

  • All unit tests are run and coverage reports are uploaded.

This is a great way to see if tests are failing, or the coverage is down on each request. Using GoReleaser, we could tie in automatic releases with semantic versioning for the CMS.

Use GoLang CLI to create a boilerplate website/resource repository

Creating resources and websites can sometimes be tedious and time consuming, particularly if they stem from the same boilerplate. So we started experimenting with different boilerplate implementations.

GitHub templates didn't give us the full rich feature set we were looking for, so we decided to create a GoLang CLI to automatically clone a boilerplate repository and push to a new one with relevant branches and a default Reddico theme.

  • The developer enters in the relevant details for a new resource.

  • A zip containing a boilerplate is downloaded and extracted to a folder on the developer’s machine.

  • Paths and .env files are set using the arguments passed.

  • A new repository is created with three branches, dev, staging and master, which all have the relevant Github workflows to automatically deploy to a Cloud Run instance.

In spite of the CLI taking a couple of days to set up, it saves a huge amount of time in the long run.

Wrapping up

By using various tools and workflows, you can help speed up your deployment process, whether it be a website, microservice or backend. Setting up workflows is extremely simple and used in combination with environments, it gives the developer fine-grained control of how and when deployments should be made. We’ve certainly noticed the benefits of using these tools, we hope you do too!