Skip to content

Commit

Permalink
added workflows for test and uat deployemnts, refactored dev deployment
Browse files Browse the repository at this point in the history
refactored workflows

Refactored deployment step, added loop

Refactored deployment step, added loop

Refactored deployment step, added loop

Refactored deployment step, added loop

Refactored deployment step, added loop

Refactored deployment step, added loop

divided to different workflows
  • Loading branch information
yatrashkevich-scn committed May 23, 2024
1 parent ab8b7dd commit b9c9702
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
name: run_build_deploy
name: run_build
on: [push, pull_request]

env:
AWS_REGION : "us-east-1"
ECR_REPO: 917902836630.dkr.ecr.us-east-1.amazonaws.com/api-server

permissions:
id-token: write
contents: read
Expand All @@ -23,6 +19,8 @@ jobs:
ECR_ADDRESS: 917902836630.dkr.ecr.us-east-1.amazonaws.com
TEST_COMMAND: sleep 1
OUT_DIR: ./out
AWS_REGION : "us-east-1"
ECR_REPO: 917902836630.dkr.ecr.us-east-1.amazonaws.com/api-server

steps:
- name: Git clone the repository
Expand Down Expand Up @@ -53,35 +51,4 @@ jobs:
env-vars-for-codebuild: |
GITHUB_ORGANIZATION, GITHUB_REPO_NAME, GITHUB_BRANCH_OR_TAG, GITHUB_REF, BUILD_NAME, BUILD_NUMBER, ECR_ADDRESS, TEST_COMMAND, ECR_REPO, OUT_DIR, DOCKER_USER, DOCKER_PASSWORD, REPORT_SERVER_PUBLIC_KEY
deploy_to_ecs:
needs: run_codebuild_project
runs-on: ubuntu-latest
env:
TASK_FAMILY: backend_api
ECS_CLUSTER_NAME: cmiml-dev
ECS_SERVICE_NAME: backend
IMAGE_PREFIX: ${{ github.ref_name }}
COMMIT_HASH: ${{ github.sha }}
if: ${{ github.event_name == 'pull_request' && github.event.action == 'closed' }}
steps:

- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v3
with:
role-to-assume: arn:aws:iam::017925157769:role/cmiml-dev-oidc-github-role
role-session-name: OIDC-GHA-session
aws-region: ${{ env.AWS_REGION }}

