Explorar el Código

Gemfile trickery for Heroku

Andrew Cantino hace 10 años
padre
commit
e21c859dfc
Se han modificado 3 ficheros con 37 adiciones y 16 borrados
  1. 8 1
      Gemfile
  2. 15 0
      Gemfile.lock
  3. 14 15
      bin/setup_heroku

+ 8 - 1
Gemfile

@@ -100,9 +100,16 @@ group :production do
   gem 'rack'
 end
 
+# This hack needs some explanation.  When on Heroku in production, use the pg, unicorn, and rails12factor gems.
+# When not on Heroku, we still want our Gemfile.lock to include these gems, so we scope them to
+# an unsupported platform.
 if ENV['ON_HEROKU'] || ENV['HEROKU_POSTGRESQL_ROSE_URL']
   gem 'pg', group: :production
-  gem 'unicorn', groups: [:development, :production]
+  gem 'unicorn', group: :production
   gem 'rails_12factor', group: :production
+else
+  gem 'pg', platform: :ruby_18
+  gem 'unicorn', platform: :ruby_18
+  gem 'rails_12factor', platform: :ruby_18
 end
 

+ 15 - 0
Gemfile.lock

@@ -161,6 +161,7 @@ GEM
     kaminari (0.16.1)
       actionpack (>= 3.0.0)
       activesupport (>= 3.0.0)
+    kgio (2.9.2)
     kramdown (1.3.3)
     launchy (2.4.2)
       addressable (~> 2.3)
@@ -192,6 +193,7 @@ GEM
       multi_xml (~> 0.5)
       rack (~> 1.2)
     orm_adapter (0.5.0)
+    pg (0.17.1)
     polyglot (0.3.5)
     protected_attributes (1.0.8)
       activemodel (>= 4.0.1, < 5.0)
@@ -214,11 +216,17 @@ GEM
       bundler (>= 1.3.0, < 2.0)
       railties (= 4.1.4)
       sprockets-rails (~> 2.0)
+    rails_12factor (0.0.2)
+      rails_serve_static_assets
+      rails_stdout_logging
+    rails_serve_static_assets (0.0.2)
+    rails_stdout_logging (0.0.3)
     railties (4.1.4)
       actionpack (= 4.1.4)
       activesupport (= 4.1.4)
       rake (>= 0.8.7)
       thor (>= 0.18.1, < 2.0)
+    raindrops (0.13.0)
     rake (10.3.2)
     ref (1.0.5)
     rest-client (1.6.7)
@@ -317,6 +325,10 @@ GEM
     uglifier (2.5.1)
       execjs (>= 0.3.0)
       json (>= 1.8.0)
+    unicorn (4.8.3)
+      kgio (~> 2.6)
+      rack
+      raindrops (~> 0.7)
     uuid (2.3.7)
       macaddr (~> 1.0)
     uuidtools (2.1.4)
@@ -374,11 +386,13 @@ DEPENDENCIES
   mqtt
   mysql2 (~> 0.3.16)
   nokogiri (~> 1.6.1)
+  pg
   protected_attributes (~> 1.0.8)
   pry
   quiet_assets
   rack
   rails (= 4.1.4)
+  rails_12factor
   rr
   rspec (~> 2.14)
   rspec-rails (~> 2.14)
@@ -395,6 +409,7 @@ DEPENDENCIES
   typhoeus (~> 0.6.3)
   tzinfo-data
   uglifier (>= 1.3.0)
+  unicorn
   vcr
   webmock (~> 1.17.4)
   weibo_2 (~> 0.1.4)

+ 14 - 15
bin/setup_heroku

@@ -32,21 +32,20 @@ def yes?(question)
   ask(question + " (y/n)") =~ /^y/i
 end
 
-def grab_heroku_config
+def grab_heroku_config!
   config_data = capture("heroku config -s")
