Search code examples
ruby-on-rails-3deploymentherokugithubproduction-environment

deploying to a test server before production on heroku


As I am new at this, I am not sure if this is how it should be -

I am making a webapp and using heroku for hosting

I want to have several developers working on the same code on github.

I'd like to have 2 servers on heroku - one for production and one for testing(is it also called staging?)

problem is I know what by doing git push heroku master from the webapp folder it will send it to the application to the heroku server which was setup in the first place.

  1. How do I deploy to 2 different heroku instances from the same folder using git? Is it possible/ recommended?

  2. When I push to github it's usually the master, should I have another branch for test?

  3. Is there a way to transfer an app between heroku instances?

if there's a place where there is a recommended deployment routine for heroku and github I'd be happy to read it


Solution

  • When you run git push heroku master 'heroku' identifies the remote repository you are pushing to. In your case 'heroku' seems to be a reference to your production server. Similarly you probably have an 'origin' remote pointing to github.

    If you list your git remotes you'll probably see something like this:

    > git remote -v 
    heroku  git@heroku.com:heroku_app_name.git (fetch)
    heroku  git@heroku.com:heroku_app_name.git (push)
    origin  git@github.com:your_github_org/repo_name.git (fetch)
    origin  git@github.com:your_github_org/repo_name.git (push)
    

    To push to a different heroku app you can just add that app as a new git remote.

    git remote add heroku-staging git@heroku.com:heroku_staging_app.git
    

    Now you should be able to push to either remote as needed.

    git push origin master //push to github
    git push heroku-staging //deploy to staging
    git push heroku master //deploy to production
    

    In general I suggest that you should not be pushing to heroku manually. Hopefully you can have a continuous integration server watch github, run tests whenever you push changes, and deploy to staging only when your automated tests pass. You can then have a manually triggered CI task which pushes whichever commit is currently on staging to production as well (or even automate production deploys as well).

    You can perform the same configuration using the heroku command line. That also gives you a good way to manage environment variables and other settings on both of your heroku apps: https://devcenter.heroku.com/articles/multiple-environments