将单个Codebuild项目部署到多个ECS容器

问题描述 投票:4回答:1

我成功地使用codebuild和codepipeline为几个项目持续部署到ECS上,但却遇到了问题。在这个项目中,我需要将相同的构建部署到四个不同的ECS容器。

我使用codebuild和codepipeline CD的默认方式如aws docs所示 - 我在构建过程结束时创建了imagedefinitions.json文件。据我所知,这个文件只能包含一个ECS容器的定义。

您必须提供容器的名称:

post_build:
commands:
  - echo Build completed on `date`
  - echo Pushing the Docker images...
  - docker push $REPOSITORY_URI:latest
  - docker push $REPOSITORY_URI:$IMAGE_TAG
  - echo Writing image definitions file...
  - printf '[{"name":"hello-world","imageUri":"%s"}]' $REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json
artifacts:
files: imagedefinitions.json

对于此任务定义:

{
"taskDefinition": {
"family": "hello-world",
"containerDefinitions": [
  {
    "name": "hello-world",
    "image": "012345678910.dkr.ecr.us-west-2.amazonaws.com/hello-world:6a57b99",
    "cpu": 100,
    "portMappings": [
      {
        "protocol": "tcp",
        "containerPort": 80,
        "hostPort": 80
      }
    ],
    "memory": 128,
    "essential": true
  }
]

如果我将不同服务中的所有四个容器的名称更改为相同的名称,它可以工作。例如,特定的图像名称。但我不知道这是不是一个好主意。

现在我想知道我是否可以在这个项目中使用codepipeline到ECS,或者我应该以不同的方式部署。

amazon-web-services amazon-ecs aws-codepipeline aws-codebuild
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.