Deploy two separate heroku applications from the same git repository

Within a single git repository, I have two separate applications (web server and API server).

How can I deploy each application in my own Heroku application?

(So, there are 2 heroku applications, one for the web server and one for the api server)

Note (before marking as duplicate): There are several questions like this. Most of them involve deploying one for two heroku applications - typically for production and production. I am looking to deploy two heroku apps for two apps. ( Question about staging vs prod )

+6
source share
2 answers

My understanding of your question is that you have one Git repository that contains two completely separate programs: one API server and one web server.

Given this assumption, here is what you want to do, step by step:

  • Go to the project folder.
  • Define the Procfile at the root of your project. This will tell Heroku how to start your web server and your API server.

Here's how you can make your Procfile look like (example):

 web: node web/index.js api: node api/index.js 

In my example above: I define two types of Heroku speakers: one is called web and one is called api . For each of them, you need to tell Heroku which command to run in order to start the corresponding server. In this example, I ran node web/index.js to start my site, and node api/index.js to start the API service.

  1. Create two new Heroku apps. You can do this by running heroku create <desired-app-name> --remote <desired-app-name> several times. NOTE The --remote flag tells Heroku to create a Git remote for each of your applications in the same repo.

  2. You will then need to tell Heroku about running your actual web application in one Heroku application and your API service in another Heroku application. You can do this using the Heroku CLI:

     $ heroku ps:scale web=1 --remote webserver-app-name $ heroku ps:scale api=1 --remote apiserver-app-name 

These teams will:

  • Launch one web diner for your Heroku app web server.
  • Launch one API for your Apacheer Heroku application.

As you can see above, using the ps:scale command, you can control what types of Heroku commands will be executed from your Procfile , and how many instances of each of them you would like to have.

Hope this helps!

+7
source

The solution offered by rdegges , unfortunately, no longer works. Cm:

The type of web process is special as its only type of process that will receive HTTP traffic from Herokus routers. Other types of processes may be named arbitrarily.

from Heroku documentation . Thus, you cannot have api and web in Procfile as for exposing web applications.

I believe the correct way to handle this is to use this collector provided by the Heroku: Heroku Multi Procfile buildpack team :

Imagine that you have one code base in which there are several different applications ... or at least the ability to run several different applications. Or maybe you google with your mono repo?

Anyway, how do you deal with this on Heroku? You will not do it. Heroku applications accept one repo for one application.

Introduce the multi-line Multi Procfile package, where each application receives a Procfile!

+2
source

Source: https://habr.com/ru/post/1013741/


All Articles