Staging instance on Heroku

前端 未结 5 843
遇见更好的自我
遇见更好的自我 2020-12-12 08:59

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?

5条回答
  •  心在旅途
    2020-12-12 09:30

    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.)

提交回复
热议问题