Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert output from list-tasks to quoted and space separated list #54

Merged
merged 1 commit into from
May 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions deploy-ecs/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,17 @@ while [ "${deployment_finished}" = "false" ]; do
# extract deployment id
new_deployment_id="$(echo "${new_deployment}" | jq -r '.id')"
# find any tasks that may have stopped unexpectedly
stopped_tasks="$(aws ecs list-tasks --cluster "${ECS_CLUSTER}" --started-by "${new_deployment_id}" --desired-status "STOPPED" | jq -r '.taskArns')"
stopped_task_count="$(echo "${stopped_tasks}" | jq -r 'length')"
# this should provide a list of arns (if any) that are quoted and space separated
# i.e. "arn:aws:ecs:us-west-2:123456789012:task/a1b2c3d4-5678-90ab-cdef-11111EXAMPLE" "arn:aws:ecs:us-west-2:123456789012:task/a1b2c3d4-5678-90ab-cdef-22222EXAMPLE"
stopped_tasks="$(aws ecs list-tasks --cluster "${ECS_CLUSTER}" --started-by "${new_deployment_id}" --desired-status "STOPPED" | jq -r '.taskArns[] | "\"\(. )\""' | tr '\n' ' ')"

# count number of quotes and divide by two
stopped_task_count=$(echo "$stopped_tasks" | grep -o '\"' | wc -l)
stopped_task_count=$((stopped_task_count / 2))

if [ "${stopped_task_count}" -gt "0" ]; then
# if there are stopped tasks, print the reason they stopped and then exit
stopped_task_list="$(echo "${stopped_tasks}" | jq -r 'join(",")')"
stopped_reasons="$(aws ecs describe-tasks --cluster "${ECS_CLUSTER}" --tasks "${stopped_task_list}" | jq -r '.tasks[].stoppedReason')"
stopped_reasons="$(aws ecs describe-tasks --cluster "${ECS_CLUSTER}" --tasks "${stopped_tasks}" | jq -r '.tasks[].stoppedReason')"
echo "The deployment failed because one or more containers stopped running. The reasons given were:"
echo "${stopped_reasons}"
exit 1
Expand Down