Nodejs slow at "Preparing build for deployment" - node.js

I create a new nodejs app and publish on openshift.
Everything are fast and good.
Then I start to add all Mean dependencies (not dev-dependencies)
and then the push build becomes very slow
remote: Saving away previously installed Node modules remote: Building
git ref 'master', commit 79fb313 remote: Building NodeJS cartridge
remote: Preparing build for deployment
The terminal blocks there for 5 minutes.
I just wonder why it's so slow.
I can ssh to the gear and copy and stop/start my app in less than 30secondes.
There is no log at all nodejs.log !
What is the cardtridge is doing and it takes so much time?
Regards,
Ball

Related

How to overcome build time limit for Haskell projects on Heroku?

I'm trying to deploy Haskell application to Heroku using the following buildpack:
https://github.com/mfine/heroku-buildpack-stack
The build is going well until it hits the build time limit with the following error:
-----> Timed out running buildpack Haskell
! Push failed
Is there any way to increase this limit or to speed up the build?
Just split dependencies in half and make a push with only part of the dependencies enabled. Then make a push with all of them enabled. The latter build will use cached dependencies from the former build. If the project is super heavy on dependencies it would probably require more than two steps though.
I faced a similar issue with my angular project in a VPS with 1GB ram. I solved it by building the project in my local environment first and then uploading build files to the server.

Azure nodejs dist directory "Error: EBUSY" or files silently not overriden

