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
|
||||
spec
|
||||
tmp
|
||||
log
|
||||
public/uploads
|
||||
1
Gemfile
1
Gemfile
|
|
@ -46,6 +46,7 @@ end
|
|||
# configuration
|
||||
|
||||
gem 'settingslogic', '2.0.6'
|
||||
gem 'heroku'
|
||||
|
||||
# database
|
||||
|
||||
|
|
|
|||
|
|
@ -208,6 +208,11 @@ GEM
|
|||
json (>= 1.4.6)
|
||||
haml (3.1.4)
|
||||
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)
|
||||
hoptoad_notifier (2.4.11)
|
||||
activesupport
|
||||
|
|
@ -232,6 +237,7 @@ GEM
|
|||
multi_json
|
||||
jwt (0.1.3)
|
||||
json (>= 1.2.4)
|
||||
launchy (2.0.3)
|
||||
linecache (0.46)
|
||||
rbx-require-relative (> 0.0.4)
|
||||
linecache19 (0.5.12)
|
||||
|
|
@ -471,6 +477,7 @@ DEPENDENCIES
|
|||
foreman
|
||||
fuubar (= 0.0.6)
|
||||
haml (= 3.1.4)
|
||||
heroku
|
||||
hoptoad_notifier
|
||||
http_accept_language!
|
||||
i18n-inflector-rails (~> 1.0)
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ class AppConfig < Settingslogic
|
|||
namespace Rails.env
|
||||
|
||||
def self.load!
|
||||
unless ENV["HEROKU"]
|
||||
unless EnviromentConfiguration.heroku?
|
||||
if no_config_file? && !have_old_config_file?
|
||||
$stderr.puts <<-HELP
|
||||
******** You haven't set up your Diaspora settings file. **********
|
||||
|
|
@ -52,7 +52,7 @@ Please do the following:
|
|||
Process.exit(1)
|
||||
end
|
||||
|
||||
if !ENV["HEROKU"] && no_cert_file_in_prod?
|
||||
if !EnviromentConfiguration.heroku? && no_cert_file_in_prod?
|
||||
$stderr.puts <<-HELP
|
||||
******** 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:
|
||||
|
|
|
|||
|
|
@ -1,4 +1 @@
|
|||
unless File.exists?( File.join(Rails.root, 'config', 'initializers', 'secret_token.rb'))
|
||||
`rake generate:secret_token`
|
||||
require File.join(Rails.root, 'config', 'initializers', 'secret_token.rb')
|
||||
end
|
||||
EnviromentConfiguration.ensure_secret_token!
|
||||
|
|
@ -3,8 +3,8 @@
|
|||
# the COPYRIGHT file.
|
||||
options = {:timeout => 5}
|
||||
|
||||
options[:ssl] = {:ca_file => AppConfig[:ca_file]} unless ENV['HEROKU']
|
||||
Faraday.default_connection = Faraday::Connection.new(options ) do |b|
|
||||
options[:ssl] = {:ca_file => EnviromentConfiguration.ca_cert_file_location}
|
||||
Faraday.default_connection = Faraday::Connection.new(options) do |b|
|
||||
b.use FaradayStack::FollowRedirects
|
||||
b.adapter Faraday.default_adapter
|
||||
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!"
|
||||
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"
|
||||
AppConfig[:community_spotlight].each do |x|
|
||||
Webfinger.new(x).fetch
|
||||
|
|
|
|||
|
|
@ -3,9 +3,11 @@
|
|||
# the COPYRIGHT file.
|
||||
|
||||
|
||||
git_cmd = `git log -1 --pretty="format:%H %ci"`
|
||||
if git_cmd =~ /^([\d\w]+?)\s(.+)$/
|
||||
AppConfig[:git_revision] = $1
|
||||
AppConfig[:git_update] = $2.strip
|
||||
ENV["RAILS_ASSET_ID"] = AppConfig[:git_revision][0..8] if Rails.env.production?
|
||||
end
|
||||
if EnviromentConfiguration.cache_git_version?
|
||||
git_cmd = `git log -1 --pretty="format:%H %ci"`
|
||||
if git_cmd =~ /^([\d\w]+?)\s(.+)$/
|
||||
AppConfig[:git_revision] = $1
|
||||
AppConfig[:git_update] = $2.strip
|
||||
ENV["RAILS_ASSET_ID"] = AppConfig[:git_revision][0..8] if Rails.env.production?
|
||||
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
|
||||
HEROKU_CONFIG_ADD_COMMAND = "heroku config:add HEROKU=true"
|
||||
|
||||
task :config do
|
||||
puts "Reading config/application.yml and sending config vars to Heroku..."
|
||||
CONFIG = YAML.load_file('config/application.yml')['production'] rescue {}
|
||||
command = "heroku config:add"
|
||||
CONFIG.each {|key, val| command << " #{key}=#{val} " if val }
|
||||
command << " HEROKU=true "
|
||||
command << " DB=postgres "
|
||||
system command
|
||||
application_config = YAML.load_file('config/application.yml')['production'] rescue {}
|
||||
application_config.delete_if { |k, v| v.blank? }
|
||||
|
||||
heroku_env = application_config.map{|k, v| "#{k}=#{v}"}.join(' ')
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -12,7 +12,12 @@ begin
|
|||
|
||||
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"
|
||||
RSpec::Core::RakeTask.new(:spec => spec_prereq)
|
||||
|
|
|
|||
Loading…
Reference in a new issue