This repository has been archived by the owner on Jun 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.sh
executable file
·34 lines (30 loc) · 1.61 KB
/
deploy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/sh
REGION=ca-central-1
ENVIRONMENT=${1:-staging}
CLUSTER_NAME=$ENVIRONMENT-renegade-dealer-cluster
SERVICE_NAME=$ENVIRONMENT-renegade-dealer-service
TASK_FAMILY=$ENVIRONMENT-renegade-dealer-task-def
ECR_URL=377928551571.dkr.ecr.ca-central-1.amazonaws.com/renegade-dealer-$ENVIRONMENT
# Fetch the latest image URI from ECR
IMAGE_URI=$(aws ecr describe-images --repository-name renegade-dealer-$ENVIRONMENT --region $REGION --query 'sort_by(imageDetails,& imagePushedAt)[-1].imageTags[0]' --output text)
FULL_IMAGE_URI="$ECR_URL:$IMAGE_URI"
echo "Using image URI: $FULL_IMAGE_URI"
# Fetch the existing definition of the task and create a new revision with the updated URI
TASK_DEFINITION=$(aws ecs describe-task-definition --task-definition $TASK_FAMILY --region $REGION --query 'taskDefinition')
NEW_TASK_DEF=$(echo $TASK_DEFINITION | \
jq --arg IMAGE_URI "$FULL_IMAGE_URI" '.containerDefinitions[0].image = $IMAGE_URI' | \
jq 'del(.taskDefinitionArn)' | \
jq 'del(.revision)' | \
jq 'del(.status)' | \
jq 'del(.requiresAttributes)' | \
jq 'del(.compatibilities)' | \
jq 'del(.registeredAt)' | \
jq 'del(.registeredBy)' | \
jq -c)
# Register the new task definition
NEW_TASK_INFO=$(aws ecs register-task-definition --cli-input-json "$NEW_TASK_DEF" --region $REGION)
NEW_REVISION=$(echo $NEW_TASK_INFO | jq -r '.taskDefinition.revision')
echo "Created new task revision: $NEW_REVISION"
# Update the ECS cluster to the new revision
aws ecs update-service --cluster $CLUSTER_NAME --service $SERVICE_NAME --task-definition $TASK_FAMILY:$NEW_REVISION --region $REGION >/dev/null 2>&1
echo "ECS cluster updated to new revision"