5

I'm trying to add a few files (credentials and API keys) to my Heroku app without having to commit them to a public GitHub repository. How would I go about doing that?

Max Gordon
  • 195
  • 14

2 Answers2

1

If I recall correctly, you have to push to Heroku and Git separately. If that is the case, then simply commit all your files, push to Heroku. Then reset your files

git reset --soft HEAD~1

Add only the files you want. Commit those files and then push to your remote git repo.

Sanil Khurana
  • 1,129
  • 9
  • 20
1

I’d strongly recommend not to complicate your deployment strategy by having different files in your deployment than your version control. You run the risk of missing steps when deploying and breaking your release. Instead, the recommended approach is to use Heroku Config Vars to store secrets such as credentials and keys, as these will persist across releases, see https://devcenter.heroku.com/articles/config-vars for details.

maniacalrobot
  • 2,413
  • 2
  • 18
  • 20
  • Can I add other data type like dicts to the config vars? – Max Gordon Oct 18 '19 at 11:16
  • you can add anything to config vars, as they're basically a key/value store, where everything is a string. So it's totally possible to store things like json objects, it's just up to you deserialize the data when you read it from the environment. – maniacalrobot Oct 18 '19 at 21:57
  • Other problem with config vars is that they are not reachable from the build process when using heroku container. – diegocl02 Feb 16 '21 at 20:46
  • Config Vars are used to define the environments that your app will run in like 'production', 'staging', 'uat' … Your build, once completed, should be deployable to any environment in your applications pipeline. So relying on Config Vars during builds could lead to unexpected behaviour when using the build in your different environments. That's not to say that it wouldn't be very handy to use config vars in builds, there are lots of situations where this would seem like a good idea, but it's not what config vars are designed for. – maniacalrobot Feb 17 '21 at 09:24