Skip to content

2.3 Setup Build and Test Environment

gyk4j edited this page Dec 12, 2024 · 3 revisions

TOC can be run and hosted locally on self-hosted server, or remotely on cloud provider infrastructure. Configuration files for common Infrastructure-as-Code tools are provided. At the moment, Vagrant is used to create virtual machines locally on VirtualBox for a developer workstation or self-hosted server. Terraform is used for creating a similar setup on the Amazon Web Services (AWS) cloud.

In essence, we need to setup 2 virtual machines to simulate a local main site for backing up and a remote stepup site for restoring backups. When deploying on AWS, they would be the Elastic Compute Cloud (EC2) instances and are billed according to usage.

Note

Both methods rely on the shared provisioning / user data scripts in the provision directory to configure the virtual machines, be it in the AWS cloud or locally on developer's workstation or self-hosted infrastructure.

Tip

For cloud deployment, it may be possible to utilize Docker container-related services such as Amazon ECS or AWS Fargate instead of creating 2 EC2 instances and installing Docker ourselves. Currently, this is done for reusing the provisioning scripts, and avoiding having to write more configuration files for such alternative services.

Local virtual machines with VirtualBox and HashiCorp Vagrant

Run the following command in the toc project directory where Vagrantfile is.

$ vagrant up

Note

To use a different Linux distribution, edit the Vagrantfile, in particular the BOX_BASE variable and PROVISIONING_SCRIPT variable.

When we are done, run the following command.

$ docker compose down
$ exit
$ vagrant halt

Cloud with Amazon Web Services (AWS) and HashiCorp Terraform

Run the following command in the toc project directory where the .tf files are.

$ terraform init
$ terraform validate
$ terraform plan
$ terraform apply
$ terraform output

When we are done, we must remember to stop and free all resources to avoid continued billing for leaving resources running on a pay-per-use cloud provider like AWS. To do so, run the following command.

$ docker compose down
$ exit
$ terraform destroy

Tip

It is a good practice to double check in the AWS console for any resources that Terraform fails to destroy and free up. In most cases, it should not happen, but it pays to be careful to avoid incurring unexpected usage bills.