Commit 20905d8cced40dc24a64188246a8eed0ffae6ce6
Committed by
Dan Croak
1 parent
01a5687e
Exists in
master
and in
1 other branch
rake heroku:setup prompts for all config vars
Signed-off-by: Dan Croak <dcroak@thoughtbot.com>
Showing
2 changed files
with
72 additions
and
0 deletions
Show diff stats
README.markdown
@@ -27,6 +27,11 @@ Get the latest & greatest at anytime with: | @@ -27,6 +27,11 @@ Get the latest & greatest at anytime with: | ||
27 | 27 | ||
28 | git pull heroku_suspenders master | 28 | git pull heroku_suspenders master |
29 | 29 | ||
30 | +A helper rake task will prompt you for all your production config vars (S3 | ||
31 | +keys, GMail account, Hoptoad API key...) and set them on your Heroku app: | ||
32 | + | ||
33 | + rake heroku:setup | ||
34 | + | ||
30 | More details available in doc/README_FOR_TEMPLATE. | 35 | More details available in doc/README_FOR_TEMPLATE. |
31 | 36 | ||
32 | Mascot | 37 | Mascot |
@@ -0,0 +1,67 @@ | @@ -0,0 +1,67 @@ | ||
1 | +namespace :heroku do | ||
2 | + def ask_yn(q) | ||
3 | + print "#{q} (y/n) " | ||
4 | + STDIN.gets.strip.downcase.slice(0, 1) == 'y' | ||
5 | + end | ||
6 | + | ||
7 | + def ask_value(q) | ||
8 | + print " #{q}: " | ||
9 | + STDIN.gets.strip.downcase | ||
10 | + end | ||
11 | + | ||
12 | + desc "Prompt for all the config vars and set them on the Heroku app" | ||
13 | + task :setup => :create do | ||
14 | + vars = {} | ||
15 | + | ||
16 | + if ask_yn("Use Amazon S3 for Paperclip uploads?") | ||
17 | + vars[:S3_KEY] = ask_value('S3 key') | ||
18 | + vars[:S3_SECRET] = ask_value('S3 secret key') | ||
19 | + vars[:S3_BUCKET] = ask_value('Name of S3 bucket to store assets in') | ||
20 | + end | ||
21 | + | ||
22 | + if ask_yn("Use Google Analytics to track web traffic?") | ||
23 | + vars[:GOOGLE_ANALYTICS_TRACKER_ID] = ask_value('Google Analytics tracker id') | ||
24 | + end | ||
25 | + | ||
26 | + if ask_yn("Use Hoptoad to store production execptions?") | ||
27 | + vars[:HOPTOAD_API_KEY] = ask_value('Hoptoad API key') | ||
28 | + end | ||
29 | + | ||
30 | + if ask_yn("Use GMail to send outgoing emails?") | ||
31 | + vars[:GMAIL_EMAIL] = ask_value('GMail email address') | ||
32 | + vars[:GMAIL_PASSWORD] = ask_value('GMail password') | ||
33 | + end | ||
34 | + | ||
35 | + puts "Generating a session key and session secret" | ||
36 | + vars[:SESSION_KEY] = "_#{ActiveSupport::SecureRandom.hex(6)}_session" | ||
37 | + vars[:SESSION_SECRET] = ActiveSupport::SecureRandom.hex(64) | ||
38 | + | ||
39 | + puts "Setting all config vars on Heroku app" | ||
40 | + vars_string = vars.map { |k,v| "#{k}='#{v}'" }.join(' ') | ||
41 | + sh "heroku config:add #{vars_string}" | ||
42 | + end | ||
43 | + | ||
44 | + desc "Create a new app" | ||
45 | + task :create => :dependencies do | ||
46 | + `cd #{Rails.root} && git remote -v | grep git@heroku.com` | ||
47 | + unless $?.success? | ||
48 | + puts "It doesn't look like this is a Heroku app (no git remote)." | ||
49 | + exit 1 unless ask_yn("Would you like to create a Heroku app now?") | ||
50 | + sh "heroku create" | ||
51 | + end | ||
52 | + end | ||
53 | + | ||
54 | + task :dependencies do | ||
55 | + `heroku` | ||
56 | + unless $?.success? | ||
57 | + puts "Heroku gem is not installed. Try: sudo gem install heroku" | ||
58 | + exit 1 | ||
59 | + end | ||
60 | + | ||
61 | + `cd #{Rails.root} && ls .git/config` | ||
62 | + unless $?.success? | ||
63 | + puts "This doesn't appear to be a git repo. Try: git init" | ||
64 | + exit 1 | ||
65 | + end | ||
66 | + end | ||
67 | +end |