【问题标题】:nodejs (NestJs) AWS Elastic Beanstalk Issue (with aws pipeline)nodejs (NestJs) AWS Elastic Beanstalk 问题(使用 aws 管道)
【发布时间】:2020-11-24 21:12:27
【问题描述】:

我多次收到红色文档,但在 Elastic Beanstalk 上部署我的项目时仍然遇到问题。

我已经创建了现成的构建解决方案,可以在我的本地计算机上正常运行。

结构如下:

我还创建了管道作为 AWS 服务:

根据文档,我创建了 buildspec.yaml 文件: (它只是创建 dist 文件夹,将文件放入其中,安装 node_modules 并制作 zip 文件)

version: 0.2
phases:
  install:
    runtime-versions:
      nodejs: 12
    commands:
      - yum install -y zip
      - echo "Instal dependencies"
      - npm install
  build:
    commands:
      - npm run build
      - cd dist
      - zip -r application.zip ./* ../package.json ../package-lock.json ../.env ../node_modules ../Procfile
      - cd ..
      - mv ./dist/application.zip ./
artifacts:
  files:
    - application.zip

它以 zip 格式创建工件并在我下载它时放入 E3 存储桶,其结构与我本地计算机中的相同:

根据文档,我已包含在部署操作期间使用的 Procfile:

web: node app.js

问题发生在部署期间。我收到来自 Elastic Beanstalk 的错误:

2020/08/04 16:58:49.766428 [INFO] Executing instruction: StageApplication
2020/08/04 16:58:49.917998 [INFO] extracting /opt/elasticbeanstalk/deployment/app_source_bundle to /var/app/staging/
2020/08/04 16:58:49.918039 [INFO] Running command /bin/sh -c /usr/bin/unzip -q -o /opt/elasticbeanstalk/deployment/app_source_bundle -d /var/app/staging/
2020/08/04 16:58:50.544212 [INFO] finished extracting /opt/elasticbeanstalk/deployment/app_source_bundle to /var/app/staging/ successfully
2020/08/04 16:58:50.544764 [INFO] Executing instruction: RunPreBuildHooks
2020/08/04 16:58:50.544792 [INFO] The dir .platform/hooks/prebuild/ does not exist in the application. Skipping this step...
2020/08/04 16:58:50.544797 [INFO] Executing instruction: Install customer specified node.js version
2020/08/04 16:58:50.544802 [INFO] installing specified nodejs version...
2020/08/04 16:58:50.544809 [INFO] there is no package.json file, skip installing specified version of nodejs
2020/08/04 16:58:50.544814 [INFO] Executing instruction: Use NPM to install dependencies
2020/08/04 16:58:50.544822 [INFO] there is no package.json file, skip installing dependencies
2020/08/04 16:58:50.544827 [INFO] Executing instruction: check Procfile
2020/08/04 16:58:50.544831 [INFO] checking Procfile
2020/08/04 16:58:50.544837 [INFO] no Procfile found, generating Procfile
2020/08/04 16:58:50.544841 [INFO] checking package.json file
2020/08/04 16:58:50.544847 [INFO] checking app.js file from source
2020/08/04 16:58:50.544853 [INFO] checking server.js file from source
2020/08/04 16:58:50.544867 [ERROR] An error occurred during execution of command [app-deploy] - [check Procfile]. Stop running the command. Error: node.js may have issues starting. Please provide a package.json file or add server.js/app.js file in source bundle 

在我看来,部署管道部分不会接收工件,因为它没有看到 package.json、Procfile 和 app.js 主文件。

此外,我想向您展示我已经在部署和构建部分之间建立了工件连接:

当我手动上传文件时 - 它可以工作.. 我究竟做错了什么?非常感谢您的建议!

【问题讨论】:

  • “当我手动上传文件时” - 你的意思是当你上传 CB 制作的 zip 工件时,它一切都按预期工作吗?部署阶段的Details 还说什么?

标签: node.js amazon-web-services amazon-elastic-beanstalk pipeline nestjs


【解决方案1】:

我遇到了类似的问题,并决定改变我的方法,不使用 zip 方法。这是我的构建配置文件。

version: 0.2

#env:
  #variables:
     # key: "value"
     # key: "value"
  #parameter-store:
     # key: "value"
     # key: "value"
  #secrets-manager:
     # key: secret-id:json-key:version-stage:version-id
     # key: secret-id:json-key:version-stage:version-id
  #exported-variables:
     # - variable
     # - variable
  #git-credential-helper: yes
#batch:
  #fast-fail: true
  #build-list:
  #build-matrix:
  #build-graph:
phases:
  install:
    #If you use the Ubuntu standard image 2.0 or later, you must specify runtime-versions.
    #If you specify runtime-versions and use an image other than Ubuntu standard image 2.0, the build fails.
    runtime-versions:
      nodejs: 14
      # name: version
    commands:
      - echo "Instal dependencies"
      - npm install
  #pre_build:
    #commands:
      # - command
      # - command
  build:
    commands:
      - npm run build
  #post_build:
    #commands:
      # - command
      # - command
#reports:
  #report-name-or-arn:
    #files:
      # - location
      # - location
    #base-directory: location
    #discard-paths: yes
    #file-format: JunitXml | CucumberJson
artifacts:
  files:
    - '**/*'
    # - location
  #name: $(date +%Y-%m-%d)
  #discard-paths: yes
  #base-directory: location
#cache:
  #paths:
    # - paths

在我的 Procfile 中,我添加了这一行:

web: npm run start:prod

它就像一个魅力。

【讨论】:

    猜你喜欢
    • 2017-12-30
    • 2019-08-11
    • 2014-10-19
    • 2019-05-11
    • 2015-01-14
    • 2014-12-30
    • 2020-04-11
    • 2019-11-22
    • 1970-01-01
    相关资源
    最近更新 更多