Memory quota exceeded after angular bitbucket heroku deployment

被刻印的时光 ゝ 提交于 2020-06-01 06:44:05

问题


I am trying to make a Bitbucket pipeline which will deploy the app to the Heroku.

It deploys but on Heroku I am getting

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

This is my package.json. The app is basically a fresh angular-cli generated project. I made some changes to package.json so it would work on 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"
  }
}

And this is my pipeline file

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'

Maybe I could just build on the bitbucket in pipeline and then push to Heroku but I would need to do write each steps so I would prefer to use the cli as it's my first CI integration.


回答1:


According to the Best Practices (https://devcenter.heroku.com/articles/node-best-practices#avoid-garbage) you can limit your node container in your Procfile:

web: node --optimize_for_size --max_old_space_size=460 --gc_interval=100 server.js



回答2:


I was also getting the same Exception, @IamSoClueless has suggested to use options

NODE_OPTIONS=--optimize_for_size --gc_interval=100 --max_old_space_size=128

This we can setup in https://dashboard.heroku.com/apps/app-named/settings->Config Vars

But unfortunately i was getting

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

I have not listed, but the error was same when added --optimize_for_size to NODE_OPTIONS

Then, I tried generating build locally and serving them using express which worked locally.

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);

After that i replaced ng server to node server.js in 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"
  },

Application worked as expected so i pushed this changes. Since this is my prototype application, I cannot borrow extra resources at cost from heroku. Hence everytime I follow this step before deployment and reverse to ng serve while developing app locally



来源:https://stackoverflow.com/questions/55462886/memory-quota-exceeded-after-angular-bitbucket-heroku-deployment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!