5

“无效的操作配置未在输入工件 ZIP 文件中找到图像定义文件 imagedefinitions.json。验证文件是否存储在管道的 Amazon S3 工件存储桶中”

收到此错误,我没有在 AWS 中使用 codebuild 并且图像直接推送到 ECR,我们使用 maven 构建该图像,我已将 imagedefinitions.json 上传到 artifi 存储桶,我还压缩了该文件,但没有任何效果,

任何人都可以提出任何建议吗

4

1 回答 1

16

当您使用 ECR 作为源时,ECR 会生成一个名为“imageDetail.json”的工件文件,其格式为 [1]。但是 ECS 部署阶段需要一个名为“imagedefinitions.json”的文件,其格式不同 [2]。

要提供所需的文件,请在源代码和部署之间添加一个 CodeBuild 步骤,并使用以下构建规范:(基本上是转换文件)

version: 0.2
phases:
    install:
        runtime-versions:
            docker: 18
    build:
        commands:
            - apt-get install jq -y
            - ContainerName="todo"
            - ImageURI=$(cat imageDetail.json | jq -r '.ImageURI')
            - printf '[{"name":"CONTAINER_NAME","imageUri":"IMAGE_URI"}]' > imagedefinitions.json
            - sed -i -e "s|CONTAINER_NAME|$ContainerName|g" imagedefinitions.json
            - sed -i -e "s|IMAGE_URI|$ImageURI|g" imagedefinitions.json
            - cat imagedefinitions.json

artifacts:
    files:
        - imagedefinitions.json

重要 1:更新任务定义中存在的“ContainerName”

重要2:确保部署操作的输入工件是BuildArtifact。

  1. https://docs.aws.amazon.com/codepipeline/latest/userguide/file-reference.html#file-reference-ecs-bluegreen
  2. https://docs.aws.amazon.com/codepipeline/latest/userguide/file-reference.html#pipelines-create-image-definitions
于 2020-05-22T22:42:51.497 回答