-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·53 lines (40 loc) · 1.2 KB
/
deploy.sh
File metadata and controls
executable file
·53 lines (40 loc) · 1.2 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
set -euo pipefail
cat > overrides.txt <<EOF
{
"containerOverrides": [
{
"name": "service",
"command": ["goose", "-dir", "migrations", "up"]
}
]
}
EOF
TASK_ARN=$(aws ecs run-task \
--cluster "${ECS_CLUSTER_NAME}" \
--launch-type EC2 \
--overrides file://overrides.txt \
--task-definition "${ECS_SERVICE_NAME}-service" | jq -r '.tasks[0].taskArn')
echo "Running task: ${TASK_ARN}"
aws ecs wait tasks-stopped \
--cluster "${ECS_CLUSTER_NAME}" \
--tasks "${TASK_ARN}"
EXIT_CODE=$(aws ecs describe-tasks \
--cluster "${ECS_CLUSTER_NAME}" \
--tasks "${TASK_ARN}" | jq -r '.tasks[0].containers[0].exitCode')
if [ "$EXIT_CODE" -ne 0 ]; then
echo "Task failed with exit code: $EXIT_CODE"
exit 1
fi
echo "Task completed successfully with exit code: $EXIT_CODE"
rm -f overrides.txt exit_code.txt
echo "Updating ECS service to use the latest task definition..."
aws ecs update-service \
--force-new-deployment \
--cluster "${ECS_CLUSTER_NAME}" \
--service "${ECS_SERVICE_NAME}" | jq
echo "Waiting for ECS service to stabilize..."
aws ecs wait services-stable \
--cluster "${ECS_CLUSTER_NAME}" \
--services "${ECS_SERVICE_NAME}"
echo "ECS service is stable."