Managing Heroku Multiple environments with existing app - heroku

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

Here are the steps that you'd need to follow
git remote rm heroku - this will remove the heroku remote from your application
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
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.

Related

How to push certain commits only to Heroku but not github

I am using a github repository that is public and deploy my app on Heroku. How do I only push commits to Heroku and not to github when I then push to origin again?
More specifically, I need to edit a .env file for Heroku that I do not want to publish on Github. I did a few commits on that file and pushed it to heroku via git push heroku master.
I do not want those commits to be pushed to github as well. Now when I make new commits and push it via git push origin master, are the previous commits (which were only ment for Heroku) pushed as well? If yes, how do I avoid this?
A few things:
1) .env probably shouldn't be checked in. A common pattern is to create a .env.sample file with placeholder values, add .env to gitignore and instruct users to copy .env.sample to .env and populate the placeholder values for development.
2) Those sensitive values can be set in Heroku's environment on the CLI via heroku config:set FOO=bar and will be available to your app through: ENV['FOO']

How do I have two different apps on heroku with two different branches on the same repository, while choosing my own app names?

This isn't critical, but annoying.
I have an app that regularly runs as a web server, but uses another app I created to run a rest server with a specific config file if an environment variable is set. (it's simpler than it sounds)
I've used:
heroku create --remote web_server
> created terriblename123.heroku.com
heroku create --remote rest_server
> created existentialcrisis345.heroku.com
and that works, but the apps have weird names. When i go to rename the apps through the web console I get a warning that the remote may break.
Honestly, using this method appears to be very brittle. I don't know how to switch between apps in heroku. There doesn't appear to be state or a way to say which app I'm configuring with the heroku commands.
Just create multiple remotes in same git repository.
For example I have one repository for staging and production heroku app.
~/code/my_app $ git remote -v
origin ssh://git#my_git_server/my_app.git (fetch)
origin ssh://git#my_git_server/my_app.git (push)
production git#heroku.com:my-app-production.git (fetch)
staging git#heroku.com:my-app-staging.git (fetch)
production git#heroku.com:my-app-production.git (push)
staging git#heroku.com:my-app-staging.git (push)
You can name the remotes as you want.
When deploying to heroku, you can specify which heroku app or remote should be used.
heroku push production master or heroku push staging master

git with app in heroku and github

With an app in heroku, with git url like git#heroku.com:app.git,
And a repo in github https://github.com/username/other_app.git
Is possible sync the two repos for hosting the sema app in two git servers (heroku and github) ?
And also Link Heroku app to Github repo. For what?
Yes of course this is possible, because git is a distributed repository. You can configure multiple remotes, one at GitHub and one at heroku, and just push your changes to both of them.
Example:
Create repository at GitHub
Clone this repository on your machine, now you have setup the remote "origin" to be GitHub
Setup heroku and add the heroku git remote (either by running heroku create or heroku git:remote -a my_heroku_app). Find details in the git documentation of heroku.
here are some useful commands when working with github/heroku:
show github remote:
git remote show origin
show heroku git:
git remote show heroku
push github to heroku:
git push heroku master
if you have a 'staging' branch on github and want to push this to heroku git (master) for a
'staging app':
git push heroku staging:master -v

How to make a devel enviroment on my app on Heroku

I wonder now about an option to have a devel version of my project on Heroku address. I mean, I have my project on the address my-random-name.heroku.com and here from my local directory I deploy my app.
Is possible from my local directory deploy my app to the other address, where I would check the new updates and if these updates will be ok, so I will deploy these changes to the my-random-name.heroku.com (here is my "bright" version of my app).
Yes - Heroku applications are just git remotes, so by pushing to a different remote you can deploy to a different application.
For instance:
git remote add production git#heroku.com:appname-production.git
git remote add staging git#heroku.com:appname-staging.git
will then allow you to deploy to each env with a simple push.
git push production master
git push staging master
If you're using different branches for development and production (a good idea) you can also deploy fairly simply

Only allow 'git push heroku master' from the master branch

I recently set up dev/staging/production environment on OSX Lion. I have a git repo with a development and a master branch, and a Heroku instance with master and staging origins.
The basic workflow is to develop in the development branch, merge into master, deploy to staging, then finally deploy to production.
I'd like to prevent Heroku deployments when I'm in any branch that isn't master, or at a minimum display a warning (e.g. "Would you like to continue? y/n").
Is this possible? Is there a git or Heroku feature that facilitates this, or would I need to write a bash script?
From the Heroku documentation:
Branches pushed to Heroku other than master will be ignored.

Resources