简体   繁体   中英

Deploying webapp and worker to Heroku from github

I have a web app which I setup the continuous deployment from github. However I'm planning to add some worker roles to this app and I'm wondering couple of things. I'm using Node.js.

In my mind, I had the design like:

  • Procfile would have the # of web and worker dynos.
  • Worker type can be a different deployment, but all I can see is it has a different start command. How does this work with the package management? What if the stuff that I require in the worker role is different than the stuff in the web app?

So my questions are?

  • Any chance that I can use the same repository and structure it in a way that the worker and web code is maintained in the same location? Can I have /web and /worker folders in the root which have different app.js and package.json files so I have them in the same repo, but their dependencies are managed differently. How can I make this work when deploying to Heroku?
  • I have some 3rd party libraries which I've installed to the web app via build packs, but I want them to be present in the worker roles. These are necessary for some of the computations that I want to do, so I'm planning to use the worker role for dequeue and process. Any way to install build packs on the worker role?
  • What's the right way of managing this through the Procfile? Can I set the number of worker roles I want in the proc file or do I need to scale up / down using the command line and that's the only option that I have?

Looks like this is entirely possible. All you need to do is have a global package.json file to manage your dependencies (you can't manage separate dependencies with worker and web role). If the package.json is not enough to make heroku detect that you're using Node.Js which was a problem I've faced; add the buildpack of heroku/nodejs and you should be ok. Whatever buildpack is installed, it will be available on the worker role.

Regarding the different directories, this is what I have now:

/web
/worker
/package.json
/Procfile

And my procfile is:

web: npm start --prefix /web
worker: npm start --prefix /worker

which seemed to fix the startup problem. There isn't any way of setting the #of dynos in the Procfile.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM