Skip to content

Commit

Permalink
PRO-610 REFACTOR use ./scripts/deploy_ecs to deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
bender2352 committed Nov 15, 2024
1 parent 35c28be commit b1441d5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
7 changes: 1 addition & 6 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,7 @@ jobs:

- name: Deploy to ECS
if: ${{ inputs.environment == 'staging' }}
uses: aws-actions/amazon-ecs-deploy-task-definition@v2
with:
service: terrateam-app-service
cluster: terrateam-app
image: ghcr.io/terrateamio/terrat-ee:{{ env.VERSION_TAG }}
wait-for-service-stability: true
run: ./scripts/deploy_ecs

- name: Deploy to Fly.io
if: ${{ inputs.environment == 'production' }}
Expand Down
35 changes: 35 additions & 0 deletions scripts/deploy_ecs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash
set -euo pipefail

CLUSTER_NAME="terrateam-app"
SERVICE_NAME="terrateam-app-service"
IMAGE_NAME="terrat-ee"
GHCR_IMAGE="ghcr.io/${GITHUB_REPOSITORY_OWNER}/${IMAGE_NAME}:${VERSION_TAG}"

# Fetch the current service information
aws ecs describe-services --cluster "$CLUSTER_NAME" --services "$SERVICE_NAME" > service.json
TASK_DEF_ARN=$(jq -r '.services[0].taskDefinition' service.json)

# Fetch the current task definition
aws ecs describe-task-definition --task-definition "$TASK_DEF_ARN" > task-def.json

# Update the app container image
jq --arg newImage "$GHCR_IMAGE" '
.taskDefinition.containerDefinitions |= map(
if .name == "app" then
.image = $newImage
else
.
end
)
' task-def.json > task-def-updated.json

# Register the new task definition
NEW_TASK_DEF=$(aws ecs register-task-definition --cli-input-json file://task-def-updated.json)
NEW_TASK_DEF_ARN=$(echo "$NEW_TASK_DEF" | jq -r '.taskDefinition.taskDefinitionArn')

# Update the service to use the new task definition
aws ecs update-service --cluster "$CLUSTER_NAME" --service "$SERVICE_NAME" --task-definition "$NEW_TASK_DEF_ARN"

# Wait for the service to stabilize
aws ecs wait services-stable --cluster "$CLUSTER_NAME" --services "$SERVICE_NAME"

0 comments on commit b1441d5

Please sign in to comment.