I am a rails developer and trying to get familiar with Heroku.
I don't add config/environment.rb to git as environment.rb might be different for each environment.
For example, ENV['RAILS_ENV'] = 'some_env' should be in environment.rb.
However, Heroku requires environment.rb to be in git so that I can push it to Heroku.
Is there a way to just copy environment.rb to Heroku without version-controlling it?
Thanks.
Sam
You always want to keep the environment.rb file checked in. You can set the environment using config variables
heroku config:add RAILS_ENV=some_env
So you store your config with each individual app. You can read any config variables from your application by using ENV[]
Related
I get this error, when running "heroku open"
"Internal Server Error
You must set config.secret_key_base in your app's config."
I've tried everything in this thread:
Heroku Config Secret Key Base Error
Set MyApp::Application.config.secret_token = ENV['SECRET_TOKEN'] in config/initializers/secret_token.rb
Created a .env file with the contents SECRET_TOKEN=NKUd7gisd7fueAISDfg....
Updated my .gitignore file to look like below
What else I have tried:
I added: DemoApp::Application.config.secret_key_base = ENV['SECRET_TOKEN'] to secret_token.rb file
Used figaro to create a application.yml file and pasted SECRET_TOKEN: 9489b3eee4eccf317ed77407553e8adc97baca7c74dc7ee33cd93e4c8b69477eea66eaedeb18af0be2679887c7c69c0a28c0fded0a71ea472a8c4abf3f0a19cb with my own SECRET_TOKEN
ran rake figaro:heroku
I still get the internal server error. Apologies if this is a total nub question, but this is my first try with the "heroku open" command.
Thanks,
David
Ok from heroku staff help turns out that my config/initializers folder was not pushing up to git.
Then these two posts solved it:
Config/initializers not pushing to repo
No submodule mapping found in .gitmodules for path
Best of luck
To set environment variables on Heroku, you need to use the Heroku Toolbelt from on local machine:
heroku config:set SECRET_TOKEN=f489b3eee4eccf317ed77407553e8adc97baca7c74dc7ee33cd93e4c8b69477eea66eaedeb18af0be2679887c7c69c0a28c0fded0a71ea472a8c4abf3f0a19ca
(Obviously, replace the token above with your own)
Then just make sure that you have MyApp::Application.config.secret_token = ENV['SECRET_TOKEN'] in your config/initializers/secret_token.rb file.
See Setting up config vars for a deployed application for further info.
Also make sure that you've added a secret_key_base entry for the production environment in your config/secrets.yml file:
production:
secret_key_base: 527dacc0390e10df59278f1a18aa8ad14e429fa6ce522e5fb3b7ac358007dff4
Don't use the key posted here. You can generate a new one with a rake task and paste it into your config/secrets.yml file
bundle exec rake secrets
Rails 4.1.0.beta1 and Devise.
I'm trying to remove all of my keys from version control and I've upgraded to Rails 4.1 to give this new secrets.yml a shot
Trying to push Devise's config.secret_key to heroku but it's failing after assets:precompile
Preparing app for Rails asset pipeline
Running: rake assets:precompile
rake aborted!
Devise.secret_key was not set. Please add the following to your Devise initializer:
config.secret_key = 'EXAMPLE_KEY_HERE'
Please ensure you restarted your application after installing Devise or setting the key.
Here are my changes, the old code I'll leave in comments. (it works)
devise.rb
# config.secret_key = 'THIS_IS_A_FAKE_KEY' #<---this_is_commented_out
config.secret_key = Rails.application.secrets.devise_secret_key
secrets.yml
production:
devise_secret_key: 'THIS_IS_A_FAKE_KEY'
then ran heroku labs:enable user-env-compile -a myapp (not sure if that's necessary)
and then when I push to my forked heroku envionment git push forked master I get the above error.
I also noticed some discussion on this in this Devise repo so I figured I'd update my gem alongside the source repo, no difference. Here's part of that discussion (here).
You've likely got secrets.yml added to your .gitignore. Which makes sense, since you put secret keys in it -- but since Heroku deployment uses git, it never sees your secrets.yml.
One solution is to use the heroku_secrets gem - See https://stackoverflow.com/a/22458102/2831572 .
Another solution is to add secrets.yml to git (i.e. remove it from .gitignore) after replacing all sensitive keys with references to environment variables.
So:
production:
devise_secret_key: <%= ENV['DEVISE_KEY'] %>
then run heroku config:set DEVISE_KEY='7658699e0f765e8whatever'
I am updating heroku config through my rails application.
Like-
def add_to_heroku_config
Rails.logger.debug "Executing: #{ self.name.capitalize }=#{ self.database_string }"
Bundler.with_clean_env { system("heroku config:set #{ self.name.capitalize }=#{ self.database_string }") }
end
Now this works from local machine, when i deploy it on heroku, obivously it is not going to work.
Now Is it possible to update/add ENV variables from the application running on heroku itself ?
I'm using the Figaro gem for this, allowing you to set the environment variables on Heroku, using a .yml file. Figaro contains a rake task doing exactly what you're asking, without making the environment variables "accessible" on the server, obviously for security reasons, by adding the .yml file to .gitignore
See https://github.com/laserlemon/figaro
There is a problem while running the application in production mode. I want to set as default to run it as production.
RAILS_ENV="production"
I added above line in application.rb but no luck.
Any idea how to make it possible. When I am uploading app to heroku it still runs in development, due to which I am not able to keep my databases separate.
The application.rb is not the best place to define environment variables. On Heroku, you can define RAILS_ENV with heroku config:add RAILS_ENV=production
Adding RAILS_ENV="production" to application.rb wont help. Read the Heroku documentation on getting started.
This is a bit tricky because Heroku uses a Read-only Filesystem across their Dyno Grid.
Which means when trying to install ckeditor remotely, I get an error :
heroku rake db:migrate
rake aborted!
Read-only file system - /disk1/home/slugs/362142_8858805_b85c-f2f3955d-f087-4bc4-8b1b-b6e898403a10/mnt/public/javascripts/ckcustom.js
ckcustom.js is a config file to manage your meta settings for ckeditor. I was wondering if anyone else had these troubles, and what they did to get around them?
Is there a reason why you're not just committing it to git and pushing it to heroku along with the rest of your source? I've never had to configure CKeditor with heroku, but that ought to work AFAIK.
The reason this error occured was because Heroku ran on my production environment. Because CKEditor is being set up on a new environment, it attempts to write a bunch of files. Because Heroku is a read-only file system it aborts this process. In order to bypass this error :
On your local machine, perform this :
rails s -e production
View your site, CKeditor will write those files for production env.
git add .
git commit -m "added files to Production for Heroku"
git push heroku master
It should now!
A cheap way to do it is to go to easy_ckeditor/init.rb and comment out the check_and_install:
#require 'ckeditor_file_utils'
#CkeditorFileUtils.check_and_install
The solution that worked for me was the following:
Make sure to
bundle update ckeditor
and then, add these lines to config/application.rb
config.assets.precompile += Ckeditor.assets
config.assets.precompile += %w( ckeditor/* )
config.autoload_paths += %W(#{config.root}/app/models/ckeditor)
This was answered in this other stack overflow thread: Problems with ckeditor running on production Rails application with Heroku