Skip to content

Instantly share code, notes, and snippets.

@onahirniak
Last active May 21, 2020 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onahirniak/2980a7a552325a5c58d46f3a71f6168b to your computer and use it in GitHub Desktop.
Save onahirniak/2980a7a552325a5c58d46f3a71f6168b to your computer and use it in GitHub Desktop.
#Login to ECR with AWS SDK v1
#$(aws ecr get-login --no-include-email)
#Login to ECR with AWS SDK v2
aws ecr get-login-password \
| docker login \
--password-stdin \
--username AWS \
"xxx.dkr.ecr.us-west-2.amazonaws.com"
#Build, tag and push to ECR
IMAGE_NAME="name"
docker build -t ${IMAGE_NAME} .
docker tag ${IMAGE_NAME}:latest xxx.dkr.ecr.us-west-2.amazonaws.com/${IMAGE_NAME}:latest
docker push xxx.dkr.ecr.us-west-2.amazonaws.com/${IMAGE_NAME}:latest
#Deploy service
TASK_DEFINITION="dev-api"
CLUSTER_NAME="dev-cluster"
SERVICE_NAME="dev-api-service"
CONTAINER_DEFINITION=$(aws ecs describe-task-definition --task-definition $TASK_DEFINITION | jq .taskDefinition.containerDefinitions)
TASK_VERSION=$(aws ecs register-task-definition --family $TASK_DEFINITION --container-definitions "$CONTAINER_DEFINITION" --memory 512 --cpu 256 --requires-compatibilities "FARGATE" --network-mode "awsvpc" --execution-role-arn "arn:aws:iam::365814684959:role/ecsTaskExecutionRole" | jq --raw-output '.taskDefinition.revision')
DEPLOYED_SERVICE=$(aws ecs update-service --cluster $CLUSTER_NAME --service $SERVICE_NAME --task-definition $TASK_DEFINITION:$TASK_VERSION | jq --raw-output '.service.serviceName')
echo "Deployment of $DEPLOYED_SERVICE complete"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment