从同一个git仓库部署两个独立的heroku应用程序 [英] Deploy two separate heroku apps from same git repo

查看:100
本文介绍了从同一个git仓库部署两个独立的heroku应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个git仓库中,我有两个独立的应用程序(Web服务器和API服务器)。



如何将每个应用程序部署到自己的Heroku应用程序?


$ b (所以有2个heroku应用程序,一个用于web服务器,一个用于api服务器)



注意(在标记为重复之前):
有几个类似的问题。大多数情况下将部署一个应用程序部署到两个 heroku应用程序 - 通常用于分期制作和制作。我正在考虑将两个应用程序部署到两个 heroku应用程序。 (关于分期和产品的问题

解决方案

我对你的问题的理解是你有一个Git仓库,它包含两个完全独立的程序:一个API服务器,和一个网络服务器。



考虑到这个假设,下面是你想要做的,一步一步的:


  1. 进入您的项目文件夹。

  2. 定义一个 Procfile 你的项目。这将告诉Heroku如何运行您的Web服务器和您的API服务器。

以下是您可能希望 (例子):

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

在上面的示例中:我定义了两种类型的Heroku dynos--一个名为 web 和一个名为 api 的程序。对于每一个,你都需要告诉Heroku运行什么命令来启动相应的服务器。在这个例子中,我会运行 node web / index.js 来启动我的网站,并且 node api / index.js 启动我的API服务。


  1. 创建两个新的Heroku应用程序。您可以通过运行 heroku create< desired-app-name> --remote< desired-app-name> 多次。 注意 - remote 标志会告诉Heroku为同一个仓库中的每个应用程序创建一个Git Remote。


  2. 接下来,您需要告诉Heroku在一个Heroku应用程序上运行实际的Web应用程序,并在另一个Heroku应用程序上运行您的API服务。您可以使用Heroku CLI完成此操作:

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


这些命令将会:


  • 为您的Web服务器Heroku应用程序运行一个Web dyno。 li>
  • 为您的apiserver Heroku应用程序运行一个API dyno。



如上所示, ps:scale 命令可以控制Heroku将从 Procfile 运行的命令类型,以及每个你想拥有。



希望这有助于!


Within one git repo, I have two separate applications (web server and API server).

How can I deploy each application to its own Heroku app?

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

Note (before marking as duplicate): There are several questions similar to this. Most deal with deploying one app to two heroku apps - typically for the purpose of staging vs. production. I am looking to deploy two apps to two heroku apps. (Question about staging vs prod)

解决方案

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

With this assumption in mind, here's what you'll want to do, step-by-step:

  1. Go into your project folder.
  2. Define a Procfile at the root of your project. This will tell Heroku how to run your web server and your API server.

Here's how you might want your Procfile to look (an example):

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

In my example above: I'm defining two types of Heroku dynos -- one called web and one called api. For each one, you'll need to tell Heroku what command to run to start the appropriate server. In this example, I would run node web/index.js to start up my website, and node api/index.js to start up my API service.

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

  2. Next, you'll need to tell Heroku to run your actual web application on one Heroku app, and your API service on another Heroku app. You can do this by using the Heroku CLI:

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

These commands will:

  • Run a single web dyno for your webserver Heroku app.
  • Run a single API dyno for your apiserver Heroku app.

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

Hopefully this helps!

这篇关于从同一个git仓库部署两个独立的heroku应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