简体   繁体   English

nodejs (NestJs) AWS Elastic Beanstalk 问题(使用 aws 管道)

[英]nodejs (NestJs) AWS Elastic Beanstalk Issue (with aws pipeline)

I have red docs many times and I still have problem with deploy my project on Elastic Beanstalk.我有很多次红色文档,但在 Elastic Beanstalk 上部署我的项目仍然存在问题。

I have created ready build solution which works without problems on my local computer.我已经创建了现成的构建解决方案,可以在我的本地计算机上正常工作。

The structure looks like this:结构如下所示:

在此处输入图像描述

also I have created pipeline as AWS service:我还创建了管道作为 AWS 服务:

在此处输入图像描述

According to the documentation, I created buildspec.yaml file: (it just creates dist folder, puts files into it, install node_modules takes together and makes zip file)根据文档,我创建了 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

It creates artifact as zip and puts into E3 bucket when I download it the structure is the same as in my local computer:它创建工件为 zip 并在我下载它时放入 E3 存储桶,其结构与我本地计算机中的结构相同:

在此处输入图像描述

According to docs I have included Procfile which is used during deploy action:根据文档,我已经包含了在部署操作期间使用的 Procfile:

web: node app.js

The problem occurs during deployment.该问题在部署期间发生。 I receive error from Elastic Beanstalk:我收到来自 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 

In my opinion deploy pipeline part does not recive artifacts because it does not see package.json, Procfile and also app.js main file.在我看来,部署管道部分不会接收工件,因为它没有看到 package.json、Procfile 以及 app.js 主文件。

In addtion I would like to show you that i have established artifacts connection between deploy and build section:此外,我想向您展示我已经在部署和构建部分之间建立了工件连接: 在此处输入图像描述

When I upload file manually - it works.. What am I doing wrong?当我手动上传文件时 - 它有效..我做错了什么? Thnaks in advice!谢谢你的建议!

I had a similar issue and decided to change my approach to not use the zip method.我有一个类似的问题,并决定改变我的方法,不使用 zip 方法。 Here's my build config file.这是我的构建配置文件。

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

And in my Procfile, I added this line:在我的 Procfile 中,我添加了这一行:

web: npm run start:prod

And it worked like a charm.它就像一个魅力。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM