AWS ECS Blue/Green CodePipeline:尝试读取图像工件时出现异常 [英] AWS ECS Blue/Green CodePipeline: Exception while trying to read the image artifact

查看:34
本文介绍了AWS ECS Blue/Green CodePipeline:尝试读取图像工件时出现异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个 CodePipeline,它从 CodeCommit 源构建一个容器映像,然后以蓝/绿方式将新映像部署到我的 ECS 服务(EC2 启动类型).

I wanted to create a CodePipeline which builds a container image from CodeCommit source and afterwards deploys the new image in Blue/Green fashion to my ECS service (EC2 launchtype).

  • 源阶段是 CodeCommit,它已经包含 appspec.json
    以及 taskdef.json
  • 构建阶段正在构建新的容器&成功推送到 ECR,文件imagedefinition.json 是这一步创建的 BuildArtifact,包含容器和最近创建的图像及其与 CodeCommit 提交 ID 对应的标记.
  • 部署阶段由操作Amazon ECS(蓝/绿)"使用SourceArtifact 和 BuildArtifact 作为 InputArtifacts,取来自 SourceArtifact 和图像的 appspec 和 taskdef来自 BuildArtifact 的描述,最终部署新的蓝/绿方式的容器.

问题在于 BuildArtifact 的图像定义.管道在部署阶段失败并出现错误:

The problem is with the image definition from the BuildArtifact. The pipeline fails in the Deploy phase with error:

""无效的动作配置尝试从工件读取图像工件文件时出现异常:BuildArtifact.""

"" Invalid action configuration Exception while trying to read the image artifact file from the artifact: BuildArtifact. ""

如何正确配置Amazon ECS(蓝/绿)"部署阶段,以便它可以使用最近创建的镜像并部署它....通过替换 taskdef.json 中的占位符 IMAGE_NAME ?

How to properly configure the "Amazon ECS (Blue/Green)" deploy phase, so that it can use the recently created image and deploy it....by replacing placeholder IMAGE_NAME inside taskdef.json ?

高度赞赏任何提示:D

推荐答案

在这里回答我自己的问题,希望对面临同样情况的其他人有所帮助.

answering my own question here, hopefully it helps others who facing the same situation.

  1. 文件 imagedefinitions.json 不适合部署操作Amazon ECS Blue/Green".为此,您必须在构建步骤中创建文件 imageDetail.json,并将其作为工件提供给部署步骤.如何 ?这是我的 buildspec.yaml 底部的样子:
  1. the file imagedefinitions.json is inappropriate for deploy action "Amazon ECS Blue/Green". For that you have to create file imageDetail.json within the build step and provide it as artifact to the deploy step. How ? This is how the bottom of my buildspec.yaml looks like:

      - printf '{"ImageURI":"%s"}' $REPOSITORY_URI:$IMAGE_TAG > imageDetail.json
artifacts:
  files: 
    - 'image*.json'
    - 'appspec.yaml'
    - 'taskdef.json'
  secondary-artifacts:
    DefinitionArtifact:
      files:
        - appspec.yaml
        - taskdef.json
    ImageArtifact:
      files:
        - imageDetail.json

  1. 在 CodePipeline 的 Deploy 阶段,使用 DefinitionArtifact 和 ImageArtifact 作为 Input Artifacts 并在Amazon ECS 任务定义"和AWS CodeDeploy AppSpec 文件"对应部分进行配置".
  1. In the Deploy phase of CodePipeline, use DefinitionArtifact and ImageArtifact as Input Artifacts and configure them in the corresponding section "Amazon ECS task definition" and "AWS CodeDeploy AppSpec file".

确保您的 appspec.yaml 包含任务定义的占位符.这是我的 appspec.yaml:

Ensure that your appspec.yaml contains placeholder for the task definition. Here is my appspec.yaml:

version: 0.0

Resources:
  - TargetService:
      Type: AWS::ECS::Service
      Properties:
        TaskDefinition: <TASK_DEFINITION>
        LoadBalancerInfo:
          ContainerName: "my-test-container"
          ContainerPort: 8000

还要确保您的 taskdef.json 包含最终图像的占位符,例如

Also ensure that your taskdef.json contains placeholder for the final image, like

...
"image": <IMAGE1_NAME>,
...

  1. 动态更新任务定义图像 - 可选"部分的蓝/绿部署阶段的代码管道配置中使用该占位符,方法是选择输入工件作为ImageArtifact"和占位符
  1. use that placeholder in the codepipeline config of your blue/green deploy phase in the section "Dynamically update task definition image - optional" by choosing the input artifact as "ImageArtifact" and the placeholder <IMAGE1_NAME>

这篇关于AWS ECS Blue/Green CodePipeline:尝试读取图像工件时出现异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