Skip to content

Commit

Permalink
fix run-task wait-for-success and update README for new run-task rela…
Browse files Browse the repository at this point in the history
…ted flags
  • Loading branch information
fillup committed Aug 21, 2020
1 parent fa8a94c commit 8b4d5f6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 24 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ Usage
--force-new-deployment Force a new deployment of the service. Default is false.
--skip-deployments-check Skip deployments check for services that take too long to drain old tasks
--run-task Run created task now. If you set this, service-name are not needed.
--wait-for-success Wait for task execution to complete and to receive the exitCode 0.
--launch-type The launch type on which to run your task. (https://docs.aws.amazon.com/cli/latest/reference/ecs/run-task.html)
--network-configuration The network configuration for the task. This parameter is required for task definitions that use
the awsvpc network mode to receive their own elastic network interface, and it is not supported
for other network modes. (https://docs.aws.amazon.com/cli/latest/reference/ecs/run-task.html)
-v | --verbose Verbose output
--version Display the version

Expand Down
49 changes: 25 additions & 24 deletions ecs-deploy
Original file line number Diff line number Diff line change
Expand Up @@ -531,41 +531,42 @@ function runTask {
TASK_ARN=$(eval $AWS_ECS_RUN_TASK | jq -r '.tasks[0].taskArn')
echo "Executed task: $TASK_ARN"

RUN_TASK_SUCCESS=false

if [ $RUN_TASK_WAIT_FOR_SUCCESS == true ]; then
RUN_TASK_SUCCESS=false
every=10
i=0
while [ $i -lt $TIMEOUT ]
do
i=0
while [ $i -lt $TIMEOUT ]
do

TASK_JSON=$($AWS_ECS describe-tasks --cluster "$CLUSTER" --tasks "$TASK_ARN")
TASK_JSON=$($AWS_ECS describe-tasks --cluster "$CLUSTER" --tasks "$TASK_ARN")

TASK_STATUS=$(echo $TASK_JSON | jq -r '.tasks[0].lastStatus')
TASK_EXIT_CODE=$(echo $TASK_JSON | jq -r '.tasks[0].containers[0].exitCode')
TASK_STATUS=$(echo $TASK_JSON | jq -r '.tasks[0].lastStatus')
TASK_EXIT_CODE=$(echo $TASK_JSON | jq -r '.tasks[0].containers[0].exitCode')

if [ $TASK_STATUS == "STOPPED" ]; then
echo "Task finished with status: $TASK_STATUS"
if [ $TASK_EXIT_CODE != 0 ]; then
echo "Task execution failed with exit code: $TASK_EXIT_CODE"
exit 1
fi
RUN_TASK_SUCCESS=true
break;
if [ $TASK_STATUS == "STOPPED" ]; then
echo "Task finished with status: $TASK_STATUS"
if [ $TASK_EXIT_CODE != 0 ]; then
echo "Task execution failed with exit code: $TASK_EXIT_CODE"
exit 1
fi
RUN_TASK_SUCCESS=true
break;
fi

echo "Checking task status every $every seconds. Status: $TASK_STATUS"
echo "Checking task status every $every seconds. Status: $TASK_STATUS"

sleep $every
i=$(( $i + $every ))
done
fi
sleep $every
i=$(( $i + $every ))
done

if [ $RUN_TASK_SUCCESS == false ]; then
echo "ERROR: New task run took longer than $TIMEOUT seconds"
exit 1
if [ $RUN_TASK_SUCCESS == false ]; then
echo "ERROR: New task run took longer than $TIMEOUT seconds"
exit 1
fi
fi



echo "Task $TASK_ARN executed successfully!"
exit 0

Expand Down

0 comments on commit 8b4d5f6

Please sign in to comment.