gpt4 book ai didi

amazon-elastic-beanstalk - Elastic Beanstalk 找不到 server.js 文件

转载 作者:行者123 更新时间:2023-12-04 08:44:28 26 4
gpt4 key购买 nike

我正在尝试部署我的 申请通过GitHub Actions到 Elastic Beanstalk 。我正在使用这个 GitHub actions用于部署到 ELB。

我的问题是,部署失败,因为 ELB 找不到 server.js文件。我试过添加 server.js文件放入 部署.zip 文件,但随后会引发不同的错误。

我明白了,需要server.js运行,但是当我下载使用 推送到 ELB 的同一应用程序的构建时特拉维斯 CI .它不会抛出这样的错误,而且 CI/CD 工作得很好。

这是 ELB 记录的错误(当 server.js 未添加到 deploy.zip 时):

throw err;
^

Error: Cannot find module '/var/app/current/server.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! climber-mentee-fe@1.0.1 aws: `node server.js && npm run serve`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the climber-mentee-fe@1.0.1 aws script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

> climber-mentee-fe@1.0.1 aws /var/app/current
> node server.js && npm run serve

我还附上了我的 package.jsonmain.yml (对于 CI)文件。

package.json :
"name": "climber-mentee-fe",
"version": "1.0.1",
"scripts": {
"ng": "ng",
"start": "node server.js",
"serve": "ng serve --configuration=dev",
"start:staging": "gulp set --env=staging && concurrently --kill-others \"node server.js\" \"npm run serve\"",
"start:prod": "gulp set --env=prod && concurrently --kill-others \"node server.js\" \"npm run serve\"",
"build": "ng build --configuration=production",
"test": "ng test",
"aws": "node server.js && npm run serve",
"lint": "ng lint",
"e2e": "ng e2e"
},
...
...
}

main.yml :
name: My application CI

on:
push:
branches:
- dry-run-actions

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x]

steps:
- uses: actions/checkout@v1

- name: Node ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- name: Installing NPM
run: npm install

- name: Building application and copying package.json to dist
run: npm run build && cp package.json dist/

- name: Generate deployment package
run: cd dist && zip -r ../deploy.zip ./*

- name: Beanstalk Deploy for App
uses: einaregilsson/beanstalk-deploy@v3
with:
aws_access_key: ${{secrets.AWS_ACCESS_KEY}}
aws_secret_key: ${{secrets.AWS_SECRET_KEY}}
application_name: my-app
environment_name: my-app-env
region: ap-south-1
version_label: 455
deployment_package: deploy.zip

var/app/current 的屏幕
enter image description here

最佳答案

我终于想通了。

我们需要压缩完整的根文件夹,不包括 node_modules文件夹。所以,在那种情况下,我不需要任何 server.jspackage.json包含在 dist 内文件夹。

更新的 yml 片段

- name: Building application
run: npm run build

- name: Generate deployment package
run: zip -r deploy.zip * -x ./node_modules

关于amazon-elastic-beanstalk - Elastic Beanstalk 找不到 server.js 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59607944/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com