Skip to content

Commit

Permalink
test deployment to dev
Browse files Browse the repository at this point in the history
Refactored deployment step, added loop

Refactored deployment conditions

Refactored deployment conditions
  • Loading branch information
yatrashkevich-scn committed May 23, 2024
1 parent b9c9702 commit 824ebae
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/run_deploy_dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ jobs:

deploy_to_ecs:
runs-on: ubuntu-latest
if: github.event.pull_request.merged
env:
TASK_FAMILY_PREFIX: backend
ECS_CLUSTER_NAME: cmiml-dev
Expand All @@ -16,9 +17,8 @@ jobs:
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:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run_deploy_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

deploy_to_ecs:
runs-on: ubuntu-latest
if: ${{ github.ref_name == v[0-9]+.[0-9]+.[0-9]+([0-9]+)+-+rc(.+) }}
if: contains(github.ref, '-rc')
env:
TASK_FAMILY: backend_api
ECS_CLUSTER_NAME: cmiml-test
Expand Down
21 changes: 9 additions & 12 deletions .github/workflows/run_deploy_uat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

deploy_to_ecs:
runs-on: ubuntu-latest
if: ${{ github.ref_name == v[0-9]+.[0-9]+.[0-9]+([0-9]+)+-+rc(.+) }}
if: contains(github.ref, '-rc')
env:
TASK_FAMILY: backend_api
ECS_CLUSTER_NAME: cmiml-uat
Expand All @@ -34,16 +34,13 @@ jobs:
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
- name: change image in the task definitions and update services
run: |
aws ecs update-service --cluster ${{ env.ECS_CLUSTER_NAME }} --service ${{ env.ECS_SERVICE_NAME }} --task-definition ${{ env.TASK_FAMILY }}
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

0 comments on commit 824ebae

Please sign in to comment.