AWS ECS蓝色/绿色CodePipeline:尝试读取图像工件时发生异常 [英] AWS ECS Blue/Green CodePipeline: Exception while trying to read the image artifact
问题描述
我想创建一个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和taskdefBuildArtifact中的描述,以最终部署新的蓝色/绿色容器.
问题在于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
Any hint highly appreciated :D
推荐答案
在这里回答我自己的问题,希望它可以帮助遇到相同情况的其他人.
answering my own question here, hopefully it helps others who facing the same situation.
- imagedefinitions.json文件不适用于部署操作"Amazon ECS蓝色/绿色".为此,您必须在构建步骤中创建文件 imageDetail.json ,并将其作为工件提供给部署步骤.如何 ?这是我的buildspec.yaml底部的样子:
- 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
- 在CodePipeline的部署阶段,将DefinitionArtifact和ImageArtifact用作输入工件,并在相应的部分" Amazon ECS任务定义"和" AWS CodeDeploy AppSpec文件"中进行配置.".
- 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>,
...
- 通过选择输入工件"ImageArtifact"和占位符
在"动态更新任务定义图像-可选"部分的蓝色/绿色部署阶段的代码管道配置中使用该占位符>< IMAGE1_NAME>
- 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蓝色/绿色CodePipeline:尝试读取图像工件时发生异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!