在 Heroku 上暂存实例
我希望能够将代码推送到 dev.myapp.com
进行测试,然后推送到 www.myapp.com
进行生产使用。 Heroku 可以做到这一点吗?
I'd like to be able to push code to dev.myapp.com
for testing and then to www.myapp.com
for production use. Is this possible with Heroku?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
Heroku 的接口本质上是一个 Git 分支。 Heroku gem 通过其 API 完成一些工作,但在您的 Git 存储库中,它只是一个新的远程分支。
一旦你在 Heroku 上设置了多个应用程序,你应该能够像这样配置你的 Git 存储库:
我通常在“工作”分支中工作,并使用 Github 作为我的 master。
假设您就是这种情况,您的部署工作流程可能类似于:
Your interface to Heroku is essentially a Git branch. The Heroku gem does some work through their API, but within your Git repository, it's just a new remote branch.
Once you set up multiple applications on Heroku, you should be able to configure your Git repository like this:
I usually work in a 'working' branch, and use Github for my master.
Assuming that's the case for you, your deploy workflow would probably look something like:
如果您像我一样是新手,那么这解释了您需要了解的所有内容:http://devcenter.heroku.com/articles/multiple-环境
This explains everything you need to know if your a newbie like me: http://devcenter.heroku.com/articles/multiple-environments
原始问题的关键部分是将暂存应用程序链接到主应用程序 (www.myapp.com) 的子域 (dev.myapp.com)。 任何答案都没有解决这个问题。
第 1 步:按照 Luke Bayes 的回答中所述配置应用程序的生产版本(“myapp”)和临时版本(“staging-myapp”)
第 2 步:在您的域管理系统(例如 GoDaddy)中:
第 3 步:配置Heroku 将 dev.myapp.com 路由到 staging-myapp:
CNAME 记录有时间传播后,您将能够在 dev.myapp.com 运行您的 staging 应用程序。
A key part of the original question is about linking up the staging app to a subdomain (dev.myapp.com) of the main app (www.myapp.com). This hasn't been addressed in any of the answers.
Step 1: Configure both production ('myapp') and staging ('staging-myapp') versions of your app as is indicated in the answer by Luke Bayes
Step 2: In your domain management system (e.g. GoDaddy):
Step 3: Configure Heroku to route dev.myapp.com to staging-myapp:
After the CNAME record has had time to propagate, you will be able to run your staging app at dev.myapp.com.
您应该检查 heroku_san
它在处理 Heroku 上的环境方面做得非常好。
You should check the heroku_san
It does a pretty good job juggling with environments on heroku.
现在事情变得容易多了。 操作方法如下...
为每个环境创建一个应用程序
这将为每个应用程序创建命名的远程存储库,您可以在
.git/config
中看到它。现在,您可以使用 --app 或 --remote 开关来定位特定应用程序:
为 Rails 应用程序设置 Rails 环境
,Heroku 默认为“生产”环境。 如果您希望临时应用程序在临时环境中运行,请在项目中创建环境,然后在应用程序上设置相应的 RAILS_ENV 和 RAKE_ENV 环境变量:
配置环境
如果您有其他配置变量,则还需要为每个环境传递它们。
但这是一个巨大的痛苦,所以我只是使用我的 snappconfig gem 并运行
来加载我的项目的 YAML配置文件到 Heroku.
部署
现在,您只需像这样推送到 Heroku:
并像这样迁移:(
请参阅管理应用程序的多个环境 | Heroku 开发中心< /a> 了解更多信息和快捷方式。)
Things are easier now. Here's how you do it...
Create an app for each environment
This will create named remote repos for each app, which you can see in
.git/config
.You can now use either the --app or --remote switches to target a particular app:
Set Rails environments
For Rails apps, Heroku defaults to the "production" environment. If you want your staging app to run in a staging environment, create the environment in your project and set the corresponding RAILS_ENV and RAKE_ENV environment variables on the app:
Configure environments
If you have other configuration variables you'll need to pass them in for each environment as well.
That's a huge pain though so I just use my snappconfig gem and run
to load my project's YAML config files into Heroku.
Deploy
Now you just push to Heroku like this:
and migrate like this:
(See Managing Multiple Environments for an App | Heroku Dev Center for more info and shortcuts.)