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

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

问题描述

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

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

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

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

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

注意(在标记为重复之前):有几个类似的问题.大多数处理将一个应用程序部署到两个heroku应用程序 - 通常用于分段与生产的目的.我希望将 两个 应用程序部署到 两个 heroku 应用程序.(关于 staging 与 prod 的问题)

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)

推荐答案

我对你的问题的理解是你有一个 Git 存储库,其中包含两个完全独立的程序:一个 API 服务器和一个 Web 服务器.

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. 进入您的项目文件夹.
  2. 在项目的根目录定义一个 Procfile.这将告诉 Heroku 如何运行您的 Web 服务器和 API 服务器.
  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.

以下是您可能希望 Procfile 的外观(示例):

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

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

在我上面的例子中:我定义了两种类型的 Heroku dynos——一种叫做 web,一种叫做 api.对于每一个,你都需要告诉 Heroku 运行什么命令来启动适当的服务器.在这个例子中,我将运行 node web/index.js 来启动我的网站,并运行 node api/index.js 来启动我的 API 服务.

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. 创建两个新的 Heroku 应用程序.你可以通过运行 heroku create 来做到这一点.--remote 多次.注意:--remote 标志将告诉 Heroku 为同一存储库中的每个应用程序创建一个 Git 远程.

  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.

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

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

这些命令将:

  • 为您的网络服务器 Heroku 应用运行单个网络动态.
  • 为您的 apiserver Heroku 应用运行单个 API dyno.

正如你在上面看到的,使用 ps:scale 命令你可以控制 Heroku 将从你的 Procfile 运行什么类型的命令,以及每个你的实例的数量想要.

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.

希望这会有所帮助!

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

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