DevOps

Motivation

Software Engineering is a tool to keep your steps on product fast and reliable.

A Case of CI/CD for Larasite

We use Ansible(2.15.5) for configuration and deployment. The code of CI/CD leaves in the same repo with business code.

The CI/CD pipeline consist of these logics:

  1. How code changes trigger the pipeline?

    1. any of code change

  2. How to package the artifact and version it, and what’s the versioning strategy?

    1. separate devops package and the business package to two artifact with the same version number.

    2. the versioning format: $(echo $(date +'v%Y.%m.%d%H%M'))

  3. How to deploy the specify versioned artifact to the specify env?

    1. the operator would select a draft release from github releases list, and swith it to a formal release.

    2. the switch event will trigger the deployement of production with a the specify version.

  4. How to execute sql migration script or other script of laravel?

    1. sql migration will be run as a ansible task we’d written on laravel roles.

    2. if there’s other script we would like to run on the deployment, we could add it into the end of devops/roles/laravel/tasks/main.yml

  5. How to add configurations to deployment?

    1. Ansible is a configuration system also. The configuration have many levels in Ansible.

    2. What’s the minimal we have to know is that:

      1. where the service will be deployed to?

        1. go to subfolder `devops/env_vars`, you will see the different env folder like stag and prod.

        2. the hosts.yaml file in the env folder contains all host address of servers. You can change it if your server address is change. But you have to commit it to github to trigger the deployement.

      2. where the secret vars are placed?

        1. we define the secret vars on Github repo

        2. we use it as a ansible-play command line var in github actions script.

 

The structure of repo is as follows:

.github └── workflows ├── compile-to-stage.yml --> compile larasite, package it as a draft release then deploy the package to stag env by ansible. ├── loki-deployment.yml --> deploy loki server to prod env by triggered of the specify folder changes. └── prod-deployment.yml --> deploy larasite to prod env by triggerd of switching draft release to release ├── README.md ├── ...<other source code> devops ├── Vagrantfile --> for testing locally ├── common_vars --> common vars for ansible playbook │ ├── global.yaml --> off │ ├── loki-docker-compose.yaml │ └── nginx-vhosts.yaml ├── env_vars │ ├── prod --> all of prod env configuration in this folder │ ├── group_vars │ └── loki.hosts.yaml --> specific loki host │ └── stag --> all of stag env configuration in this folder ├── group_vars └── hosts.yaml --> specific larasite host ├── playbook-larasite.yml --> deploy larasite ├── playbook-loki.yml --> deploy loki a kind of log server ├── roles --> each subfolder of it is that meanings a kind of deployment for a component │ ├── ansible-role-docker │ ├── ansible-role-loki │ ├── ansible-role-nginx │ ├── ansible-role-php │ ├── ansible-role-php-versions │ ├── ansible-role-pip │ ├── ansible-role-promtail │ └── laravel --> the main logic of deployment for larasite ├── scripts --> store a few script helper │ └── install-ansible.sh └── test └── docker-compose.yaml --> for tesing locally

The relationship between servers as fllows: