【问题标题】:Flaky ECS Fargate deploys (An AppSpec file is required, but could not be found)Flaky ECS Fargate 部署(需要 AppSpec 文件,但找不到)
【发布时间】:2020-03-16 17:25:58
【问题描述】:

我们有一些令人沮丧的片状 CodeDeploy 错误。在大约 10% 的部署中,我们收到以下错误:需要一个 AppSpec 文件,但在修订版中找不到。

问题在于,当我们从 s3 下载工件 zip 文件时,我们清楚地看到了一个 appspec.yaml 文件。我们的构建脚本在部署之间不会发生变化,当我们在同一个提交上重新运行管道时(使用“发布更改”按钮),无需更改任何内容,它就可以工作。

错误消息没有帮助,而且 CodeDeploy 似乎不是 100% 可靠的。

我们通过蓝/绿部署使用 ECS Fargate。

我们的buildspec.yml 文件如下所示:

version: 0.2

env:
  parameter-store:
    BUILD_ENV: key-foo-site-node-env

phases:
  pre_build:
    commands:
      - echo Logging in to Amazon ECR...
      - $(aws ecr get-login --no-include-email --region $AWS_DEFAULT_REGION)
      - IMAGE_TAG=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-6)
      - ACCOUNT_ID=$(aws sts get-caller-identity --output text --query 'Account')
      - REPOSITORY_URI="$ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/foo-site"
      - echo Saving source version into version.txt...
      - echo $IMAGE_TAG >> version.txt
  build:
    commands:
      - echo Build started on `date`
      - echo Building the app Docker image...
      - docker build -t $REPOSITORY_URI/app:$IMAGE_TAG .
      - echo Building the nginx Docker image...
      - docker build -t $REPOSITORY_URI/nginx:$IMAGE_TAG docker/nginx
  post_build:
    commands:
      - echo Build completed on `date`

      - echo Pushing the Docker images...
      - docker push $REPOSITORY_URI/app:$IMAGE_TAG
      - docker push $REPOSITORY_URI/nginx:$IMAGE_TAG

      # Create a valid json file that will be used to create a new task definition version
      # Using sed we need to replace $APP_IMAGE and $NGINX_IMAGE by image urls
      - echo Creating a task definition json
      - sed "s+\$APP_IMAGE+$REPOSITORY_URI/app:$IMAGE_TAG+g; s+\$NGINX_IMAGE+$REPOSITORY_URI/nginx:$IMAGE_TAG+g;" taskdef.$BUILD_ENV.json > register-task-definition.json

      # Using the aws cli we register a new task definition
      # We need to new task definition arn to create a valid appspec.yaml
      # If you need debugging, the next line is useful
      # - aws --debug ecs register-task-definition --cli-input-json "$(cat register-task-definition.json)" > task-definition.json
      - echo Creating an appspec.yaml file
      - TASK_DEFINITION_ARN=`aws ecs register-task-definition --cli-input-json "$(cat register-task-definition.json)" --query 'taskDefinition.taskDefinitionArn' --output text`
      - sed "s+\$TASK_DEFINITION_ARN+$TASK_DEFINITION_ARN+g" appspec.yml > appspec.yaml

artifacts:
  files:
    - appspec.yaml
    - register-task-definition.json
    - task-definition.json

我们的appspec.yml 文件如下所示:

version: 0.0
Resources:
  - TargetService:
      Type: AWS::ECS::Service
      Properties:
        TaskDefinition: "$TASK_DEFINITION_ARN"
        LoadBalancerInfo:
          ContainerName: "nginx"
          ContainerPort: "80"

【问题讨论】:

  • 你发现问题了吗?

标签: amazon-web-services amazon-ecs aws-fargate


【解决方案1】:

可能不再相关,但看起来您的 AppSpec 文件的后缀 (.yml) 与 buildspec 文件 (.yaml) 的 artifcats 定义中指示的不同。

【讨论】:

    猜你喜欢
    • 2020-03-10
    • 2022-07-28
    • 2019-08-12
    • 2020-12-28
    • 2021-01-24
    • 1970-01-01
    • 2022-01-15
    • 2019-04-10
    • 1970-01-01
    相关资源
    最近更新 更多