Skip to content

Commit

Permalink
docs(cicd): updated documentation + deps bump (#220)
Browse files Browse the repository at this point in the history
## Introduction
CICD Documentation

## Resolution
* Updated documentation
* Updated deployment bash script
* Bumped dependencies

Co-authored-by: Abhi Markan <abhi.markan@ukexportfinance.gov.uk>
  • Loading branch information
abhi-markan and Abhi Markan authored May 31, 2023
1 parent e43bf3f commit 441c570
Show file tree
Hide file tree
Showing 5 changed files with 212 additions and 109 deletions.
104 changes: 96 additions & 8 deletions .github/workflows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,102 @@ The action has three steps: setup, base, ca, and apim. The setup step sets up in

## Deployment

### GHA
This is a YAML file for a GitHub Action that deploys an APIM system for the MDM micro-service. It defines two jobs: "setup" that sets environment variables, and "mdm" that deploys the MDM micro-service to a container app environment.
The action triggers when a push is made to the "dev" branch and runs only when files in specific directories are modified. It defines several environment variables, including "product," "environment," and "timezone."
The "mdm" job has several steps, including checking out the repository, logging in to Azure, and configuring the Azure CLI defaults. The action also sets up a container registry, builds and pushes Docker images, and updates the container app with environment variables.
It is assumed that the secrets referenced in the action definition (e.g. ACR_USERNAME and ACR_PASSWORD) are set up beforehand in the repository's secrets.

### Bash
This is a Bash script for a deployment strategy for a project. It prompts the user with a list of deployment destinations and asks for input to select the destination. The script sets the destination and the branch for the deployment based on the user's input. If the user selects ACR Purge, the script runs the az acr run command to purge the ACR repository based on specified filter and ago duration. After setting the destination and branch, the script displays the latest push commit for the selected branch, creates a new branch based on the destination, and pushes the changes to that branch. Then the script cleans up the local branches and notifies the user that the deployment has been initiated. The script version and author information are also provided at the end of the script.
### Script
#### CICD 📝

This Bash script represents a Continuous Integration and Continuous Deployment (CICD) process.

#### Color Variables

- `RED` 🟥: Represents the color code for red.
- `GREEN` 🟩: Represents the color code for green.
- `BLUE` 🔵: Represents the color code for blue.
- `YELLOW` 🟨: Represents the color code for yellow.
- `NC` ⬛: Represents the color code for no color (default).

#### User Input

The script prompts the user to select an option from the following:

- `${YELLOW}0. Infrastructure 🔧${NC}`
- `${BLUE}1. Deployment 🧪${NC}`
- `${RED}2. ACR Purge 🗑️${NC}`

#### Option Handling

Based on the user's selection, the script performs the following actions:

#### Infrastructure 🔧

- Sets the `destination` variable to "infrastructure".
- Sets the `branch` variable to "main".

#### Deployment 🧪

- Prompts the user to enter a value for the `destination` variable.
- Sets the `branch` variable to "main".

#### ACR Purge 🗑️

- Clears the values of the `destination` and `branch` variables.
- Runs an Azure CLI command to purge specific resources in an Azure Container Registry (ACR).

#### Deployment Logic

If both `destination` and `branch` variables are not empty, the script performs the following actions:

- Checks out the `branch` and pulls the latest changes.
- Displays information about the latest push commit on the `branch`.
- Creates a new branch based on the `destination` value.
- Force pushes the new branch to the remote repository and sets the upstream branch.
- Switches back to the original `branch`.
- Deletes the new branch.
- Prints a success message indicating the deployment initiation and the switch to the original `branch`.


### Workflow: Deployment 🚀

This workflow is triggered on push events to the `dev`, `staging`, and `production` branches, and specific file modifications.

#### Environment Variables

- `PRODUCT` 📦: Represents the name of the product ("apim").
- `ENVIRONMENT` 🌍: Represents the name of the environment, which is retrieved from the GitHub ref name.
- `TIMEZONE` 🕒: Specifies the timezone as "Europe/London."
- `FROM` 📁: Represents a base artifact, with the value "latest."

#### Jobs

##### 1. Setup 🔧

- This job sets up deployment variables.
- It runs on a self-hosted runner with the "APIM" and "deployment" labels.
- Outputs:
- `product`: Contains the value of the `PRODUCT` environment variable.
- `environment`: Contains the value of the `ENVIRONMENT` environment variable.
- `timezone`: Contains the value of the `TIMEZONE` environment variable.
- Steps:
- Environment 🧪: Displays the environment set to the `ENVIRONMENT` value.
- Timezone 🌐: Displays the timezone set to the `TIMEZONE` value.

##### 2. MDM 📦️

- This job represents the deployment of the MDM (Master Data Management) micro-service.
- Depends on the successful completion of the **Setup** job.
- Environment: Uses the `environment` output from the **Setup** job.
- Environment Variables:
- `NAME` 📁: Represents the name of the micro-service ("mdm").
- `ENVIRONMENT` 🌍: Represents the environment name.
- Runs on a self-hosted runner with the "APIM" and "deployment" labels.
- Steps:
1. Repository 🗃️: Checks out the repository using the `actions/checkout` action.
2. Azure 🔐: Authenticates with Azure using the `azure/login` action.
3. CLI 📝: Sets up CLI commands to retrieve various Azure resources and store them as environment variables.
4. Defaults ✨: Uses the Azure CLI to configure default settings.
5. ACR 🔐: Logs in to an Azure Container Registry (ACR) using the `azure/docker-login` action.
6. Artifacts 🗃️: Builds and pushes Docker images to the ACR.
7. Revisions 🔀: Uses the Azure CLI to update a container application with the new image and set environment variables.
8. Import ⬇️: Imports an API specification to an Azure API Management (APIM) service.

## SCA
This is a GitHub Action YAML file that sets up environment variables and performs various source code analysis (SCA) tasks on the MDM-API project when a pull request is made to the main branch. The code quality SCA is performed by Codacy and the licensing SCA is performed by Fossa.
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ if [ -n "$selection" ]; then
############### DEPLOYMENT ###############
elif [ "$selection" = "1" ]
then
destination=deployment
read destination
branch=main
############### ACR PURGE ###############
elif [ "$selection" = "2" ]
Expand Down Expand Up @@ -60,7 +60,7 @@ else
fi

#######################################
# UKEF deployment shell script v0.0.6
# 11/05/2023
# UKEF deployment shell script v0.0.7
# 31/05/2023
# Abhi Markan
#######################################
3 changes: 1 addition & 2 deletions .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# *********
# GHA is only invoked when following conditions are satisfied:
# 1. Push to the `dev`, `staging` and `production` branches only.
# 2. Any modifications inside `src` directory
# 2. Any modifications to atleast one of the `paths` targets.

name: Deployment 🚀
run-name: APIM deployment for ${{ github.repository }}
Expand All @@ -27,7 +27,6 @@ on:
- dev
- staging
- production
- APIM-207-ia-c-add-monitor

paths:
- 'src/**'
Expand Down
Loading

0 comments on commit 441c570

Please sign in to comment.