- name: change image in the task definition
run: |
TASK_DEFINITION=$(aws ecs describe-task-definition --task-definition ${{ env.TASK_FAMILY }} --region ${{ env.AWS_REGION }})
COMMIT_HASH_SHORT=$(echo $COMMIT_HASH | cut -c1-5)
NEW_IMAGE=${IMAGE_PREFIX/\//-}-$COMMIT_HASH_SHORT
NEW_TASK_DEFINTIION=$(echo $TASK_DEFINITION | jq --arg IMAGE "$ECR_REPO:$NEW_IMAGE" '.taskDefinition | .containerDefinitions[0].image = $IMAGE | del(.taskDefinitionArn) | del(.revision) | del(.status) | del(.requiresAttributes) | del(.compatibilities) | del(.registeredAt) | del(.registeredBy)')
aws ecs register-task-definition --region ${{ env.AWS_REGION }} --cli-input-json "$NEW_TASK_DEFINTIION"
- name: update ECS service
run: |
aws ecs update-service --cluster ${{ env.ECS_CLUSTER_NAME }} --service ${{ env.ECS_SERVICE_NAME }} --task-definition ${{ env.TASK_FAMILY }}
38 changes: 38 additions & 0 deletions .github/workflows/run_deploy_dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: deploy_to_dev
on:
workflow_run:
workflows: ["run_build"]
types:
- completed
jobs:

deploy_to_ecs:
runs-on: ubuntu-latest
env:
TASK_FAMILY_PREFIX: backend
ECS_CLUSTER_NAME: cmiml-dev
ECS_SERVICE_NAME: backend
ECR_REPO: 917902836630.dkr.ecr.us-east-1.amazonaws.com
IMAGE_PREFIX: ${{ github.ref_name }}
COMMIT_HASH: ${{ github.sha }}
AWS_REGION : "us-east-1"
if: ${{ github.event_name == 'pull_request' && github.event.action == 'closed' }}
steps:

- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v3
with:
role-to-assume: arn:aws:iam::017925157769:role/cmiml-dev-oidc-github-role
role-session-name: OIDC-GHA-session
aws-region: ${{ env.AWS_REGION }}

- name: change image in the task definitions and update services
run: |
NEW_IMAGE=${IMAGE_PREFIX/\//-}-$(echo $COMMIT_HASH | cut -c1-5)
for app in api worker scheduler; do
NEW_TASK_DEFINITION=$(aws ecs describe-task-definition --task-definition ${TASK_FAMILY_PREFIX}_${app} --region ${AWS_REGION} | jq --arg IMAGE "$ECR_REPO:$NEW_IMAGE" '.taskDefinition | .containerDefinitions[0].image = $IMAGE | del(.taskDefinitionArn) | del(.revision) | del(.status) | del(.requiresAttributes) | del(.compatibilities) | del(.registeredAt) | del(.registeredBy)')
aws ecs register-task-definition --region ${{ env.AWS_REGION }} --cli-input-json "$NEW_TASK_DEFINTIION"
aws ecs update-service --cluster ${{ env.ECS_CLUSTER_NAME }} --service ${{ env.ECS_SERVICE_NAME }}_${app} --task-definition ${TASK_FAMILY_PREFIX}_${app}
done
46 changes: 46 additions & 0 deletions .github/workflows/run_deploy_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: deploy_to_test
on:
workflow_run:
workflows: ["run_build"]
types:
- completed

permissions:
id-token: write
contents: read

jobs:

deploy_to_ecs:
runs-on: ubuntu-latest
if: ${{ github.ref_name == v[0-9]+.[0-9]+.[0-9]+([0-9]+)+-+rc(.+) }}
env:
TASK_FAMILY: backend_api
ECS_CLUSTER_NAME: cmiml-test
ECS_SERVICE_NAME: backend
AWS_REGION : "us-east-1"
ECR_REPO: 917902836630.dkr.ecr.us-east-1.amazonaws.com/api-server
IMAGE_PREFIX: ${{ github.ref_name }}
COMMIT_HASH: ${{ github.sha }}
steps:

- name: Git clone the repository
uses: actions/checkout@v4

- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v3
with:
role-to-assume: arn:aws:iam::641513112151:role/cmiml-devops-oidc-github-role
role-session-name: OIDC-GHA-session
aws-region: ${{ env.AWS_REGION }}

- name: change image in the task definitions and update services
run: |
NEW_IMAGE=${IMAGE_PREFIX/\//-}-$(echo $COMMIT_HASH | cut -c1-5)
for app in api worker scheduler; do
NEW_TASK_DEFINITION=$(aws ecs describe-task-definition --task-definition ${TASK_FAMILY_PREFIX}_${app} --region ${AWS_REGION} | jq --arg IMAGE "$ECR_REPO:$NEW_IMAGE" '.taskDefinition | .containerDefinitions[0].image = $IMAGE | del(.taskDefinitionArn) | del(.revision) | del(.status) | del(.requiresAttributes) | del(.compatibilities) | del(.registeredAt) | del(.registeredBy)')
aws ecs register-task-definition --region ${{ env.AWS_REGION }} --cli-input-json "$NEW_TASK_DEFINTIION"
aws ecs update-service --cluster ${{ env.ECS_CLUSTER_NAME }} --service ${{ env.ECS_SERVICE_NAME }}_${app} --task-definition ${TASK_FAMILY_PREFIX}_${app}
done
49 changes: 49 additions & 0 deletions .github/workflows/run_deploy_uat.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: deploy_to_uat
on:
workflow_run:
workflows: ["run_build"]
types:
- completed

permissions:
id-token: write
contents: read

jobs:

deploy_to_ecs:
runs-on: ubuntu-latest
if: ${{ github.ref_name == v[0-9]+.[0-9]+.[0-9]+([0-9]+)+-+rc(.+) }}
env:
TASK_FAMILY: backend_api
ECS_CLUSTER_NAME: cmiml-uat
ECS_SERVICE_NAME: backend
ECR_URL: 917902836630.dkr.ecr.us-east-1.amazonaws.com
IMAGE_PREFIX: ${{ github.ref_name }}
COMMIT_HASH: ${{ github.sha }}
AWS_REGION : "us-east-1"
ECR_REPO: 917902836630.dkr.ecr.us-east-1.amazonaws.com/api-server
steps:

- name: Git clone the repository
uses: actions/checkout@v4

- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v3
with:
role-to-assume: arn:aws:iam::641513112151:role/cmiml-devops-oidc-github-role
role-session-name: OIDC-GHA-session
aws-region: ${{ env.AWS_REGION }}

- name: change image in the task definition
run: |
TASK_DEFINITION=$(aws ecs describe-task-definition --task-definition ${{ env.TASK_FAMILY }} --region ${{ env.AWS_REGION }})
COMMIT_HASH_SHORT=$(echo $COMMIT_HASH | cut -c1-5)
NEW_IMAGE=${IMAGE_PREFIX/\//-}-$COMMIT_HASH_SHORT
echo $NEW_IMAGE
NEW_TASK_DEFINTIION=$(echo $TASK_DEFINITION | jq --arg IMAGE "$ECR_REPO:$NEW_IMAGE" '.taskDefinition | .containerDefinitions[0].image = $IMAGE | del(.taskDefinitionArn) | del(.revision) | del(.status) | del(.requiresAttributes) | del(.compatibilities) | del(.registeredAt) | del(.registeredBy)')
aws ecs register-task-definition --region ${{ env.AWS_REGION }} --cli-input-json "$NEW_TASK_DEFINTIION"
- name: update ECS service
run: |
aws ecs update-service --cluster ${{ env.ECS_CLUSTER_NAME }} --service ${{ env.ECS_SERVICE_NAME }} --task-definition ${{ env.TASK_FAMILY }}

0 comments on commit b9c9702

Please sign in to comment.