I'd like to use Datomic Pro (Starter Edition, for now) on Heroku. But I don't want to commit my download key into Git. Instead, the right thing to do would seem to be store it in an environment variable. That means my project.clj now contains:
:dependencies [[org.clojure/clojure "1.5.1"]
[com.datomic/datomic-pro "0.9.4707"]]
:repositories {"my.datomic.com" {:url "https://my.datomic.com/repo"
:username ~(System/getenv "DATOMIC_EMAIL")
:password ~(System/getenv "DATOMIC_KEY")}}
I've set DATOMIC_EMAIL and DATOMIC_KEY in the Heroku app's config. Turns out that doesn't matter, because the project.clj is processed during the build phase, without access to the environment variables.
Now that the user-env-compile feature no longer exists, how can I get Datomic running on Heroku?
(I could fork the buildpack and force the environment variables to be used during the build phase, but I'd rather avoid going that far if I can.)
I think you no longer need to fork the buildpack. Heroku recently made changes to their buildpack API that allow buildpacks to see environment vars that you've set for your app.
As described in Clojure buildpack's README, you need to set BUILD_CONFIG_WHITELIST var to something like this: DATOMIC_EMAIL DATOMIC_KEY and also, of course, set DATOMIC_EMAIL and DATOMIC_KEY vars accordingly.
Hope this helps.
Related
if I exclude the file with API KEY and push to gitHub and then to Heroku the app doesn't work because the app can't get access to the api key.
What is the workaround? I'm quite a novice so comments or info with human readable language would be highly appreciated. Thanks!
You need to store the API key as an environment variable.
In heroku, go to your app, then settings and click on "Reveal Config Vars".
In there you can store your API key for your deployed server to use. This is also where you will store DB urls too, etc.
Heroku has interface for setting up environment variables.
So use environment variable locally (from environment or e.g. .env file) and remotely.
Also read on 12-factor-app
Usually this kind of stuff should be kept in Heroku config variables. I find heroku command line more convenience. You can download it here. Then, you can use this command to setup the new Heroku configVar at will.
heroku config:set API_KEY=1234567890 --app your_app_name
To see all configs,
heroku config --app your_app_name
Then, based on the language developed, you can access this configVar from code. For example, you can do this in Ruby on Rails' code.
<%= ENV["MY_API"] %>
I'd like to get the release version of my app in Heroku on PHP. I was hoping it might be available as an environment variable, for example like $_ENV['HEROKU_RELEASE'] might retrieve v23. Is there a way to get ahold of this?
Yes, that is possible, by enabling dyno metadata on your app with the following command:
heroku labs:enable runtime-dyno-metadata -a
Then, Heroku will set a HEROKU_RELEASE_VERSION environment variable on your app (as well as other ones, which are all described in the article linked above).
That variable includes the number of the current release for your app.
I'm not really sure where to start with this. I'm making a Ruby project that interfaces with a dictionary API, and uses an API key. I don't want anybody and his uncle to be able to see this key, but the project will have to be hosted on GitHub. How can I go about doing this, and accessing the key from the Ruby program?
Clarification: this is for a class, and we have to use GitHub
Normally, you'd put such things in a file like this:
DICTIONARY_API=key_goes_here
and check in a version of the file (named .example or .sample or something) which just contains blanks:
DICTIONARY_API=
Or you could read the key from the environment, using ENV. If you host on Heroku, this is recommended. See also the Dotenv gem and the ENVied gem.
I've seen both methods combined (especially when using Dotenv) by making a .env file for local/non-heroku usage, and using Heroku's config settings on Heroku.
Use the Figaro gem. Documentation
Basically you will use a file called application.yml and store environmental variables. Double check that application.yml is listed in your .gitignore file so nobody can view it on github.
You could set:
# application.yml
API_KEY: my_api_key_here
And then you could set it to another variable in your app with:
# anywhere in your app
api_key = ENV['API_KEY']
For production, you can use Figaro's commands to sync your env variables with Heroku.
I have more than one app/git remote at heroku and I would like to know if it is possible to configure a default application so that, whenever I forget to specify the app (--app), the toolbelt would use it.
You can set the heroku.remote key in your repo's Git config to the name of the default remote. For example, if your remote is called staging, you could do this:
$ git config heroku.remote staging
To see how this works, here is the relevant source.
For more, information about this, see Managing Multiple Environments for an App.
You could also go for:
heroku git:remote -a <name-of-the-app>
or if you tend to make a lot of mistakes in the configuration of wrong apps, you can use this library I made: https://github.com/kubek2k/heroshell
This is a Heroku wrapper shell that allows you to work in the context of a given Heroku application
You can set the HEROKU_APP environment variable.
Found this question while searching for it myself. The other answers refer to Heroku's old ruby-based CLI. The new JS CLI doesn't seem to support the same git-remote-reading feature. A quick search of the source code on GitHub found this.
I made a Sinatra app, that will be hosted on Heroku, and the source will be up on GitHub. The problem is that i have a file with API keys, that is currently in .gitignore. Is there a way, that I can push my repo to heroku with the key file and exclude the file when pushing to GitHub?
Thanks in advance!
It is possible to maintain a separate branch just for deployment, but it takes much discipline to maintain it properly:
Add a commit to a production branch that adds the config file (git add -f to bybass your excludes).
To update your production branch, merge other branches (e.g. master) into it.
However, you must then never merge your production branch into anything else, or start branches based on any “production commit” (one whose ancestry includes your “add the keys” commit).
An easier path is to adopt Heroku’s custom of using environment variables to communicate your secret values to your instances. See the docs on Configuration and Config Vars:
heroku config:add KEY1=foobar KEY2=frobozz
Then access the values via ENV['KEY1'] and ENV['KEY2'] in your initialization code or wherever you need them. To support your non-Heroku deployments, you could either define the same environment variables or fall back to reading your existing config files if the environment variables do not exist.
The Figaro gem provides a good way to manage this issue. It basically simulates Heroku's environment variable approach locally, and makes it easy to keep your keys in sync between your development environment and Heroku.