ECS Service - Automating deploy with new Docker image

后端 未结 3 2148
耶瑟儿~
耶瑟儿~ 2021-02-05 06:18

I want to automate the deployment of my application by having my ECS service launch with the latest Docker image. From what I\'ve read, the way to deploy a new image version is

3条回答
  •  醉酒成梦
    2021-02-05 07:02

    #!/bin/bash
    SERVICE_NAME="your service name"
    IMAGE_VERSION="v_"${BUILD_NUMBER}
    TASK_FAMILY="your task defination name"
    CLUSTER="your cluster name"
    REGION="your region"
    
    
    echo "=====================Create a new task definition for this build==========================="
    sed -e "s;%BUILD_NUMBER%;${BUILD_NUMBER};g" taskdef.json > ${TASK_FAMILY}-${IMAGE_VERSION}.json
    
    echo "=================Resgistring the task defination==========================================="
    aws ecs register-task-definition  --family ${TASK_FAMILY} --cli-input-json  file://${TASK_FAMILY}-${IMAGE_VERSION}.json --region ${REGION}
    
    echo "================Update the service with the new task definition and desired count================"
    TASK_REVISION=`aws ecs describe-task-definition --task-definition  ${TASK_FAMILY}  --region ${REGION} | egrep "revision" | tr "/" " " | awk '{print $2}' | sed 's/"$//'`
    
    
    DESIRED_COUNT=`aws ecs describe-services --cluster ${CLUSTER} --services ${SERVICE_NAME}  --region ${REGION} | jq .services[].desiredCount`
    if [ ${DESIRED_COUNT} = "0" ]; then
        DESIRED_COUNT="1"
    fi
    
    echo "===============Updating the service=============================================================="
    aws ecs update-service --cluster ${CLUSTER} --service ${SERVICE_NAME} --task-definition ${TASK_FAMILY}:${TASK_REVISION} --desired-count ${DESIRED_COUNT} --region ${REGION}
    
    
        enter code here
    

提交回复
热议问题