Sul*_*Sah 7 amazon-web-services amazon-ecs docker aws-codepipeline
我希望在存在新标签时更新我的 ECS 任务定义映像标签。
在 CodePipeline 中,当我使用新标签推送映像后,我尝试使用以下命令更新服务,但它不会自动获取新映像,仍然是旧映像。
- docker push ${DOCKERHUB_USER}/aws-dummy-api:${IMAGE_TAG}
- aws ecs update-service --cluster my-cluster --service dummy-api-service --force-new-deployment --region eu-central-1
Run Code Online (Sandbox Code Playgroud)
那么当我推送新标签时如何自动获取新的图片标签呢?
Sul*_*Sah 10
看来我需要使用新的映像标签创建新的修订版,并更新 ECS 服务。
在这个github问题之后,我在 CodePipeline buildspec.yml 中进行了这样的管理:
build:
commands:
- docker build -t $FULL_IMAGE --target prod .
- docker push $FULL_IMAGE
post_build:
commands:
- TASK_DEFINITION=$(aws ecs describe-task-definition --task-definition "$TASK_FAMILY" --region "$AWS_DEFAULT_REGION")
- NEW_TASK_DEFINITION=$(echo $TASK_DEFINITION | jq --arg IMAGE "$FULL_IMAGE" '.taskDefinition | .containerDefinitions[0].image = $IMAGE | del(.taskDefinitionArn) | del(.revision) | del(.status) | del(.requiresAttributes) | del(.compatibilities) | del(.registeredAt) | del(.registeredBy)')
- NEW_TASK_INFO=$(aws ecs register-task-definition --region "$AWS_DEFAULT_REGION" --cli-input-json "$NEW_TASK_DEFINITION")
- NEW_REVISION=$(echo $NEW_TASK_INFO | jq '.taskDefinition.revision')
- aws ecs update-service --cluster ${ECS_CLUSTER} --service ${SERVICE_NAME} --task-definition ${TASK_FAMILY}:${NEW_REVISION}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3945 次 |
最近记录: |