Git Deployment + Configuration Files + Heroku

GIt Deployment + Configuration Files + Heroku

You can have config vars persistently stored ON each heroku app's local setup so they do not have to be in your code at all! so the same code can run on multiple heroku sites but with different configuration. It very simple, easy, elegant...

It's the approach we used. (We used it for the SAME thing... we have multiple clones of the SAME app at Heroku, but we want only ONE source at github, in our dev local directory we do the PUSH to ORIGIN (github), then when we have it the way we like it, we CD to the prod local directory, which goes to the SAME github repository, and we ONLY PULL from GITHUB into this directory, never push (eg, all pushes to github come from our dev directory, the prod directory is just a staging area for the other heroku app.)

By having the different configs ON the different HEROKU sites (as explained below), the EXACT SAME CODE works on BOTH heroku sites.

So our workflow is: (the key is that BOTH directories point to SAME github repo)

cd myDEVdir
*....develop away....*
git add .
git commit -am "another day, another push"
git push origin *(to our SINGLE github repo)*
git push heroku *(test it out on heroku #1)*

cd ../myPRODdir
git pull *(grabs SAME code as used on other site *)
git push heroku *(now the SAME code runs on Heroku #2)*

that's it!

Now here's how you keep your site-specific config vars ON the heroku site:

http://docs.heroku.com/config-vars

on your local command line, for EACH of your two local directories, do:

$ heroku config:add FIRST_CONFIGVAR=fooheroku1
Adding config vars:
FIRST_CONFIGVAR => fooheroku1

$ heroku config:add SECOND_CONFIGVAR=barheroku1
Adding config vars:
SECOND_CONFIGVAR => barheroku1

to see the ones you have defined:

$ heroku config
FIRST_CONFIGVAR => fooheroku1
SECOND_CONFIGVAR => barheroku1

then cd to your other directory myPRODdir and do the SAME thing, only set the same remote heroku vars to fooheroku2 and barheroku2.

then in your rails app you simple refer to them like so:

a = ENV['FIRST_CONFIGVAR']

One app will read 'fooheroku1' the other app will read 'fooheroku2'

And finally, on your LOCAL directory myDEVdir, where you run in DEV mode, put the same config commands in your config/environment/development.rb file your 'dev' version of the config vars will be set to whatever they should be:

ENV['FIRST_CONFIGVAR'] = "foodev"
ENV['SECOND_CONFIGVAR'] = "bardev"

Easy, elegant. Thanks, Heroku!

Deployment to heroku with private config file

If you have sensitive static configuration data that you want to hide then Environment Variables may be the answer. For example your Postgres User/Pass and Addon API keys are stored as environment variables on Heroku. It's only really an option for a small amount of information, not a huge configuration file. See this for how to setup config/env variables:
https://devcenter.heroku.com/articles/config-vars

If you want to keep the file, then I found this: How to hide connection string, user name, pw when using source control?. As long as you are not pushing to heroku from the remote branch (git push heroku remote) and pushing from a branch that you have on your local (git push heroku master) then the files on your box will be pushed up, not the files on github.

Heroku: Difficulty in deploying Node.js app, as a configuration file is not published in GitHub

Use Environment variables on Heroku. As you rightly mentioned in your question, it is not a good idea to push credentials and other sensitive information in code repositories. So instead of pushing .env file, just create Environment Variables on Heroku. It can be done using Heroku web interface or using Heroku CLI too.

Sample commands on CLI will look like

To get existing config variables

heroku config

To get a specific config variable

heroku config:get GITHUB_USERNAME

To set a config variable

heroku config:set GITHUB_USERNAME=joesmith

To delete a config variable

heroku config:unset GITHUB_USERNAME

To access variable inside your Node.js app,

process.env.GITHUB_USERNAME

Configuration and Config Vars

How to deploy heroku app with secret yaml configuration file without committing the file?

Heroku have some guidance on this -

http://devcenter.heroku.com/articles/config-vars

How to mantain files in Heroku that are not in git repo after a deploy


How can I set up a file on Heroku that I can use to save user data that is not affected by git pushes and deploys?

You can't.

Furthermore, this isn't just about deploys: your file will be lost at other times too.

Your file isn't being overwritten by Git; Heroku's filesystem is ephemeral. Any changes made to it will be lost any time the dyno restarts. This happens frequently (at least once per day) whether you deploy or not.

You will need to change how you're persisting data. I suggest using a real client-server database, but you could also save your file in third-party object storage using something like Amazon S3 or Azure Blob Storage.

managing production credentials in heroku

you can set environment variables on heroku by using the heroku gem:

heroku config:add MYKEY=12345679

and you can use that in your heroku App using ENV['MYKEY']

See: http://devcenter.heroku.com/articles/config-vars

keep config file on heroku but remove from public repo on github?

Heroku take all your files from Github, each push replace all your files by the new ones. I don't think you can do something like this.

If you put your file in the .gitignore, you won't be able to push it to Heroku.

A solution may be to use branch on Github, on the master you keep your code without the config file, and on the branch "Heroku", you add the file and use it to do the push on Heroku.



Related Topics



Leave a reply



Submit