add EnviromentConfiguration to keep track of heroku specfic enviroment hacks
This commit is contained in:
parent
7841d02edd
commit
a7d59ce115
11 changed files with 84 additions and 22 deletions
|
|
@ -1,2 +1,5 @@
|
||||||
features
|
features
|
||||||
spec
|
spec
|
||||||
|
tmp
|
||||||
|
log
|
||||||
|
public/uploads
|
||||||
1
Gemfile
1
Gemfile
|
|
@ -46,6 +46,7 @@ end
|
||||||
# configuration
|
# configuration
|
||||||
|
|
||||||
gem 'settingslogic', '2.0.6'
|
gem 'settingslogic', '2.0.6'
|
||||||
|
gem 'heroku'
|
||||||
|
|
||||||
# database
|
# database
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -208,6 +208,11 @@ GEM
|
||||||
json (>= 1.4.6)
|
json (>= 1.4.6)
|
||||||
haml (3.1.4)
|
haml (3.1.4)
|
||||||
hashie (1.2.0)
|
hashie (1.2.0)
|
||||||
|
heroku (2.16.2)
|
||||||
|
launchy (>= 0.3.2)
|
||||||
|
rest-client (~> 1.6.1)
|
||||||
|
rubyzip
|
||||||
|
term-ansicolor (~> 1.0.5)
|
||||||
highline (1.6.8)
|
highline (1.6.8)
|
||||||
hoptoad_notifier (2.4.11)
|
hoptoad_notifier (2.4.11)
|
||||||
activesupport
|
activesupport
|
||||||
|
|
@ -232,6 +237,7 @@ GEM
|
||||||
multi_json
|
multi_json
|
||||||
jwt (0.1.3)
|
jwt (0.1.3)
|
||||||
json (>= 1.2.4)
|
json (>= 1.2.4)
|
||||||
|
launchy (2.0.3)
|
||||||
linecache (0.46)
|
linecache (0.46)
|
||||||
rbx-require-relative (> 0.0.4)
|
rbx-require-relative (> 0.0.4)
|
||||||
linecache19 (0.5.12)
|
linecache19 (0.5.12)
|
||||||
|
|
@ -471,6 +477,7 @@ DEPENDENCIES
|
||||||
foreman
|
foreman
|
||||||
fuubar (= 0.0.6)
|
fuubar (= 0.0.6)
|
||||||
haml (= 3.1.4)
|
haml (= 3.1.4)
|
||||||
|
heroku
|
||||||
hoptoad_notifier
|
hoptoad_notifier
|
||||||
http_accept_language!
|
http_accept_language!
|
||||||
i18n-inflector-rails (~> 1.0)
|
i18n-inflector-rails (~> 1.0)
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ class AppConfig < Settingslogic
|
||||||
namespace Rails.env
|
namespace Rails.env
|
||||||
|
|
||||||
def self.load!
|
def self.load!
|
||||||
unless ENV["HEROKU"]
|
unless EnviromentConfiguration.heroku?
|
||||||
if no_config_file? && !have_old_config_file?
|
if no_config_file? && !have_old_config_file?
|
||||||
$stderr.puts <<-HELP
|
$stderr.puts <<-HELP
|
||||||
******** You haven't set up your Diaspora settings file. **********
|
******** You haven't set up your Diaspora settings file. **********
|
||||||
|
|
@ -52,7 +52,7 @@ Please do the following:
|
||||||
Process.exit(1)
|
Process.exit(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
if !ENV["HEROKU"] && no_cert_file_in_prod?
|
if !EnviromentConfiguration.heroku? && no_cert_file_in_prod?
|
||||||
$stderr.puts <<-HELP
|
$stderr.puts <<-HELP
|
||||||
******** Diaspora does not know where your SSL-CA-Certificates file is. **********
|
******** Diaspora does not know where your SSL-CA-Certificates file is. **********
|
||||||
Please add the root certificate bundle (this is operating system specific) to application.yml. Defaults:
|
Please add the root certificate bundle (this is operating system specific) to application.yml. Defaults:
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1 @@
|
||||||
unless File.exists?( File.join(Rails.root, 'config', 'initializers', 'secret_token.rb'))
|
EnviromentConfiguration.ensure_secret_token!
|
||||||
`rake generate:secret_token`
|
|
||||||
require File.join(Rails.root, 'config', 'initializers', 'secret_token.rb')
|
|
||||||
end
|
|
||||||
|
|
@ -3,8 +3,8 @@
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
options = {:timeout => 5}
|
options = {:timeout => 5}
|
||||||
|
|
||||||
options[:ssl] = {:ca_file => AppConfig[:ca_file]} unless ENV['HEROKU']
|
options[:ssl] = {:ca_file => EnviromentConfiguration.ca_cert_file_location}
|
||||||
Faraday.default_connection = Faraday::Connection.new(options ) do |b|
|
Faraday.default_connection = Faraday::Connection.new(options) do |b|
|
||||||
b.use FaradayStack::FollowRedirects
|
b.use FaradayStack::FollowRedirects
|
||||||
b.adapter Faraday.default_adapter
|
b.adapter Faraday.default_adapter
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ if AppConfig[:featured_users].present? && AppConfig[:community_spotlight].blank?
|
||||||
puts "DEPRICATION WARNING (10/21/11): Please change `featured_users` in your application.yml to `community_spotlight`. Thanks!"
|
puts "DEPRICATION WARNING (10/21/11): Please change `featured_users` in your application.yml to `community_spotlight`. Thanks!"
|
||||||
end
|
end
|
||||||
|
|
||||||
unless !ActiveRecord::Base.connection.table_exists?('people') || Rails.env == 'test' || AppConfig[:community_spotlight].nil? || AppConfig[:community_spotlight].count == Person.community_spotlight.count
|
unless EnviromentConfiguration.prevent_fetching_community_spotlight?
|
||||||
print "Fetching community spotlight users from remote servers"
|
print "Fetching community spotlight users from remote servers"
|
||||||
AppConfig[:community_spotlight].each do |x|
|
AppConfig[:community_spotlight].each do |x|
|
||||||
Webfinger.new(x).fetch
|
Webfinger.new(x).fetch
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,11 @@
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
|
|
||||||
git_cmd = `git log -1 --pretty="format:%H %ci"`
|
if EnviromentConfiguration.cache_git_version?
|
||||||
if git_cmd =~ /^([\d\w]+?)\s(.+)$/
|
git_cmd = `git log -1 --pretty="format:%H %ci"`
|
||||||
AppConfig[:git_revision] = $1
|
if git_cmd =~ /^([\d\w]+?)\s(.+)$/
|
||||||
AppConfig[:git_update] = $2.strip
|
AppConfig[:git_revision] = $1
|
||||||
ENV["RAILS_ASSET_ID"] = AppConfig[:git_revision][0..8] if Rails.env.production?
|
AppConfig[:git_update] = $2.strip
|
||||||
|
ENV["RAILS_ASSET_ID"] = AppConfig[:git_revision][0..8] if Rails.env.production?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
38
lib/enviroment_configuration.rb
Normal file
38
lib/enviroment_configuration.rb
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
module EnviromentConfiguration
|
||||||
|
def self.heroku?
|
||||||
|
ENV['HEROKU']
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.secret_token_initializer_is_not_present?
|
||||||
|
!File.exists?( File.join(Rails.root, 'config', 'initializers', 'secret_token.rb'))
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.prevent_fetching_community_spotlight?
|
||||||
|
return true if heroku?
|
||||||
|
!ActiveRecord::Base.connection.table_exists?('people') || Rails.env == 'test' || AppConfig[:community_spotlight].nil? || AppConfig[:community_spotlight].count
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.cache_git_version?
|
||||||
|
!self.heroku?
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.ensure_secret_token!
|
||||||
|
if heroku?
|
||||||
|
puts 'heroku app detected; using session secret from config vars...'
|
||||||
|
Rails.application.config.secret_token = ENV['SECRET_TOKEN']
|
||||||
|
elsif secret_token_initializer_is_not_present?
|
||||||
|
`rake generate:secret_token`
|
||||||
|
require File.join(Rails.root, 'config', 'initializers', 'secret_token.rb')
|
||||||
|
else
|
||||||
|
#do nothing
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.ca_cert_file_location
|
||||||
|
if self.heroku?
|
||||||
|
"/usr/lib/ssl/certs/ca-certificates.crt"
|
||||||
|
else
|
||||||
|
AppConfig[:ca_file]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -1,11 +1,20 @@
|
||||||
namespace :heroku do
|
namespace :heroku do
|
||||||
|
HEROKU_CONFIG_ADD_COMMAND = "heroku config:add HEROKU=true"
|
||||||
|
|
||||||
task :config do
|
task :config do
|
||||||
puts "Reading config/application.yml and sending config vars to Heroku..."
|
puts "Reading config/application.yml and sending config vars to Heroku..."
|
||||||
CONFIG = YAML.load_file('config/application.yml')['production'] rescue {}
|
application_config = YAML.load_file('config/application.yml')['production'] rescue {}
|
||||||
command = "heroku config:add"
|
application_config.delete_if { |k, v| v.blank? }
|
||||||
CONFIG.each {|key, val| command << " #{key}=#{val} " if val }
|
|
||||||
command << " HEROKU=true "
|
heroku_env = application_config.map{|k, v| "#{k}=#{v}"}.join(' ')
|
||||||
command << " DB=postgres "
|
|
||||||
system command
|
puts "Generating and setting a new secret token"
|
||||||
|
token = ActiveSupport::SecureRandom.hex(40)#reloads secret token every time you reload vars.... this expires cookies, and kinda sucks
|
||||||
|
system "#{HEROKU_CONFIG_ADD_COMMAND} #{heroku_env} SECRET_TOKEN=#{token}"
|
||||||
|
end
|
||||||
|
|
||||||
|
task :install_requirements do
|
||||||
|
system 'heroku addons:add lgging:expanded'
|
||||||
|
system 'heroku addons:add redistogo:nano'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,12 @@ begin
|
||||||
|
|
||||||
task :stats => "spec:statsetup"
|
task :stats => "spec:statsetup"
|
||||||
|
|
||||||
Rake::Task[:spec].clear
|
#heroku barfs here :/
|
||||||
|
begin
|
||||||
|
Rake::Task[:spec].clear
|
||||||
|
rescue
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
desc "Run all specs in spec directory"
|
desc "Run all specs in spec directory"
|
||||||
RSpec::Core::RakeTask.new(:spec => spec_prereq)
|
RSpec::Core::RakeTask.new(:spec => spec_prereq)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue