Merge branch 'heroku'

This commit is contained in:
danielgrippi 2011-09-14 18:22:19 -07:00
commit d3720faa08
10 changed files with 73 additions and 35 deletions

2
.slugignore Normal file
View file

@ -0,0 +1,2 @@
features
spec

View file

@ -4,6 +4,7 @@ gem 'rails', '3.0.10'
gem 'bundler', '>= 1.0.0'
gem 'foreman'
gem 'heroku'
gem 'thin', '1.2.11', :require => false

View file

@ -209,6 +209,11 @@ GEM
json (>= 1.4.6)
haml (3.1.2)
hashie (1.0.0)
heroku (2.6.1)
launchy (>= 0.3.2)
rest-client (~> 1.6.1)
rubyzip
term-ansicolor (~> 1.0.5)
highline (1.6.2)
hoptoad_notifier (2.4.11)
activesupport
@ -237,6 +242,7 @@ GEM
json (>= 1.2.4)
kaminari (0.12.4)
rails (>= 3.0.0)
launchy (2.0.3)
linecache (0.43)
linecache19 (0.5.12)
ruby_core_source (>= 0.1.4)
@ -493,6 +499,7 @@ DEPENDENCIES
foreman
fuubar
haml (= 3.1.2)
heroku
hoptoad_notifier
http_accept_language!
i18n-inflector-rails (~> 1.0)

View file

@ -1,4 +1,4 @@
web: bundle exec rails s thin -p $PORT
redis: redis-server
websocket: ruby script/websocket_server.rb
worker: QUEUE=* rake resque:work
worker: QUEUE=* bundle exec rake resque:work

View file

@ -6,7 +6,7 @@ require 'uri'
class AppConfig < Settingslogic
def self.source_file_name
if Rails.env == 'test' || ENV["CI"] || Rails.env.include?("integration")
if Rails.env == 'test' || ENV["CI"] || Rails.env.include?("integration") || ENV["HEROKU"]
File.join(Rails.root, "config", "application.yml.example")
else
File.join(Rails.root, "config", "application.yml")
@ -16,8 +16,9 @@ class AppConfig < Settingslogic
namespace Rails.env
def self.load!
if no_config_file? && !have_old_config_file?
$stderr.puts <<-HELP
unless ENV["HEROKU"]
if no_config_file? && !have_old_config_file?
$stderr.puts <<-HELP
******** You haven't set up your Diaspora settings file. **********
Please do the following:
1. Copy config/application.yml.example to config/application.yml.
@ -25,12 +26,12 @@ Please do the following:
work without modification. However, it's always good to know what's available to change later.
3. Restart Diaspora!
******** Thanks for being an alpha tester! **********
HELP
Process.exit(1)
end
HELP
Process.exit(1)
end
if (no_config_file? && have_old_config_file?) || config_file_is_old_style?
$stderr.puts <<-HELP
if ((no_config_file? && have_old_config_file?) || config_file_is_old_style?)
$stderr.puts <<-HELP
******** The Diaspora configuration file format has changed. **********
Please do the following:
1. Copy config/application.yml.example to config/application.yml.
@ -38,8 +39,9 @@ Please do the following:
3. Delete config/app.yml and config/app_config.yml. Don't worry if they don't exist, though.
4. Restart Diaspora!
******** Thanks for being an alpha tester! **********
HELP
Process.exit(1)
HELP
Process.exit(1)
end
end
begin
@ -50,7 +52,7 @@ HELP
Process.exit(1)
end
if no_cert_file_in_prod?
if !ENV["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:
@ -115,6 +117,7 @@ HELP
def self.[] (key)
return self.pod_uri if key == :pod_uri
return ENV[key.to_s] if ENV[key.to_s].present? && ENV["HEROKU"]
super
end
@ -131,9 +134,9 @@ HELP
def self.pod_uri
if @@pod_uri.nil?
begin
@@pod_uri = Addressable::URI.parse(self.pod_url)
@@pod_uri = Addressable::URI.parse(self[:pod_url])
rescue
puts "WARNING: pod url " + self.pod_url + " is not a legal URI"
puts "WARNING: pod url " + self[:pod_url] + " is not a legal URI"
end
end
return @@pod_uri

View file

@ -1,8 +1,10 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
options = {:timeout => 5}
Faraday.default_connection = Faraday::Connection.new( :ssl => {:ca_file => AppConfig[:ca_file]}, :timeout => 5 ) do |b|
options[:ssl] = {:ca_file => AppConfig[:ca_file]} unless ENV['HEROKU']
Faraday.default_connection = Faraday::Connection.new(options ) do |b|
b.use FaradayStack::FollowRedirects
b.adapter Faraday.default_adapter
end

View file

@ -2,22 +2,26 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
s = `git show --name-only 2>/dev/null || :`
if (s.nil? or s.empty?)
path = File.expand_path("config/gitversion")
begin
if (File.exists?( path))
s = ''
f = File.open( path)
f.each_line do |line|
s += line
end
f.close
end
rescue
s = ""
end
unless ENV['HEROKU']
s = `git show --name-only 2>/dev/null || :`
if (s.nil? or s.empty?)
path = File.expand_path("config/gitversion")
begin
if (File.exists?( path))
s = ''
f = File.open( path)
f.each_line do |line|
s += line
end
f.close
end
rescue
s = ""
end
end
GIT_INFO = s
# What's the scope of this s? Leave to GC just in case...
s = nil
else
GIT_INFO = nil
end
GIT_INFO = s
# What's the scope of this s? Leave to GC just in case...
s = nil

View file

@ -2,8 +2,13 @@ require 'resque'
Resque::Plugins::Timeout.timeout = 120
if !AppConfig.single_process_mode? && AppConfig[:redis_url]
Resque.redis = Redis.new(:host => AppConfig[:redis_url], :port => 6379)
if !AppConfig.single_process_mode?
if redis_to_go = ENV["REDISTOGO_URL"]
uri = URI.parse(redis_to_go)
Resque.redis = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
elsif AppConfig[:redis_url]
Resque.redis = Redis.new(:host => AppConfig[:redis_url], :port => 6379)
end
end
if AppConfig.single_process_mode?

10
lib/tasks/heroku.rake Normal file
View file

@ -0,0 +1,10 @@
namespace :heroku do
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 "
system command
end
end

View file

@ -1,5 +1,9 @@
require 'resque/tasks'
task "resque:setup" do
require File.join(File.dirname(__FILE__), '..', '..', 'config', 'environment')
Rails.logger.info("event=resque_setup rails_env=#{Rails.env}")
end
desc "Alias for resque:work (To run workers on Heroku)"
task "jobs:work" => "resque:work"