Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run Procfile with multiple commands on Heroku?

I'm trying to deploy the static website to Heroku and I struggle how to correctly setup the Procfile.

I have next command to run on the server:

  • npm install
  • gulp build (will make a build with /public folder)
  • http-server (will serve /public by default)

What I've tried:

  • web: npm install; gulp build; http-server
  • web: npm install & gulp build & http-server
like image 410
ummahusla Avatar asked Jun 24 '17 07:06

ummahusla


People also ask

Is Procfile necessary Heroku?

Deploying to HerokuA Procfile is not technically required to deploy simple apps written in most Heroku-supported languages—the platform automatically detects the language and creates a default web process type to boot the application server.

What is a Heroku Procfile?

Procfile is a file that specifies the commands that are executed. by an Heroku app on startup. While it is not necessary to include a Procfile. for Heroku deployment, a Procfile allows for more startup configuration. and the definition of multiple processes that run separate dynos.


2 Answers

Okay, so I've spent a bit of time on that and came up with the answer. By default, heroku is installing all packages from the package.json file, so npm install is no longer required. Then what was left - gulp build and http-server.

For that case, I've added "postinstall" : "gulp build" to my package.json and it left me with web: http-server.

Simplifying things have actually solved the problem. Not sure how useful that information might be to you, but it's worth to share.

like image 55
ummahusla Avatar answered Sep 21 '22 12:09

ummahusla


You may also have been looking for && or a library like concurrently.

Regardless, and per the docs, use Procfile as nothing more than an entry point to your npm start script.


Use the npm scripts lifecycle as stated (npm-scripts).

Directly From The Documentation (heroku-build-process).

"scripts": {
    "start": "node index.js",
    "test": "mocha",
    "postinstall": "bower install && grunt build"
}

Heroku has adopted the 'there's an app for everything' mantra, but for buildpacks. Whatever you're building, there's a buildpack for it.

like image 41
Harry Scheuerle Avatar answered Sep 17 '22 12:09

Harry Scheuerle