Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions .github/actions/deploy-ecs/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: "Deploy to ECS"
description: "Deploy new image to given ECS service by updating task definition file"
inputs:
aws-role:
required: true
description: "AWS ROLE"
aws-region:
required: true
description: "AWS REGION"
task-definition:
required: true
description: "TASK DEFINITION"
container-name:
required: true
description: "CONTAINER NAME"
ecs-service:
required: true
description: "ECS SERVICE"
ecs-cluster:
required: true
description: "ECS CLUSTER"
image:
required: true
description: "APP IMAGE"
runs:
using: "composite"
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ inputs.aws-role }}
aws-region: ${{ inputs.aws-region }}

- name: Download task definition
run: |
aws ecs describe-task-definition --task-definition ${{ inputs.task-definition }} \
--query taskDefinition > task-definition.json
shell: bash

- name: Fill in the new image ID in the Amazon ECS task definition
id: task_def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: task-definition.json
container-name: ${{ inputs.container-name }}
image: ${{ inputs.image }}

- name: Remove unwanted fields from task definition
id: task_def_cleanup
shell: bash
run: |
jq 'del(.taskDefinitionArn, .revision, .status, .requiresAttributes, .compatibilities, .registeredAt, .registeredBy)' ${{ steps.task_def.outputs.task-definition }} > updated-task-definition.json

- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: updated-task-definition.json
service: ${{ inputs.ecs-service }}
cluster: ${{ inputs.ecs-cluster }}
wait-for-service-stability: true
34 changes: 34 additions & 0 deletions .github/workflows/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Conductor CI/CD Workflow

This repository contains workflow files for implementing Continuous Integration (CI) and Continuous Deployment (CD) processes separately for Conductor UI and server components. The workflow is designed to deploy to both development (dev) and production (prd) environments on AWS (ECS).

## Workflow Overview

The CI/CD workflow is triggered manually & comprises two main components:

1. **Conductor UI CI/CD:**
- Workflow file: `.github/workflows/ci-ui.yaml`
`.github/workflows/cd-ui.yaml`
- These workflows handle the CI & CD process for Conductor UI.

2. **Conductor Server CI/CD:**
- Workflow file: `.github/workflows/ci-server.yaml`
`.github/workflows/cd-server.yaml`
- These workflows handle the CI & CD process for Conductor server.

## Deployment Strategy

- **Branches:**
- The `production` branch is considered the master branch for all deployments.
- All deployments to both development and production environments are triggered from the `production` branch.

- **Input Variables:**
- The workflow takes the following input variables:
1. **Branch:** Specifies the branch to be deployed (e.g., `production`).
2. **Environment:** Specifies the deployment environment (e.g., `dev` or `prd`).
3. **Tag:** Specifies the version to be deployed. This version is used for tagging the Docker image.

## Versioning and Docker Image Tagging

The version provided as an input variable is crucial for versioning and tagging Docker images. The workflow utilizes this version to tag the Docker image before deploying to the AWS Elastic Container Registry (ECR). During ECS deployment, this tagged image is fetched from ECR.

156 changes: 156 additions & 0 deletions .github/workflows/cd-server.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
name: Deploy Conductor Server

on:
workflow_dispatch:
inputs:
Environment:
required: true
type: choice
description: Choose aws env
options:
- dev
- stg
- prd
Tag:
required: true
type: string
description: Provide tag (Eg:v3.14.0)

env:
SERVICE_NAME: conductor-server
AWS_REGION: "ap-south-1"


jobs:
prepare-env:
name: Prepare Env
runs-on: 'ubuntu-latest'
timeout-minutes: 2
outputs:
AWS_ROLE: ${{ steps.vars.outputs.AWS_ROLE }}
ENV: ${{ steps.vars.outputs.ENV }}
PROJECT_PREFIX: ${{ steps.vars.outputs.PROJECT_PREFIX }}
ECS_CLUSTER: ${{ steps.set_env.outputs.ECS_CLUSTER }}
ECS_SERVICE: ${{ steps.set_env.outputs.ECS_SERVICE }}
TASK_DEFINITION: ${{ steps.set_env.outputs.TASK_DEFINITION }}
CONTAINER_NAME: ${{ steps.set_env.outputs.CONTAINER_NAME }}
ECR_REPOSITORY: ${{ steps.set_env.outputs.ECR_REPOSITORY }}
SLACK_WEBHOOK_URL: ${{ steps.vars.outputs.SLACK_WEBHOOK_URL }}

steps:
- id: vars
shell: bash
run: |
BRANCH="${GITHUB_REF#refs/heads/}"
ENV=${{ github.event.inputs.environment }}
IMAGE_TAG=${{ github.event.inputs.tag }}
echo $BRANCH

