From f55a0867525be83f89011ab20109fe3222b33975 Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Tue, 30 Aug 2011 11:32:56 -0700 Subject: [PATCH 01/14] edit app+_config to look for heroku's ENV['STACK'] config var; load settings from ENV hash instead of application.yml if on heroku --- app/models/app_config.rb | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/app/models/app_config.rb b/app/models/app_config.rb index c4b626461..cbb53fbd4 100644 --- a/app/models/app_config.rb +++ b/app/models/app_config.rb @@ -6,6 +6,8 @@ require 'uri' class AppConfig < Settingslogic def self.source_file_name + return ENV.to_hash if ENV["STACK"] # Using Heroku + if Rails.env == 'test' || ENV["CI"] || Rails.env.include?("integration") File.join(Rails.root, "config", "application.yml.example") else @@ -16,8 +18,9 @@ class AppConfig < Settingslogic namespace Rails.env def self.load! - if no_config_file? && !have_old_config_file? - $stderr.puts <<-HELP + unless ENV["STACK"] + 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 +28,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 +41,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 +54,7 @@ HELP Process.exit(1) end - if no_cert_file_in_prod? + if !ENV["STACK"] && 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: From ba63c028e6453dd2d45cdad398ecbbf4dea6682d Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Tue, 30 Aug 2011 11:39:42 -0700 Subject: [PATCH 02/14] added heroku gem, slugignore, and heroku rake task to load application.yml vars as config vars --- .slugignore | 2 ++ Gemfile | 1 + Gemfile.lock | 6 ++++++ lib/tasks/heroku.rake | 9 +++++++++ 4 files changed, 18 insertions(+) create mode 100644 .slugignore create mode 100644 lib/tasks/heroku.rake diff --git a/.slugignore b/.slugignore new file mode 100644 index 000000000..6d68cf7fe --- /dev/null +++ b/.slugignore @@ -0,0 +1,2 @@ +features +spec diff --git a/Gemfile b/Gemfile index 80c1f53b3..04031070e 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/Gemfile.lock b/Gemfile.lock index 5428faa43..493fcc31e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 @@ -493,6 +498,7 @@ DEPENDENCIES foreman fuubar haml (= 3.1.2) + heroku hoptoad_notifier http_accept_language! i18n-inflector-rails (~> 1.0) diff --git a/lib/tasks/heroku.rake b/lib/tasks/heroku.rake new file mode 100644 index 000000000..9abe40533 --- /dev/null +++ b/lib/tasks/heroku.rake @@ -0,0 +1,9 @@ +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 } + system command + end +end From 57079ef5cd5de1a01707a58b82a129adb13b6418 Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Tue, 30 Aug 2011 14:38:21 -0700 Subject: [PATCH 03/14] set ENV['HEROKU'] explicitly in the heroku:config task --- app/models/app_config.rb | 6 +++--- lib/tasks/heroku.rake | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/models/app_config.rb b/app/models/app_config.rb index cbb53fbd4..ba3afc2d4 100644 --- a/app/models/app_config.rb +++ b/app/models/app_config.rb @@ -6,7 +6,7 @@ require 'uri' class AppConfig < Settingslogic def self.source_file_name - return ENV.to_hash if ENV["STACK"] # Using Heroku + return ENV.to_hash if ENV["HEROKU"] # Using Heroku if Rails.env == 'test' || ENV["CI"] || Rails.env.include?("integration") File.join(Rails.root, "config", "application.yml.example") @@ -18,7 +18,7 @@ class AppConfig < Settingslogic namespace Rails.env def self.load! - unless ENV["STACK"] + unless ENV["HEROKU"] if no_config_file? && !have_old_config_file? $stderr.puts <<-HELP ******** You haven't set up your Diaspora settings file. ********** @@ -54,7 +54,7 @@ Please do the following: Process.exit(1) end - if !ENV["STACK"] && 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: diff --git a/lib/tasks/heroku.rake b/lib/tasks/heroku.rake index 9abe40533..741b456cd 100644 --- a/lib/tasks/heroku.rake +++ b/lib/tasks/heroku.rake @@ -4,6 +4,7 @@ namespace :heroku do 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 From 2f9ea6cd43d97809760bc15c1b77a019552b1b5b Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Tue, 30 Aug 2011 15:03:39 -0700 Subject: [PATCH 04/14] try accessing env var if present in app_config --- app/models/app_config.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/models/app_config.rb b/app/models/app_config.rb index ba3afc2d4..148c1ba7d 100644 --- a/app/models/app_config.rb +++ b/app/models/app_config.rb @@ -6,9 +6,7 @@ require 'uri' class AppConfig < Settingslogic def self.source_file_name - return ENV.to_hash if ENV["HEROKU"] # Using Heroku - - if Rails.env == 'test' || ENV["CI"] || Rails.env.include?("integration") + if Rails.env == 'test' || ENV["CI"] || Rails.env.include?("integration") || ENV["HEROKU"].present? File.join(Rails.root, "config", "application.yml.example") else File.join(Rails.root, "config", "application.yml") @@ -18,7 +16,7 @@ class AppConfig < Settingslogic namespace Rails.env def self.load! - unless ENV["HEROKU"] + unless ENV["HEROKU"].present? if no_config_file? && !have_old_config_file? $stderr.puts <<-HELP ******** You haven't set up your Diaspora settings file. ********** @@ -54,7 +52,7 @@ Please do the following: Process.exit(1) end - if !ENV["HEROKU"] && no_cert_file_in_prod? + if !ENV["HEROKU"].present? && 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: @@ -119,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 From c1b46e557f0df2a72e04bc5183b8f78d560d4912 Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Tue, 30 Aug 2011 16:58:36 -0700 Subject: [PATCH 05/14] added redis to go support in redis --- config/initializers/resque.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/config/initializers/resque.rb b/config/initializers/resque.rb index f1202f72c..eb2ca2856 100644 --- a/config/initializers/resque.rb +++ b/config/initializers/resque.rb @@ -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? From 084ed0e8385ccbd3b1dc98dd3ac51600fb6b3e1e Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Tue, 30 Aug 2011 17:16:51 -0700 Subject: [PATCH 06/14] dont tell faraday to get a custom ca file, hopefully heroku does magic to make sure they work --- config/initializers/faraday.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/config/initializers/faraday.rb b/config/initializers/faraday.rb index 4488fa1ee..1d4a5454e 100644 --- a/config/initializers/faraday.rb +++ b/config/initializers/faraday.rb @@ -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 From 4da94254804b12b6833ce0b83c53f6a9fb37fc25 Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Tue, 30 Aug 2011 17:41:46 -0700 Subject: [PATCH 07/14] fix pod_uri bug in app_config --- app/models/app_config.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/models/app_config.rb b/app/models/app_config.rb index 148c1ba7d..e31e4dbb7 100644 --- a/app/models/app_config.rb +++ b/app/models/app_config.rb @@ -6,7 +6,7 @@ require 'uri' class AppConfig < Settingslogic def self.source_file_name - if Rails.env == 'test' || ENV["CI"] || Rails.env.include?("integration") || ENV["HEROKU"].present? + 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,7 +16,7 @@ class AppConfig < Settingslogic namespace Rails.env def self.load! - unless ENV["HEROKU"].present? + unless ENV["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"].present? && 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: @@ -134,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 From e0bdbef2811027c611bcb91e404dc1a73e08d2d4 Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Tue, 30 Aug 2011 18:03:02 -0700 Subject: [PATCH 08/14] show redis connection --- app/views/layouts/application.html.haml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 6d6e22632..6613909a4 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -97,6 +97,9 @@ %header{:class=>('landing' unless current_user)} = render 'layouts/header' + %h3 + = Resque.redis.inspect + .container{:style=> "#{yield(:break_the_mold)}"} .span-24.last{:style=> "#{yield(:break_the_mold)}"} = yield From 5681062f33e604ae7554660d2c7b0d4290292a32 Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Tue, 30 Aug 2011 18:13:49 -0700 Subject: [PATCH 09/14] add 'bundle exec' to worker process --- Procfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Procfile b/Procfile index b44eb8898..8e97aa04d 100644 --- a/Procfile +++ b/Procfile @@ -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 From b3534ed5f4b47d56564c2ad81968140e8c15cd6a Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Tue, 30 Aug 2011 21:26:04 -0700 Subject: [PATCH 10/14] Revert "show redis connection" This reverts commit 6a887a6d99899b9876e3145fb0a8b92ce2a405cf. --- app/views/layouts/application.html.haml | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 6613909a4..6d6e22632 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -97,9 +97,6 @@ %header{:class=>('landing' unless current_user)} = render 'layouts/header' - %h3 - = Resque.redis.inspect - .container{:style=> "#{yield(:break_the_mold)}"} .span-24.last{:style=> "#{yield(:break_the_mold)}"} = yield From 3f84dd066f6f0b3e7ca5233ca765b2663f9c9688 Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Tue, 30 Aug 2011 21:51:33 -0700 Subject: [PATCH 11/14] can't access git on heroku --- config/initializers/git_info.rb | 40 ++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/config/initializers/git_info.rb b/config/initializers/git_info.rb index 1b5f24cef..885e3a91b 100644 --- a/config/initializers/git_info.rb +++ b/config/initializers/git_info.rb @@ -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 From a99a174d5fcb40c2407eab768287cdfab42163fb Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Tue, 30 Aug 2011 22:00:04 -0700 Subject: [PATCH 12/14] alias jobs:work --- lib/tasks/resque.rake | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/tasks/resque.rake b/lib/tasks/resque.rake index 9c714ab5d..8b582cbfe 100644 --- a/lib/tasks/resque.rake +++ b/lib/tasks/resque.rake @@ -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" From cb7bc0ecad856ba02b3788031d2c54a7094b63e8 Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Wed, 31 Aug 2011 16:03:59 -0700 Subject: [PATCH 13/14] add debug line --- lib/salmon/salmon.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/salmon/salmon.rb b/lib/salmon/salmon.rb index 20c7c750b..aa0dd4b1d 100644 --- a/lib/salmon/salmon.rb +++ b/lib/salmon/salmon.rb @@ -17,6 +17,7 @@ module Base64 # ArgumentError is raised if +str+ is incorrectly padded or contains # non-alphabet characters. Note that CR or LF are also rejected. def strict_decode64(str) + Rails.logger.info("trying to decode string: " + str) str.unpack("m0").first end From a396ad811f9d036c3ec61f6098c03df9c314e9fd Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Wed, 14 Sep 2011 18:21:54 -0700 Subject: [PATCH 14/14] remove debug line --- Gemfile.lock | 1 + lib/salmon/salmon.rb | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 493fcc31e..0d51d7eaa 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -242,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) diff --git a/lib/salmon/salmon.rb b/lib/salmon/salmon.rb index aa0dd4b1d..20c7c750b 100644 --- a/lib/salmon/salmon.rb +++ b/lib/salmon/salmon.rb @@ -17,7 +17,6 @@ module Base64 # ArgumentError is raised if +str+ is incorrectly padded or contains # non-alphabet characters. Note that CR or LF are also rejected. def strict_decode64(str) - Rails.logger.info("trying to decode string: " + str) str.unpack("m0").first end