【问题标题】:AWS Elastic Beanstalk error: Failed to deploy applicationAWS Elastic Beanstalk 错误:无法部署应用程序
【发布时间】:2020-07-26 16:19:44
【问题描述】:

我花了很多时间来解决我的问题。我使用 CodePipelineCodeSourceCodeBuild 生成 docker 容器(来自 Bitbucket 的代码)并将图像存储在 ECR .

CodeDeploy 中,我想将该映像从 ECR 部署到 Elastic Beanstalk

Elastic Beanstalk 中的错误:

Environment health has transitioned from Info to Degraded. Command failed on all instances. Incorrect application version found on all instances. Expected version "Sample Application" (deployment 6). Application update failed 15 seconds ago and took 59 seconds.

During an aborted deployment, some instances may have deployed the new application version. To ensure all instances are running the same version, re-deploy the appropriate application version.

Failed to deploy application.

Unsuccessful command execution on instance id(s) 'i-04df549361597208a'. Aborting the operation.

EB 的另一个错误:

Incorrect application version "code-pipeline-1586854202535-MyflashcardsBuildOutput-ce0d6cd7-8290-40ad-a95e-9c57162b9ff1" 
(deployment 9). Expected version "Sample Application" (deployment 8).

CodeDeploy 中的错误:

Action execution failed
Deployment completed, but with errors: During an aborted deployment, some instances may have deployed the new application version. To ensure all instances are running the same version, re-deploy the appropriate application version. Failed to deploy application. Unsuccessful command execution on instance id(s) 'i-04df539061522208a'. Aborting the operation. [Instance: i-04df549333582208a] Command failed on instance. An unexpected error has occurred [ErrorCode: 0000000001].

有人知道这里发生了什么吗?

我使用 Dockerfile:

### STAGE 1: Build ###
FROM node:12.7-alpine AS build
WORKDIR /usr/src/app
COPY package.json ./
RUN npm install
COPY . .
RUN npm run build

### STAGE 2: Run ###
FROM nginx:1.17.1-alpine
EXPOSE 80
COPY --from=build /usr/src/app/dist /usr/share/nginx/html

和 buildspec.yml:

version: 0.2
phases:
  pre_build:
    commands:
      - echo Logging in to Amazon ECR...
      - aws --version
      - $(aws ecr get-login --region eu-west-1 --no-include-email)
      - REPOSITORY_URI=176901363719.dkr.ecr.eu-west-1.amazonaws.com/myflashcards
      - COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
      - IMAGE_TAG=myflashcards
  build:
    commands:
      - echo Build started on `date`
      - echo Building the Docker image
      - docker build --tag $REPOSITORY_URI:latest .
  post_build:
    commands:
      - echo Build completed on `date`
      - echo Pushing the Docker images...
      - docker push $REPOSITORY_URI:latest
      - echo Writing image definitions file...
      - printf '[{"name":"eagle","imageUri":"%s"}]' $REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json
#      - echo Deleting old artifacts
#      - aws s3 sync dist/ s3://$BUCKET_NAME --delete
artifacts:
  files: imagedefinitions.json

第三步(CodeDeploy)失败:(

【问题讨论】:

    标签: amazon-web-services amazon-elastic-beanstalk aws-code-deploy aws-codepipeline


    【解决方案1】:

    遇到了同样的问题。第一个修复对我有用。列出所有可以解决此问题的可能修复:

    1. 原因:elasticbeanstalk 的一些错误导致多阶段构建器步骤失败。 AWS 日志会向您显示一条消息,例如 docker pull 需要一个参数

    解决方案:使用未命名的构建器。默认情况下,阶段没有命名,您可以通过它们的整数来引用它们,第一个 FROM 指令从 0 开始。在您的 docker 文件中进行如下更改:

    ### STAGE 1: Build ###
    FROM node:12.7-alpine
    WORKDIR /usr/src/app
    COPY package.json ./
    RUN npm install
    COPY . .
    RUN npm run build
    
    ### STAGE 2: Run ###
    FROM nginx:1.17.1-alpine
    EXPOSE 80
    COPY --from=0 /usr/src/app/dist /usr/share/nginx/html
    
    1. 原因:Incase 使用 t2.micro 作为实例类型。 npm install 命令有时会在 t2.micro 实例上超时。

    解决方案:更改 Elastic Beanstalk 使用的实例类型不是 t2.micro(比如 t2.small)

    1. 如果以上两个修复都不起作用,请尝试更改 Dockerfile 的 COPY 行,如下所示:

      复制包*.json ./

    因为 AWS 有时更喜欢 ./ 而不是 '.'

    【讨论】:

    • #2 为我工作。即使我从 ECR 部署预构建的映像,我仍然需要升级实例类型
    猜你喜欢
    • 2020-04-25
    • 2021-06-22
    • 1970-01-01
    • 2021-03-01
    • 2019-03-07
    • 2017-03-04
    • 2015-03-05
    • 2019-02-22
    • 2021-08-28
    相关资源
    最近更新 更多