Github Actions - Environments, Git Tags & Deployments

Summary

Today, we will be attempting to create Environments, Git Tags & Releases, & build Docker images based on environments

Environments

We will be creating several environments today.

  • DEV
  • UAT
  • PROD
Screenshot 2024-05-18 at 7 15 14 AM

In order to create the above environments, go to Settings > Environments > New Environment. Input the New Environment e.g. DEV > Configure Environment.

Screenshot 2024-05-18 at 7 16 37 AM

Ideally, we should enable "Required Reviewers" & "Prevent Self-Review", which requires engineers to get approval from other team members who will need to approve the pipeline before the application is deployed to that particular environment. This is exceptionally important in PROD environment.

Screenshot 2024-05-18 at 7 19 20 AM

You can also set Environment Secrets and Variables, which will override Repository Secrets and Variables, which will be specific to that particular environment.

Another key feature would be to enable Deployment Branches & Tags for particular branches. A standard would be for example:

  • DEV --> Any branches can be deployed to DEV env
  • UAT --> Only release/** branches can be deployed to UAT env
  • PROD --> Only release/** & hotfix/** branches can be deployed to PROD env

A sample in DEV:

Screenshot 2024-05-18 at 7 22 34 AM

A sample in UAT:

Screenshot 2024-05-18 at 7 23 05 AM

A sample in PROD:

Screenshot 2024-05-18 at 7 23 30 AM

Creating Git Tags & Releases

Tags will be used when we are preparing for UAT and PROD environments for Docker images. In DEV environments, we can stick to "latest" tag, but in UAT and PROD, we can incrementally increase the version with each releases e.g. v1.0.1 --> v1.0.2 --> v1.1.1 --> v.1.1.2 etc.

Screenshot 2024-05-18 at 7 24 46 AM

In order to view tags, in the main page, click the "tags" button next to "branches" button.

Screenshot 2024-05-18 at 7 27 36 AM

Here, you will see all the tags available. To create tags, go to "Releases" tab and click "Draft a new release"

Screenshot 2024-05-18 at 7 28 34 AM

You can input a version tag from the tag dropdown and click "Create new tag". Ensure that you choose the right branch as the target.

Screenshot 2024-05-18 at 7 28 58 AM Screenshot 2024-05-18 at 7 30 02 AM

Once done, click "Publish Release"

Deployments

We will next create 2 yaml files - 1 for CI and 1 for CD, with the CI file making workflow calls to the CD file to allow automatic deployments to the target environment based on your branch.