在 Heroku 上暂存实例

发布于 2024-07-30 18:28:36 字数 109 浏览 4 评论 0原文

我希望能够将代码推送到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

來不及說愛妳 2024-08-06 18:28:36

Heroku 的接口本质上是一个 Git 分支。 Heroku gem 通过其 API 完成一些工作,但在您的 Git 存储库中,它只是一个新的远程分支。

heroku create yourapp # production
git br -D heroku # delete the default branch

heroku create staging-yourapp # staging
git br -D heroku # delete the default branch

一旦你在 Heroku 上设置了多个应用程序,你应该能够像这样配置你的 Git 存储库:

git remote add staging [email protected]:staging-yourapp.git
git push origin staging

git remote add production [email protected]:yourapp.git
git push origin production

我通常在“工作”分支中工作,并使用 Github 作为我的 master。

假设您就是这种情况,您的部署工作流程可能类似于:

git co -b working
# do some work

# push to github:
git co master
git merge working
git push

# push to staging:
git co staging
git merge master
git push origin staging

# push to production
git co production
git merge master
git push origin production

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.

heroku create yourapp # production
git br -D heroku # delete the default branch

heroku create staging-yourapp # staging
git br -D heroku # delete the default branch

Once you set up multiple applications on Heroku, you should be able to configure your Git repository like this:

git remote add staging [email protected]:staging-yourapp.git
git push origin staging

git remote add production [email protected]:yourapp.git
git push origin production

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:

git co -b working
# do some work

# push to github:
git co master
git merge working
git push

# push to staging:
git co staging
git merge master
git push origin staging

# push to production
git co production
git merge master
git push origin production
不即不离 2024-08-06 18:28:36

如果您像我一样是新手,那么这解释了您需要了解的所有内容: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

琴流音 2024-08-06 18:28:36

原始问题的关键部分是将暂存应用程序链接到主应用程序 (www.myapp.com) 的子域 (dev.myapp.com)。 任何答案都没有解决这个问题。

第 1 步:按照 Luke Bayes 的回答中所述配置应用程序的生产版本(“myapp”)和临时版本(“staging-myapp”)

第 2 步:在您的域管理系统(例如 GoDaddy)中:

Create a CNAME record:  dev.myapp.com 
that points to:   proxy.heroku.com

第 3 步:配置Heroku 将 dev.myapp.com 路由到 staging-myapp:

heroku domains:add dev.myapp.com --app 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):

Create a CNAME record:  dev.myapp.com 
that points to:   proxy.heroku.com

Step 3: Configure Heroku to route dev.myapp.com to staging-myapp:

heroku domains:add dev.myapp.com --app staging-myapp

After the CNAME record has had time to propagate, you will be able to run your staging app at dev.myapp.com.

情痴 2024-08-06 18:28:36

您应该检查 heroku_san

它在处理 Heroku 上的环境方面做得非常好。

You should check the heroku_san

It does a pretty good job juggling with environments on heroku.

羁〃客ぐ 2024-08-06 18:28:36

现在事情变得容易多了。 操作方法如下...

为每个环境创建一个应用程序

$ heroku create myapp --remote production
$ heroku create myapp-staging --remote staging

这将为每个应用程序创建命名的远程存储库,您可以在 .git/config 中看到它。

现在,您可以使用 --app--remote 开关来定位特定应用程序:

$ heroku info --app myapp-staging
$ heroku info --remote staging

为 Rails 应用程序设置 Rails 环境

,Heroku 默认为“生产”环境。 如果您希望临时应用程序在临时环境中运行,请在项目中创建环境,然后在应用程序上设置相应的 RAILS_ENVRAKE_ENV 环境变量:

$ heroku config:set RACK_ENV=staging RAILS_ENV=staging --remote staging

配置环境

如果您有其他配置变量,则还需要为每个环境传递它们。

$ heroku config:set AWS_KEY=abc --remote staging
$ heroku config:set AWD_SECRET=123 --remote staging
...etc

但这是一个巨大的痛苦,所以我只是使用我的 snappconfig gem 并运行

$ rake heroku:config:load[myapp-staging]

来加载我的项目的 YAML配置文件到 Heroku.

部署

现在,您只需像这样推送到 Heroku:

$ git push staging master
$ git push production master

并像这样迁移:(

$ heroku run rake db:migrate --remote staging
$ heroku run rake db:migrate --remote production

请参阅管理应用程序的多个环境 | Heroku 开发中心< /a> 了解更多信息和快捷方式。)

Things are easier now. Here's how you do it...

Create an app for each environment

$ heroku create myapp --remote production
$ heroku create myapp-staging --remote staging

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:

$ heroku info --app myapp-staging
$ heroku info --remote staging

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:

$ heroku config:set RACK_ENV=staging RAILS_ENV=staging --remote staging

Configure environments

If you have other configuration variables you'll need to pass them in for each environment as well.

$ heroku config:set AWS_KEY=abc --remote staging
$ heroku config:set AWD_SECRET=123 --remote staging
...etc

That's a huge pain though so I just use my snappconfig gem and run

$ rake heroku:config:load[myapp-staging]

to load my project's YAML config files into Heroku.

Deploy

Now you just push to Heroku like this:

$ git push staging master
$ git push production master

and migrate like this:

$ heroku run rake db:migrate --remote staging
$ heroku run rake db:migrate --remote production

(See Managing Multiple Environments for an App | Heroku Dev Center for more info and shortcuts.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文