Alex
Alex

Reputation: 38519

Managing Heroku Multiple environments with existing app

I've got an app, that has 'heroku' configured as a remote, to one application.
Let's call this app 'MyAppDev'

However, I have another app, called 'MyAppLive'
I want to configure deployment like this:

git push staging
push to MyAppDev

git push production
push to MyAppLive

How can I do this?

Also, what about environment variables?
Both apps have MongoLab, so I'd like the MyAppDev app to use it's own db....

Upvotes: 2

Views: 3839

Answers (1)

John Beynon
John Beynon

Reputation: 37507

Here are the steps that you'd need to follow

  1. git remote rm heroku - this will remove the heroku remote from your application

  2. git remote add production <production apps heroku git repo url> - this will add a new remote named 'production' pointing at the production apps git repo url (you can get this from the My Apps page on heroku.com

  3. git remote add staging <staging apps heroku git repo url>

This now means you can do git push production master or git push staging master to push your codebase to either repo.

NOTE If you need to push branches to Heroku you need to push them into the master branch of Heroku.

eg. assuming a staging branch locally you would do;

git push staging staging:master

To push your locally staging branch into master of the staging remote.

Any addons you use would need to be duplicated to the staging application.

Config variables can either be done manually via heroku config:set or you can use the plugin detailed at the bottom of this page https://devcenter.heroku.com/articles/config-vars which allows you to push and pull your Heroku variables into a .env file suitable for running with Foreman locally. Becareful about overriding variables though - I tend to do my variables manually as I don't typically have many.

Upvotes: 15

Related Questions