Alexecus Portfolio Site

How automation using continuous integration helped on the creation of this site. From server creation and provisioning, up to deployment.

The goal of this project is to allow automated management of servers and deployment by only managing one single user interface. The entire server setup is controlled by code, and is being processed by Gitlab CI. This allows zero manual steps and all steps can either be self executing or executed by a click of a button.

What has been automated:

  • Creation of server instance
  • Installation of web server and all dependencies into the server instance
  • Virtual host configuration
  • Generating SSL certificate for active hosts
  • Deployment of an application to the server

The main technologies used for automation are as follows:

  • Gitlab CI
  • Terraform
  • Ansible

The entires stack will be managed by these 2 repositories which contains:

  • The Server Definition Codebase, contains the creation and provisioning scripts that is executed by the Gitlab CI pipelines of the repository
  • The Website Codebase is also hosted on the pipelines but has different steps and is more focused on application deployment

Creating Server Instances using Terraform

Terraform is a tool that allows you to define the infrastructure setup by code. Terraform comes built with modules that can manage a Digitalocean-based infrastructure.

Terraform was used to do these setups

  • Create the droplet with the proper region and base OS
  • Configure the domain names associated with the droplet
  • Bind an SSH key to the droplet

The problem with Terraform state management

Terraform can create and destroy server instances, it can do this since it tracks the state of the server. The deal with Terraform is that it produces a state file, and since we are using Gitlab CI as our Terraform host, all pipelines must refer to a single state file. To fix this problem, Terraform Remote State was used, and it is configured to use Digitalocean Spaces to store the state files.

Gitlab CI pipeline steps for server provisioning

Provisioning Server using Ansible

After creating the server instances, we need to provision it. This will install the tools and services needed to run a website. Ansible was the provisioner of choice.

Ansible was used to do these setups

  • Install Nginx and setup the virtual hosts
  • Install NodeJS
  • Install MySQL
  • Install Redis
  • Setup the firewall rules

Using Pipelines and Artifacts for Deployment

With the server up and running, the next step is to create a package that would be deployed to the server. The package will contain the actual site together with the asset compiled and dependencies resolved.

These steps are usually provided by the application meant to be deployed, and consists of the following steps:


Build step will create the package from scratch. It will run composer install followed by yarn install and yarn dist. The resulting package will be compressed into a tar file and uploaded to Gitlab's artifactory.


This will deploy to the environment of choice. It will establish a secure SSH session to the server using an SSH key configured in the Gitlab's environment variables settings.

Gitlab CI pipeline steps for package deployment