if [ -z "$ENV" ]
then
case $BRANCH in
"dev")
ENV="dev"
;;
"stg")
ENV="stg"
;;
"main")
ENV="prd"
;;
*)
echo "ENV not configured" && exit 1
;;
esac
fi
if [[ $ENV == 'prd' && $BRANCH == 'production' ]]
then
echo "AWS_ROLE=PRD_AWS_ROLE" >> $GITHUB_OUTPUT
echo "PROJECT_PREFIX=sirn-prd-mb" >> $GITHUB_OUTPUT
echo "SLACK_WEBHOOK_URL=PRD_SLACK_WEBHOOK_URL" >> $GITHUB_OUTPUT
elif [ $ENV == 'stg' ]
then
echo "AWS_ROLE=STG_AWS_ROLE" >> $GITHUB_OUTPUT
echo "PROJECT_PREFIX=sirn-stg-mb" >> $GITHUB_OUTPUT
echo "SLACK_WEBHOOK_URL=DEV_SLACK_WEBHOOK_URL" >> $GITHUB_OUTPUT
elif [ $ENV == 'dev' ]
then
echo "AWS_ROLE=DEV_AWS_ROLE" >> $GITHUB_OUTPUT
echo "PROJECT_PREFIX=sirn-dev-mb" >> $GITHUB_OUTPUT
echo "SLACK_WEBHOOK_URL=DEV_SLACK_WEBHOOK_URL" >> $GITHUB_OUTPUT
else
echo "Branch not configured!"
exit 1
fi
echo "ENV=$ENV" >> $GITHUB_OUTPUT
echo ":rocket: Environment - $ENV " >> $GITHUB_STEP_SUMMARY
echo ":label: Image Tag - $IMAGE_TAG " >> $GITHUB_STEP_SUMMARY
- name: set variables
id: set_env
run: |
PROJECT_PREFIX=${{ steps.vars.outputs.PROJECT_PREFIX }}
echo "ECR_REPOSITORY=$PROJECT_PREFIX-ecr-$SERVICE_NAME" >> $GITHUB_OUTPUT
echo "ECS_CLUSTER=$PROJECT_PREFIX-ecs-cluster" >> $GITHUB_OUTPUT
echo "ECS_SERVICE=$PROJECT_PREFIX-svc-$SERVICE_NAME" >> $GITHUB_OUTPUT
echo "TASK_DEFINITION=$PROJECT_PREFIX-td-$SERVICE_NAME" >> $GITHUB_OUTPUT
echo "CONTAINER_NAME=$PROJECT_PREFIX-cntr-$SERVICE_NAME" >> $GITHUB_OUTPUT
echo ":seedling: Branch:${GITHUB_REF#refs/heads/}" >> $GITHUB_STEP_SUMMARY

# Deploy Conductor UI Image to ECS
deploy-ui-image:
name: Deploy UI Image
runs-on: 'ubuntu-latest'
timeout-minutes: 20
permissions:
id-token: write
pull-requests: write
contents: read
needs: prepare-env
env:
AWS_ROLE: ${{ needs.prepare-env.outputs.AWS_ROLE }}
ENV: ${{ needs.prepare-env.outputs.ENV }}
PROJECT_PREFIX: ${{needs.prepare-env.outputs.PROJECT_PREFIX}}
ECR_REPOSITORY: ${{needs.prepare-env.outputs.ECR_REPOSITORY}}
IMAGE_TAG: ${{ github.event.inputs.tag }}
ECS_CLUSTER: ${{ needs.prepare-env.outputs.ECS_CLUSTER }}
ECS_SERVICE: ${{ needs.prepare-env.outputs.ECS_SERVICE }}
TASK_DEFINITION: ${{ needs.prepare-env.outputs.TASK_DEFINITION }}
CONTAINER_NAME: ${{ needs.prepare-env.outputs.CONTAINER_NAME }}

steps:
- name: Checkout code from action
uses: actions/checkout@v2

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets[env.AWS_ROLE] }}
aws-region: ${{ env.AWS_REGION }}

- name: Amazon ECR Login
id: login-ecr
uses: aws-actions/[email protected]

- name: Check if image tag exists in ECR
id: check-image-existence
run: |
if aws ecr describe-images --repository-name "${{ env.ECR_REPOSITORY }}" --region "${{ env.AWS_REGION }}" --image-ids imageTag="${{ env.IMAGE_TAG }}" 2>&1 | grep -q "imageTag"; then
echo "Image tag $IMAGE_TAG exists in ECR"
else
echo "Error: Image tag $IMAGE_TAG does not exist in ECR"
exit 1
fi

- name: Deploy backend
id: deploy_backend
uses: ./.github/actions/deploy-ecs
env:
APP_IMAGE: ${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
with:
aws-region : ${{ env.AWS_REGION }}
aws-role: ${{ secrets[env.AWS_ROLE] }}
task-definition: ${{ env.TASK_DEFINITION }}
container-name: ${{ env.CONTAINER_NAME }}
ecs-service: ${{ env.ECS_SERVICE }}
ecs-cluster: ${{ env.ECS_CLUSTER }}
image: ${{ env.APP_IMAGE }}
Loading