angular bitbucket heroku 部署后超出内存配额
Memory quota exceeded after angular bitbucket heroku deployment
我正在尝试制作一个 Bitbucket 管道,它将应用程序部署到 Heroku。
它部署了,但在 Heroku 上我得到
2019-04-01T19:47:11.305401+00:00 app[web.1]: [34mℹ[39m [90m「wdm」[39m: Compiled successfully.
2019-04-01T19:47:18.311170+00:00 heroku[web.1]: Process running mem=571M(111.6%)
2019-04-01T19:47:18.311170+00:00 heroku[web.1]: Error R14 (Memory quota exceeded)
2019-04-01T19:47:40.049088+00:00 heroku[web.1]: Process running mem=558M(109.0%)
2019-04-01T19:47:40.049160+00:00 heroku[web.1]: Error R14 (Memory quota exceeded)
2019-04-01T19:47:51.213698+00:00 heroku[web.1]: State changed from starting to crashed
2019-04-01T19:47:51.071576+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
这是我的package.json。该应用程序基本上是一个全新的 angular-cli 生成的项目。我对 package.json 进行了一些更改,因此它可以在 Heroku 上运行。
{
"name": "quiz-web",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"heroku-postbuild": "ng build --prod"
},
"private": true,
"dependencies": {
"@angular/animations": "^7.2.11",
"@angular/cdk": "^7.3.6",
"@angular/common": "~7.2.0",
"@angular/compiler": "~7.2.0",
"@angular/core": "~7.2.0",
"@angular/forms": "~7.2.0",
"@angular/material": "^7.3.6",
"@angular/platform-browser": "~7.2.0",
"@angular/platform-browser-dynamic": "~7.2.0",
"@angular/router": "~7.2.0",
"@angular/cli": "~7.3.6",
"@angular-devkit/build-angular": "~0.13.0",
"@angular/compiler-cli": "~7.2.0",
"core-js": "^2.5.4",
"rxjs": "~6.3.3",
"tslib": "^1.9.0",
"zone.js": "~0.8.26"
},
"devDependencies": {
"@angular/language-service": "~7.2.0",
"@types/node": "~8.9.4",
"@types/jasmine": "~2.8.8",
"@types/jasminewd2": "~2.0.3",
"codelyzer": "~4.5.0",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~4.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.11.0",
"typescript": "~3.2.2"
},
"engines": {
"node": "10.15.0",
"npm": "6.4.1"
}
}
这是我的管道文件
image: node:10.15.0
clone:
depth: full
pipelines:
default:
- step:
script:
# create a zip file from the heroku app sources
- git archive --format=tar.gz master -o sample-app.tar.gz
- pipe: atlassian/heroku-deploy:0.1.1
variables:
HEROKU_API_KEY: $HEROKU_API_KEY
HEROKU_APP_NAME: $HEROKU_APP_NAME
# here you specify the name of the zip file containing your
# heroku application sources
ZIP_FILE: 'sample-app.tar.gz'
也许我可以在管道中的 bitbucket 上构建,然后推送到 Heroku,但我需要编写每个步骤,所以我更愿意使用 cli,因为这是我的第一个 CI 集成。
根据最佳实践 (https://devcenter.heroku.com/articles/node-best-practices#avoid-garbage),您可以在 Procfile 中限制节点容器:
web: node --optimize_for_size --max_old_space_size=460 --gc_interval=100 server.js
我也遇到了同样的异常,@IamSoClueless 建议使用选项
NODE_OPTIONS=--optimize_for_size --gc_interval=100 --max_old_space_size=128
这个我们可以在https://dashboard.heroku.com/apps/app-named/settings->Config Vars
中设置
但不幸的是我得到了
remote: -----> Creating runtime environment
remote:
remote: NPM_CONFIG_LOGLEVEL=error
remote: **NODE_OPTIONS=--gc_interval=100 --max_old_space_size=128**
remote: NODE_ENV=production
remote: NODE_MODULES_CACHE=true
remote: NODE_VERBOSE=false
remote:
remote: -----> Installing binaries
remote: engines.node (package.json): unspecified
remote: engines.npm (package.json): unspecified (use default)
remote:
remote: Resolving node version 12.x...
remote: Downloading and installing node 12.17.0...
remote: **node: --gc_interval= is not allowed in NODE_OPTIONS**
remote:
remote: -----> Build failed
我没有列出来,但是将--optimize_for_size
添加到NODE_OPTIONS
时错误相同
然后,我尝试在本地生成构建并使用在本地运行的 express 为它们提供服务。
const express = require('express');
const path = require('path');
const app = express();
// Serve only the static files form the dist directory
app.use(express.static('dist/app-name'));
app.get('/*', function (req, res) {
res.sendFile(path.join(__dirname, 'dist/app-name/index.html'));
});
// Start the app by listening on the default Heroku port
app.listen(process.env.PORT || 4200);
之后我在package.json
中将ng server
替换为node server.js
"scripts": {
"ng": "ng",
"start": "node server.js",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"postinstall": "ng build --aot --prod"
},
应用程序按预期工作,所以我推送了此更改。
由于这是我的原型应用程序,我不能以成本从 heroku 借用额外的资源。因此,每次我在部署之前执行此步骤并在本地开发应用程序时返回 ng serve
我正在尝试制作一个 Bitbucket 管道,它将应用程序部署到 Heroku。
它部署了,但在 Heroku 上我得到
2019-04-01T19:47:11.305401+00:00 app[web.1]: [34mℹ[39m [90m「wdm」[39m: Compiled successfully.
2019-04-01T19:47:18.311170+00:00 heroku[web.1]: Process running mem=571M(111.6%)
2019-04-01T19:47:18.311170+00:00 heroku[web.1]: Error R14 (Memory quota exceeded)
2019-04-01T19:47:40.049088+00:00 heroku[web.1]: Process running mem=558M(109.0%)
2019-04-01T19:47:40.049160+00:00 heroku[web.1]: Error R14 (Memory quota exceeded)
2019-04-01T19:47:51.213698+00:00 heroku[web.1]: State changed from starting to crashed
2019-04-01T19:47:51.071576+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
这是我的package.json。该应用程序基本上是一个全新的 angular-cli 生成的项目。我对 package.json 进行了一些更改,因此它可以在 Heroku 上运行。
{
"name": "quiz-web",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"heroku-postbuild": "ng build --prod"
},
"private": true,
"dependencies": {
"@angular/animations": "^7.2.11",
"@angular/cdk": "^7.3.6",
"@angular/common": "~7.2.0",
"@angular/compiler": "~7.2.0",
"@angular/core": "~7.2.0",
"@angular/forms": "~7.2.0",
"@angular/material": "^7.3.6",
"@angular/platform-browser": "~7.2.0",
"@angular/platform-browser-dynamic": "~7.2.0",
"@angular/router": "~7.2.0",
"@angular/cli": "~7.3.6",
"@angular-devkit/build-angular": "~0.13.0",
"@angular/compiler-cli": "~7.2.0",
"core-js": "^2.5.4",
"rxjs": "~6.3.3",
"tslib": "^1.9.0",
"zone.js": "~0.8.26"
},
"devDependencies": {
"@angular/language-service": "~7.2.0",
"@types/node": "~8.9.4",
"@types/jasmine": "~2.8.8",
"@types/jasminewd2": "~2.0.3",
"codelyzer": "~4.5.0",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~4.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.11.0",
"typescript": "~3.2.2"
},
"engines": {
"node": "10.15.0",
"npm": "6.4.1"
}
}
这是我的管道文件
image: node:10.15.0
clone:
depth: full
pipelines:
default:
- step:
script:
# create a zip file from the heroku app sources
- git archive --format=tar.gz master -o sample-app.tar.gz
- pipe: atlassian/heroku-deploy:0.1.1
variables:
HEROKU_API_KEY: $HEROKU_API_KEY
HEROKU_APP_NAME: $HEROKU_APP_NAME
# here you specify the name of the zip file containing your
# heroku application sources
ZIP_FILE: 'sample-app.tar.gz'
也许我可以在管道中的 bitbucket 上构建,然后推送到 Heroku,但我需要编写每个步骤,所以我更愿意使用 cli,因为这是我的第一个 CI 集成。
根据最佳实践 (https://devcenter.heroku.com/articles/node-best-practices#avoid-garbage),您可以在 Procfile 中限制节点容器:
web: node --optimize_for_size --max_old_space_size=460 --gc_interval=100 server.js
我也遇到了同样的异常,@IamSoClueless 建议使用选项
NODE_OPTIONS=--optimize_for_size --gc_interval=100 --max_old_space_size=128
这个我们可以在https://dashboard.heroku.com/apps/app-named/settings->Config Vars
但不幸的是我得到了
remote: -----> Creating runtime environment
remote:
remote: NPM_CONFIG_LOGLEVEL=error
remote: **NODE_OPTIONS=--gc_interval=100 --max_old_space_size=128**
remote: NODE_ENV=production
remote: NODE_MODULES_CACHE=true
remote: NODE_VERBOSE=false
remote:
remote: -----> Installing binaries
remote: engines.node (package.json): unspecified
remote: engines.npm (package.json): unspecified (use default)
remote:
remote: Resolving node version 12.x...
remote: Downloading and installing node 12.17.0...
remote: **node: --gc_interval= is not allowed in NODE_OPTIONS**
remote:
remote: -----> Build failed
我没有列出来,但是将--optimize_for_size
添加到NODE_OPTIONS
然后,我尝试在本地生成构建并使用在本地运行的 express 为它们提供服务。
const express = require('express');
const path = require('path');
const app = express();
// Serve only the static files form the dist directory
app.use(express.static('dist/app-name'));
app.get('/*', function (req, res) {
res.sendFile(path.join(__dirname, 'dist/app-name/index.html'));
});
// Start the app by listening on the default Heroku port
app.listen(process.env.PORT || 4200);
之后我在package.json
ng server
替换为node server.js
"scripts": {
"ng": "ng",
"start": "node server.js",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"postinstall": "ng build --aot --prod"
},
应用程序按预期工作,所以我推送了此更改。
由于这是我的原型应用程序,我不能以成本从 heroku 借用额外的资源。因此,每次我在部署之前执行此步骤并在本地开发应用程序时返回 ng serve