Builds pushed to ECR are in a register/deregister loop

ecr
aws

#1

So everything looks good. My task definition, service, and docker repository on ECR are all being updated which triggers the rolling restarts on my instances.

However, whenever it spins up a task using the image built by my CircleCI deploy script, it falls into a loop of being registered/deregistered. When I build locally and push up it works so I believe it’s the built image. The deploy script uses essentially the same commands I use on my local machine. I have the AWS Elastic Load Balancer hooked up which may be bringing it down if it’s failing the health check.

Any tips on how to debug this, or pointers on how a CircleCI build differs from a local machine build? Currently, I’m wondering if intermediate containers not being removed could be the problem?

For reference, here’s my circle.yml

  node:
    version: 6.9.2
  services:
    - docker

deployment:
  production:
    branch: master
    commands:
      - docker build -t $AWS_ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com/___/___ .
      - sh ./deploy/circle_ci_deploy.sh

circle_ci_deploy.sh


family="___"
cluster="___"
desired_count=2

configure_aws_cli() {
	aws --version
	aws configure set default.region us-east-1
	aws configure set default.output json
}

push_ecr_image(){
	 eval $(aws ecr get-login --region us-east-1)
   docker push $AWS_ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com/___/___
  #  docker push $AWS_ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com/___/___:$CIRCLE_SHA1
}

register_definition() {
    if task_revision=$(aws ecs register-task-definition --cli-input-json file://deploy/api-task-definition.json); then
        echo "Task Revision: $task_revision"
    else
        echo "Failed to register task definition"
        return 1
    fi
}

update_cluster_service() {
    register_definition
    if service=$(aws ecs update-service --cluster $cluster --service $family --task-definition $family --desired-count $desired_count); then
        echo "Service Updated: $service"
    else
        echo "Error updating service."
        return 1
    fi
}

configure_aws_cli
push_ecr_image
update_cluster_service

#2