I've deployed an app to Heroku, and I'm currently storing my environment variables in an .env file. I used heroku config:push to push the variables up to heroku, and that worked fine.
Now, I want to update one of them. I changed it in my .env file, and ran heroku config:push again. The push said it was successful, but when I run heroku config, I can see that the values actually haven't changed. I've tried running heroku restart, but that didn't do anything.
How can I update my environment variables in heroku?
Figured it out. You need to run heroku config:push --overwrite because it won't overwrite existing variables by default. This is poorly documented :-/
Related
I want Heroku to not set SECRET_KEY_BASE so I can use the one from credentials, but despite me deleting it from the UI, verifying it doesn't exist by running heroku config, I still get it set as an environment variable on my dynos. And it's the same in all the dynos:
SECRET_KEY_BASE=d2753b472abb...
I also tried setting it to a blank string by running heroku config:set SECRET_KEY_BASE="" and Heroku insist on setting it up as I can see by running bash and then env within bash.
How can I prevent that from happening?
Unfortunately, the Heroku Ruby buildpack generates and sets SECRET_KEY_BASE via the shell if it doesn't exist in your Heroku config vars.
It currently doesn't seem possible to directly use the secret key set in credentials.yml. You could make credentials.yml and SECRET_KEY_BASE align though.
Source: https://github.com/heroku/heroku-buildpack-ruby/issues/1143
And here is a short extract from that issue:
If you set your own SECRET_KEY_BASE, we do nothing.
If you do not set a SECRET_KEY_BASE we generate and set one for you.
We recommend using our heroku config interface for storing secrets rather than using the encrypted file storage that ships with rails.
If you want to use encrypted file storage locally with rails you could copy our secret key base heroku run echo $SECRET_KEY_BASE or you can set your own
value manually locally and then again via heroku config.
I deleted secrets.yml and created credentials.yml.enc.
Locally I am using master.key, and in production I don't have any master key, only a RAILS_MASTER_KEY set as an environment variable.
On Heroku, if I run Rails.application.secrets I get:
{:secret_key_base=>nil, :secret_token=>nil}
and if I run Rails.application.credentials I do in fact see my secret_key_base.
However, locally... if I run the same commands, I DO see secret_key_base when calling Rails.application.secrets.
My main concern is that rails is going to have an empty secret_key_base in production which would be used to encrypt sessions and all kinds of critically important security things. I'm trying to verify that it actually does have the key set.
I'd love a way to 100% confirm that it's working in production, and that it's not blank. Is there some method I can call to check which doesn't rely on calling it via the methods above?
The SECRET_KEY_BASE is stored as an environment variable on Heroku. You can either view these in the interface by going to the settings for that dyno or you can do it in the terminal:
heroku run bash
then
env | grep SECRET_KEY_BASE
If you do not see it there may be an issue but you can generate a new one for Heroku and set it in the environment variables (see Rails.application.key_generator)
I am coming in late to add some functionality to an already existing app hosted on heroku. The original builder has given me access and I 'heroku git:clone -a app-name' to my local computer.
I've found some conflicting instructions on how to set up a staging environment for this site. I don't want to push to the original site but want a way to try out functionality.
If anyone has had experience with staging and heroku, I'd appreciate any clarification.
You'll need to create a staging.rb file in config/environments. You can copy development.rb or production.rb and adjust whatever values you need.
Heroku will handle configuring the database configuration and such. You can clone an app in Heroku or just create a new one, then set it's RAILS_ENV and RACK_ENV environment variables to staging, and push to it.
Please refer: Heroku - Managing Multiple Environments for an App
You Need to create a second Heroku application that hosts your staging application.
Follow the instructions provided in the link for working with multiple environment in heroku.
I have an app up and running on heroku connected to it's own database, however i have a database in my own server which is free and I want to connect my app to it, I changed my Gemfile accordingly but it seems to just ignore it.
I tried
heroku config:add DATABASE_URL=url
but it said he couldn't replace the existing DATABASE_URL...
You can either do this via the command line by first removing and then adding the variable:
heroku config:remove DATABASE_URL
heroku config:add DATABASE_URL=http://someurl.com
or you can do this via the heroku dashboard.
Select your app
Go to Settings
Reveal config variables
Change your DATABASE_URL
I have an ajax call that relies on an API key as part of the request URL. I am using dotenv to hide that key. It works fine when I run it locally, but once deployed on Heroku, it gives me back a:
Uncaught TypeError: Cannot read property '________' of null
It looks as though it's returning null back (but it's totally fine in development). I'm wondering if I have to change any of the settings relating to dotenv when pushing up to Heroku / for production?
Thanks!
I am assuming you are referring to the file named .env as dotenv. Every variable in that file that you need on Heroku must be defined in Heroku config vars : https://devcenter.heroku.com/articles/config-vars
The .env file is an easy way to replicate the Heroku config vars locally. That way your code is prepared to read configuration data from config vars. For code running on Heroku you need to set the heroku config vars.