英文:
Elastic Beanstalk cannot find the server.js file
问题
我正在尝试通过GitHub Actions将我的Angular应用程序部署到Elastic Beanstalk。我正在使用这个GitHub Actions来进行ELB部署。
我的问题是,部署失败了,因为ELB找不到server.js
文件。我尝试将server.js
文件添加到deploy.zip文件中,但然后它会抛出不同的错误。
我明白了,它需要server.js
来运行,但是当我下载使用Travis CI推送到ELB的同一应用程序的构建时,它不会抛出这样的错误,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.json
和main.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的截图:
英文:
I'm trying to deploy my Angular application through GitHub Actions to Elastic Beanstalk. I'm using this GitHub actions for the deploying to ELB.
My problem is, the deployment is failing as the ELB cannot find the server.js
file. I have tried adding server.js
file into the deploy.zip file, but then it throws a different error.
I get it, it needs server.js
to run, but when I download the build for the same application which is pushed to ELB using Travis CI. It doesn't throw such error and CI/CD is working just fine.
Here is the error logged by ELB (when server.js
is not added to 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
I'm also attaching my package.json
and main.yml
(for CI) files.
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
答案1
得分: 1
我终于弄清楚了。
我们需要将完整的根文件夹压缩,但不包括 node_modules
文件夹。所以,在这种情况下,我不需要在 dist
文件夹中包含任何 server.js
和 package.json
。
更新的 yml 片段
-
name: 构建应用程序
run: npm run build -
name: 生成部署包
run: zip -r deploy.zip * -x ./node_modules
英文:
I figured it out finally.
We need to zip the complete root folder excluding the node_modules
folder. So, in that case, I won't need any server.js
and package.json
included inside the dist
folder.
Updated yml snippet
- name: Building application
run: npm run build
- name: Generate deployment package
run: zip -r deploy.zip * -x ./node_modules
答案2
得分: 0
我通过添加一个名为.ebextensions
的目录,其中包含一个名为python.config
的单个文件来解决了这个问题。该文件的内容如下:
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: server:app
这个文件告诉Elastic Beanstalk,FastAPI应用程序位于server.py
文件中,名称为app
。
英文:
I solved this problem by adding an .ebextensions
directory containing a single file named python.config
. The contents of that file are:
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: server:app
This file tells Elastic Beanstalk that the FastAPI application is located in the server.py
file and is named app
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论