我正在尝试创建一个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'
也许我可以只在流水线中构建位桶,然后推送到Heroku,但是我需要编写每个步骤,所以我更喜欢使用cli,因为这是我的第一个CI集成。
答案 0 :(得分:1)
根据最佳做法(https://devcenter.heroku.com/articles/node-best-practices#avoid-garbage),您可以将节点容器限制在Procfile中:
az account get-access-token --query tenant --output tsv
答案 1 :(得分:0)
我也遇到了同样的异常,@ 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);
此后,我将ng server
中的node server.js
替换为package.json
"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