在 Heroku 中为 Phoenix 构建开发环境

Building a dev environment in Heroku for Phoenix

我正在尝试设置 Phoenix 1.2,以便我有两个 Heroku 环境:一个用于 dev/testing(它将保留 this-app-12345.herokuapp.com url),和标准的生产环境。

目前,我以通常的方式设置我的应用程序:

mix phoenix.new my_app
cd my_app
mix ecto.create
mix ecto.migrate
git init && git add . && git commit -m "Initial commit"
heroku create

这给了我一个 Heroku 实例:

Creating app... done, ⬢ first-instance-12345
https://first-instance-12345.herokuapp.com/ | https://git.heroku.com/first-instance-12345.git

然后我添加构建包,更改 config/ 文件和 运行 git push heroku master,一切正常。

现在我想创建另一个 Heroku 实例,我也可以部署到该实例。如果我再次 运行 heroku create,我会得到:

Creating app... done, ⬢ second-instance-23456
https://second-instance-23456.herokuapp.com/ | https://git.heroku.com/second-instance-23456.git

如果我用新实例替换 prod.exs 中的 url...

config :my_app,  MyApp.Endpoint,
  http: [port: {:system, "PORT"}],
  url: [scheme: "https", host: "second-instance-23456.herokuapp.com", port: 443], force_ssl: [rewrite_on: [:x_forwarded_proto]],

...然后提交并运行 git push heroku master,它仍然会部署到第一个实例-12345.herokuapp.com,这不是我想要的。

重新运行构建包也无济于事。

$ heroku buildpacks:add https://github.com/HashNuke/heroku-buildpack-elixir
 ▸    The buildpack https://github.com/HashNuke/heroku-buildpack-elixir is already set on your app.
$ heroku buildpacks:add https://github.com/gjaldon/phoenix-static-buildpack
 ▸    The buildpack https://github.com/gjaldon/phoenix-static-buildpack is already set on your app.

是否有标准方法(或任何方法)让 Phoenix 部署到多个 heroku 环境? (并希望在部署时指定 one/s)

将一个应用程序部署到多个 Heroku 应用程序的标准方法是将多个远程添加到存储库并推送到您要部署到的那个。对 config/prod.exs 进行更改不会影响应用程序的部署位置。

添加两个遥控器的方法如下:

$ git remote add first https://git.heroku.com/first-instance-12345.git
$ git remote add second https://git.heroku.com/second-instance-23456.git

现在您可以使用以下方式部署到第一个:

$ git push first master

第二个使用:

$ git push second master

当然最好的方法是像@dogbert 写的那样有两个不同的实例。 还要记住为 heroku 更改 Procfile,因为你想 运行 应用程序使用不同的环境,例如

# Procfile for prod
web: MIX_ENV=prod mix phoenix.server

# Procfile for dev
web: MIX_ENV=dev mix phoenix.server

对于这两种环境,您都需要应用迁移:

heroku run MIX_ENV=<env> ecto.migrate