-  config = {}
+  $config = {}
   if config_data !~ /has no config vars/
     config_data.split("\n").map do |line|
       next if line =~ /^\s*(#|$)/ # skip comments and empty lines
       first_equal_sign = line.index('=')
-      config[line.slice(0, first_equal_sign)] = line.slice(first_equal_sign + 1, line.length)
+      $config[line.slice(0, first_equal_sign)] = line.slice(first_equal_sign + 1, line.length)
     end
   end
-  config
 end
 
 def set_value(key, value, options = {})
-  unless config[key] == value
+  unless $config[key] == value
     puts "Setting #{key} to #{value}" unless options[:silent]
     puts capture("heroku config:set #{key}=#{value}")
   end
@@ -79,17 +78,17 @@ unless yes?("Your Heroku app name is #{app_name}.  Is this correct?")
   puts "Well, then I'm not sure what to do here, sorry."
 end
 
-config = grab_heroku_config
+grab_heroku_config!
 
-if config.length > 0
+if $config.length > 0
   puts
   puts "Your current Heroku config:"
-  config.each do |key, value|
+  $config.each do |key, value|
     puts '  ' + key + ' ' * (25 - [key.length, 25].min) + '= ' + value
   end
 end
 
-unless config['APP_SECRET_TOKEN']
+unless $config['APP_SECRET_TOKEN']
   puts "Setting up APP_SECRET_TOKEN..."
   puts capture("heroku config:set APP_SECRET_TOKEN=`rake secret`")
 end
@@ -100,7 +99,7 @@ set_value 'ON_HEROKU', "true"
 set_value 'FORCE_SSL', "true"
 set_value 'DOMAIN', "#{app_name}.herokuapp.com"
 
-unless config['INVITATION_CODE']
+unless $config['INVITATION_CODE']
   puts "You need to set an invitation code for your Huginn instance.  If you plan to share this instance, you will"
   puts "tell this code to anyone who you'd like to invite.  If you won't share it, then just set this to something"
   puts "that people will not guess."
@@ -109,7 +108,7 @@ unless config['INVITATION_CODE']
   set_value 'INVITATION_CODE', invitation_code
 end
 
-unless config['SMTP_DOMAIN'] && config['SMTP_USER_NAME'] && config['SMTP_PASSWORD'] && config['SMTP_SERVER'] && config['EMAIL_FROM_ADDRESS']
+unless $config['SMTP_DOMAIN'] && $config['SMTP_USER_NAME'] && $config['SMTP_PASSWORD'] && $config['SMTP_SERVER'] && $config['EMAIL_FROM_ADDRESS']
   puts "Okay, let's setup outgoing email settings.  The simplest solution is to use the free sendgrid Heroku addon."
   puts "If you'd like to use your own server, or your Gmail account, please see .env.example and set"
   puts "SMTP_DOMAIN, SMTP_USER_NAME, SMTP_PASSWORD, and SMTP_SERVER with 'heroku config:set'."
@@ -119,14 +118,14 @@ unless config['SMTP_DOMAIN'] && config['SMTP_USER_NAME'] && config['SMTP_PASSWOR
     set_value 'SMTP_SERVER', "smtp.sendgrid.net", silent: true
     set_value 'SMTP_DOMAIN', "heroku.com", silent: true
 
-    config = grab_heroku_config
-    set_value 'SMTP_USER_NAME', config['SENDGRID_USERNAME'], silent: true
-    set_value 'SMTP_PASSWORD', config['SENDGRID_PASSWORD'], silent: true
+    grab_heroku_config!
+    set_value 'SMTP_USER_NAME', $config['SENDGRID_USERNAME'], silent: true
+    set_value 'SMTP_PASSWORD', $config['SENDGRID_PASSWORD'], silent: true
   else
     puts "Okay, you'll need to set SMTP_DOMAIN, SMTP_USER_NAME, SMTP_PASSWORD, and SMTP_SERVER with 'heroku config:set' manually."
   end
 
-  unless config['EMAIL_FROM_ADDRESS']
+  unless $config['EMAIL_FROM_ADDRESS']
     email = nag("What email address would you like email to appear to be sent from?")
     set_value 'EMAIL_FROM_ADDRESS', email
   end