amazon-elastic-beanstalk - Elastic Beanstalk 找不到 server.js 文件
问题描述
我正在尝试通过GitHub Actions将我的Angular应用程序部署到 Elastic Beanstalk。我正在使用这个GitHub 操作来部署到 ELB。
我的问题是,部署失败,因为 ELB 找不到server.js
文件。我曾尝试将server.js
文件添加到deploy.zip文件中,但随后会引发不同的错误。
我明白了,它需要运行,但是当我下载使用Travis CIserver.js
推送到 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)文件。
包.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
解决方案
我终于想通了。
我们需要压缩不包括文件夹的完整根文件node_modules
夹。因此,在这种情况下,我不需要任何内容server.js
并将package.json
其包含在dist
文件夹中。
更新了 yml 片段
- name: Building application
run: npm run build
- name: Generate deployment package
run: zip -r deploy.zip * -x ./node_modules
推荐阅读
- android - append() 后 TextView 中的文本格式不正确
- polly - 调用执行前的 Polly 超时
- xcode - 小程序集 (nasm) 程序因线程 1 崩溃:EXC_BAD_ACCESS (code=2, address=0x10000101a)
- chaos - 混沌工程实验
- python - 为什么日志信息不打印到屏幕上?
- c++ - vigenere cipher 的 C++ 函数仅有时有效(适用于某些输入,跳过其他输入)
- docker - 从 docker 容器连接到主机套接字
- amazon-cloudformation - CloudFormation 在启动 EC2 实例时抛出“Value () for parameter groupId is invalid. The value cannot be empty”
- python - Python 运行时访问模块函数或动态函数创建
- r - 将数据框中的特定值相乘