We have a nodejs - express, angular app. The express app and Angular app are built separately, and the Angular is added into a static/ directory under the express app. In this formation, both are moved into a dist directory to be run using node. It is deployed to Azure and runs under a Windows server (not my choice).
If the deploy script deletes the dist/ directory it fails with
...
remote: > bottal#1.0.0 clear:dist D:\home\site\wwwroot
remote: > rimraf dist
remote:
remote: D:\home\site\wwwroot\node_modules\rimraf\bin.js:47
remote: throw er
remote: ^
remote:
remote: Error: EBUSY: resource busy or locked, rmdir 'D:\home\site\wwwroot\dist'
If the dist directory is not deleted then the deploy silently fails by not overwriting the files.
Is there a best way to write such apps?
This was fixed in 2 ways.
Delete the directory in the Azure deploy.sh (specified in .deployment file)
Instead change to using zip deploys instead of git local (whoops, I didn't say that above).
Both solve the problem, however what made the zip deploy the solution was because the npm install (download and install of dependencies) seemed almost instant compared to when being performed in a git local deploy. We were in a bit of a hurry to keep moving forward (after wasting so much time on what should not have been a problem) that I didn't put any investigation time in to this. It would be interesting to know if it is true, however.d

Speed up deployment on Heroku [duplicate]

This question already has answers here:
Avoid npm refresh after every deployment on Heroku
(4 answers)
Closed 8 years ago.
Heroku is great. But every time I deploy, Heroku seems to like to redownload and rebuild all the packages. With socket.io and mailparser this is taking around 3 minutes.
Is there a way to speed up the deployment process? Is there a way to tell Heroku that it can cache these items? Or can I upload prebuilt node_modules?
It seems like as of today Heroku is finally caching the node_modules folder!
-----> Deleting 6 files matching .slugignore patterns.
-----> Node.js app detected
-----> Requested node range: 0.10.x
-----> Resolved node version: 0.10.22
-----> Downloading and installing node
-----> Restoring node_modules from cache
-----> Installing dependencies
-----> Pruning unused dependencies
-----> Caching node_modules directory for future builds
-----> Cleaning up node-gyp and npm artifacts
Build time is like 3 seconds for me now.
One thing I did to speed up process was to add .slugignore file to the main folder and add all the files and folders I did not want to run the app.
Sample content of .slugignore file:
working
mockups
*.psd
*.pdf
I'm running into the same problem.
Some discussion here about caching the node_modules folder: https://github.com/heroku/heroku-buildpack-nodejs/pull/37
Another idea: https://github.com/heroku/heroku-buildpack-nodejs/issues/25
I'm thinking about a few solutions right now.
Check in node_modules in a separate branch: The core Node.js maintainers actually recommend checking in the node_modules folder into source control (for apps, not libs). I don't like this. A way to get around it though might be to have a separate production branch with a different .gitignore file that doesn't ignore node_modules. When you want to deploy, just do a rebase from your master and node_modules will be checked in. At least this keeps your master branch free from dependencies.
Add a preinstall script to package.json to download compressed dependency zip: You could also add a pre-push git hook to bundle up your dependencies and upload them to S3. This would probably be too slow though.
Modify the heroku-buildpack-nodejs: Integrate the outstanding pull request with node_modules caching:
heroku config:set BUILDPACK_URL=https://github.com/opdemand/buildpack-nodejs.git
I had the same question (see Avoid npm refresh after every deployment on Heroku).
Heroku forces a download/build/etc. sequence because they need to start an app with a 'blank slate': to clean previous undeleted files, when they move your app to another server, when you assign new web dynos, etc.
The issue is clearly with native packages, and recompilation. For all js-only packages, I commit them with my project, and remove them from package.json. It gains a few seconds, but not that much.
I should definitely be possible to pre-compile and commit native modules (I successfully run wkhtml2pdf on Heroku, for instance, with a binary compiled for linux-amd64), if you get access to a Linux box (or VM) with the same configuration - as of today, Linux [...] 2.6.32-350-ec2 #57-Ubuntu SMP [...] x86_64 GNU/Linux.
Though I would not recommend it as a definitive solution, since it is likely to break some day - It does not seem to me that heroku guarantees the platform an app runs onto.
Seems like there has recently been progress at the heroku-buildpack-nodejs.
Once the pull request is merged, you can add
heroku config:set BUILDPACK_URL=https://github.com/heroku/heroku-buildpack-nodejs
to your heroku environment variables.
For now, David Dollar's forked repository is available at
https://github.com/ddollar/heroku-buildpack-nodejs
With this as your BUILDPACK_URL it should cache the npm modules.
I tried it with node.js 0.10.5a, npm version: 1.3.5 and npm_modules in .gitignore. Tt seems to work fine so far!
Check out this branch of the new Heroku Node.js buildpack, now in beta, which supports node_modules caching between builds:
https://github.com/heroku/heroku-buildpack-nodejs/tree/diet
To use it:
heroku config:set BUILDPACK_URL=https://github.com/heroku/heroku-buildpack-nodejs#diet -a my-node-app
git commit -am "fakeout" --allow-empty
git push heroku

Forcing Heroku to Treat App as Node.js

I have a Node.js app which I'm attempting to deploy to Heroku. However, Heroku seems to think that it's a Ruby app, likely because it has a Gemfile (we have a private gem containing some custom scripts and the like, as well as the Heroku gem itself for command-line control). I added Gemfile and Gemfile.lock to the .slugignore (discussed in Heroku's Slug Compiler article), but the app is still detected as a Ruby app.
$ git push heroku master
Total 0 (delta 0), reused 0 (delta 0)
-----> Heroku receiving push
-----> Ruby app detected
-----> Installing dependencies using Bundler version 1.2.0.pre
Running: bundle install --without development:test --path vendor/bundle --binstubs bin/ --deployment
The bundle fails, because our custom gem is a private repo, and I never get any further. I'm unable to find any way to force Heroku to treat the app as a Node.js app and use the Procfile to start the web app. Does anyone have and idea how I can do this?
Well crap, I must not have looked far enough. This was already asked on Stack Overflow and the answer was to use the custom Node.js build pack, a la:
heroku config:add BUILDPACK_URL=https://github.com/heroku/heroku-buildpack-nodejs.git

Changing app from one language to another in heroku

Is it possible to switch a Heroku app on the Cedar stack from one language to another?
In this particular instance I am trying to migrate an app from PHP to NodeJS, which is being detected as a NodeJS app after performing a git push:
-----> Heroku receiving push
-----> Node.js app detected
-----> Fetching Node.js binaries
-----> Vendoring node 0.4.7
-----> Installing dependencies with npm 1.0.94
Dependencies installed
-----> Discovering process types
Procfile declares types -> web
-----> Compiled slug size is 5.0MB
-----> Launching... done, v7
... however it then crashes with:
Error: No such file or directory - node main.js
Trying to run the Node REPL also suggests the binary doesn't exist:
> heroku run node
Running node attached to terminal... up, run.1
sh: node: not found
Is there any way to reinitialise a Cedar stack app, without creating a new instance?
Create a new instance application instance. It is probably not a good idea to try to morph one into the other. DNS will update for you automatically as that's handled by the routing mesh, and you'll be much happier and better off for it.
I (although a slightly different use case) migrated an application from Bamboo to Cedar and the whole process took me less than five minutes. The only downtime was a couple of seconds while I relocated the custom domain setup on the application.
I know it's an old question but I ran into this problem changing my app from PHP to NodeJs. The first time I run the git push heroku master I got an error saying that it couldn't use PHP buildpack.
So I went in my app Settings tab in Heroku dashboard and remove the PHP buildpack from the Buildpacks list.
Finally whe I ran git push heroku master, Heroku auto detected the NodeJS buildpack.

Resources