1

我正在创建一个 Play 2.1.3 网络应用程序,并在 Heroku 中设置了两个环境,一个用于生产,一个用于暂存。

区分这两种环境的最简单方法是什么?例如,我不希望搜索机器人为我的登台应用程序编制索引,因此我想添加一个robots.txt用于登台,但在推送存储库时它也会被添加到生产环境中。

我是否应该在我的计算机上有两个本地(app-prodapp-staging)Play 应用程序以及单独的 git 存储库?然后我必须让这两个应用程序保持同步。在验证 Heroku 上的暂存应用程序成功运行后,我必须将这些更改与我本地计算机上的生产应用程序同步(我如何使用 Git 做到这一点?),然后将这些更改推送到 Heroku 上的生产应用程序。

4

2 回答 2

1

I'm not familiar with Play but for my applications I use a basic authentication prompt on them for staging so I know that nothing can be seen whilst I'm working on it or indexed at all.

If you want to use a more traditional git flow your are best with having two Heroku applications and deploy to them from a single git repo using corresponding branches - when you connect your repo to Heroku then name the remotes something like production and staging so it's easier to distinguish when you push. (you would probably be used to see git push heroku master up to this point)

eg

git remote add production <git url of production heroku app>
git remote add staging <git url of staging heroku app>

then your deployment process becomes;

  • git push staging staging:master - deploy local staging branch to the staging remotes master branch
  • verify on staging Heroku app
  • git checkout master - switch to local master branch
  • git merge staging - merge staging into local master
  • git push production master - deploy local master to the production remote

Heroku have also introduced a new feature recently called Pipelines which sounds like it might be of also be a fit here https://devcenter.heroku.com/articles/labs-pipelines.

于 2013-09-07T07:20:32.297 回答
1

您可以创建一个名为 robots.txt 的路由,该路由返回 404 或实际资产。它可以查看 application.conf ,然后它会从您为不同环境设置的环境变量中读取以修改应用程序行为。

编辑:

我应该更好地解释我的解决方案。您可以创建一个控制器以具有一些次要逻辑。这是应该给出返回 404 或实际 robots.txt 文件的逻辑的地方。

package controllers

import java.io.File
import play.api.mvc._

object Robots {

  def get = Action {
    Ok.sendFile(
      content = new File("/path/to/your/robots.txt"),
      fileName = _ => "robots.txt"
    )
  }
}

您可以在此处找到有关提供文件的文档:http ://www.playframework.com/documentation/2.2.x/ScalaStream

然后路由文件将只有

GET /robots.txt   controllers.Robots.get

这将比资产控制器具有更高的优先级

于 2013-09-06T22:14:04.407 回答