heroku_san 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.rdoc +9 -3
  2. data/VERSION +1 -1
  3. data/lib/tasks/heroku.rake +204 -0
  4. metadata +4 -4
data/README.rdoc CHANGED
@@ -18,7 +18,7 @@ Rake tasks are not automatically loaded from gems, so you’ll need to add the f
18
18
 
19
19
  To install as a plugin:
20
20
 
21
- script/plugin install git://github.com/glennr/heroku_san.git
21
+ script/plugin install git://github.com/fastestforward/heroku_san.git
22
22
 
23
23
  == Configure
24
24
 
@@ -30,16 +30,21 @@ In config/heroku.yml you will need add the Heroku apps that you would like to at
30
30
  staging: awesomeapp-staging
31
31
  demo: awesomeapp-demo
32
32
 
33
+ If this is a fresh project, heroku_san can create all the applications for
34
+ you, and set the RACK_ENV.
35
+
36
+ rake all heroku:create heroku:rack_env
37
+
33
38
  == Usage
34
39
 
35
- After configuring your Heroku apps you can use a rake tasks to control the
40
+ After configuring your Heroku apps you can use rake tasks to control the
36
41
  apps.
37
42
 
38
43
  rake production deploy
39
44
 
40
45
  A rake task with the shorthand name of each app is now available and adds that
41
46
  server to the list that subsequent commands will execute on. Because this list
42
- is additive, you can easily select which servers to run a command on
47
+ is additive, you can easily select which servers to run a command on.
43
48
 
44
49
  rake demo staging restart
45
50
 
@@ -63,6 +68,7 @@ A full list of tasks provided:
63
68
  rake deploy # Deploys, migrates and restarts latest code.
64
69
  rake capture # Captures a bundle on Heroku
65
70
  rake heroku:apps # Lists configured apps
71
+ rake heroku:create # Creates the Heroku app
66
72
  rake heroku:create_config # Creates an example configuration file
67
73
  rake heroku:gems # Generate the Heroku gems manifest from gem dependencies
68
74
  rake heroku:remotes # Add git remotes for all apps in this project
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -1 +1,205 @@
1
+ <<<<<<< HEAD
2
+ HEROKU_CONFIG_FILE = File.join(RAILS_ROOT, 'config', 'heroku.yml')
3
+
4
+ HEROKU_SETTINGS =
5
+ if File.exists?(HEROKU_CONFIG_FILE)
6
+ YAML.load_file(HEROKU_CONFIG_FILE)
7
+ else
8
+ {}
9
+ end
10
+
11
+ (HEROKU_SETTINGS['apps'] || []).each do |name, app|
12
+ desc "Select #{name} Heroku app for later commands"
13
+ task name do
14
+ @heroku_apps ||= []
15
+ @heroku_apps << name
16
+ end
17
+ end
18
+
19
+ desc 'Select all Heroku apps for later command'
20
+ task :all do
21
+ @heroku_apps = HEROKU_SETTINGS['apps'].keys
22
+ end
23
+
24
+ namespace :heroku do
25
+ desc "Creates the Heroku app"
26
+ task :create do
27
+ each_heroku_app do |name, app, repo|
28
+ system_with_echo "heroku create #{app}"
29
+ end
30
+ end
31
+
32
+ desc "Generate the Heroku gems manifest from gem dependencies"
33
+ task :gems do
34
+ RAILS_ENV='production'
35
+ Rake::Task[:environment].invoke
36
+ list = Rails.configuration.gems.collect do |g|
37
+ command, *options = g.send(:install_command)
38
+ options.join(" ")
39
+ end
40
+
41
+ list.unshift(%Q{rails --version "= #{Rails.version}"})
42
+
43
+ File.open(File.join(RAILS_ROOT, '.gems'), 'w') do |f|
44
+ f.write(list.join("\n"))
45
+ end
46
+ end
47
+
48
+ desc 'Add git remotes for all apps in this project'
49
+ task :remotes do
50
+ each_heroku_app do |name, app, repo|
51
+ system("git remote add #{name} #{repo}")
52
+ end
53
+ end
54
+
55
+ desc 'Adds a collaborator'
56
+ task :share do
57
+ print "Email address of collaborator to add: "
58
+ $stdout.flush
59
+ email = $stdin.gets
60
+ each_heroku_app do |name, app, repo|
61
+ system_with_echo "heroku sharing:add --app #{app} #{email}"
62
+ end
63
+ end
64
+
65
+ desc 'Adds a collaborator'
66
+ task :unshare do
67
+ print "Email address of collaborator to remove: "
68
+ $stdout.flush
69
+ email = $stdin.gets
70
+ each_heroku_app do |name, app, repo|
71
+ system_with_echo "heroku sharing:remove --app #{app} #{email}"
72
+ end
73
+ end
74
+
75
+ desc 'Lists configured apps'
76
+ task :apps => :all do
77
+ each_heroku_app do |name, app, repo|
78
+ puts "#{name} is shorthand for the Heroku app #{app} located at:"
79
+ puts " #{repo}"
80
+ puts
81
+ end
82
+ end
83
+
84
+ desc 'Add proper RACK_ENV to each application'
85
+ task :rack_env => :all do
86
+ each_heroku_app do |name, app, repo|
87
+ command = "heroku config --app #{app}"
88
+ puts command
89
+ config = Hash[`#{command}`.scan(/^(.+?)\s*=>\s*(.+)$/)]
90
+ if config['RACK_ENV'] != name
91
+ system_with_echo "heroku config:add --app #{app} RACK_ENV=#{name}"
92
+ end
93
+ end
94
+ end
95
+
96
+ desc 'Creates an example configuration file'
97
+ task :create_config do
98
+ example = File.join(File.dirname(__FILE__), '..', 'templates', 'heroku.example.yml')
99
+ if File.exists?(HEROKU_CONFIG_FILE)
100
+ puts "config/heroku.yml already exists"
101
+ else
102
+ puts "Copied example config to config/heroku.yml"
103
+ FileUtils.cp(example, HEROKU_CONFIG_FILE)
104
+ system_with_echo("#{ENV['EDITOR']} #{HEROKU_CONFIG_FILE}")
105
+ end
106
+ end
107
+ end
108
+
109
+ desc "Deploys, migrates and restarts latest code"
110
+ task :deploy do
111
+ each_heroku_app do |name, app, repo|
112
+ branch = `git branch`.scan(/^\* (.*)\n/).to_s
113
+ if branch.present?
114
+ @git_push_arguments ||= []
115
+ system_with_echo "git push #{repo} #{@git_push_arguments.join(' ')} #{branch}:master && heroku rake --app #{app} db:migrate && heroku restart --app #{app}"
116
+ else
117
+ puts "Unable to determine the current git branch, please checkout the branch you'd like to deploy"
118
+ exit(1)
119
+ end
120
+ end
121
+ end
122
+
123
+ desc "Force deploys, migrates and restarts latest code"
124
+ task :force_deploy do
125
+ @git_push_arguments ||= []
126
+ @git_push_arguments << '--force'
127
+ Rake::Task[:deploy].execute
128
+ end
129
+
130
+ desc "Captures a bundle on Heroku"
131
+ task :capture do
132
+ each_heroku_app do |name, app, repo|
133
+ system_with_echo "heroku bundles:capture --app #{app}"
134
+ end
135
+ end
136
+
137
+ desc "Opens a remote console"
138
+ task :console do
139
+ each_heroku_app do |name, app, repo|
140
+ system_with_echo "heroku console --app #{app}"
141
+ end
142
+ end
143
+
144
+ desc "Restarts remote servers"
145
+ task :restart do
146
+ each_heroku_app do |name, app, repo|
147
+ system_with_echo "heroku restart --app #{app}"
148
+ end
149
+ end
150
+
151
+ desc "Migrates and restarts remote servers"
152
+ task :migrate do
153
+ each_heroku_app do |name, app, repo|
154
+ system_with_echo "heroku rake --app #{app} db:migrate && heroku restart --app #{app}"
155
+ end
156
+ end
157
+
158
+ namespace :db do
159
+ task :pull do
160
+ each_heroku_app do |name, app, repo|
161
+ system_with_echo "heroku pgdumps:capture --app #{app}"
162
+ dump = `heroku pgdumps --app #{app}`.split("\n").last.split(" ").first
163
+ system_with_echo "mkdir -p #{RAILS_ROOT}/db/dumps"
164
+ file = "#{RAILS_ROOT}/db/dumps/#{dump}.sql.gz"
165
+ url = `heroku pgdumps:url --app #{app} #{dump}`.chomp
166
+ system_with_echo "wget", url, "-O", file
167
+ system_with_echo "rake db:drop db:create"
168
+ system_with_echo "gunzip -c #{file} | #{RAILS_ROOT}/script/dbconsole"
169
+ system_with_echo "rake jobs:clear"
170
+ end
171
+ end
172
+ end
173
+
174
+ def system_with_echo(*args)
175
+ puts args.join(' ')
176
+ system(*args)
177
+ end
178
+
179
+ def each_heroku_app
180
+ if @heroku_apps.blank? && HEROKU_SETTINGS['apps'].size == 1
181
+ app = HEROKU_SETTINGS['apps'].keys.first
182
+ puts "Defaulting to #{app} app since only one app is defined"
183
+ @heroku_apps = [app]
184
+ end
185
+ if @heroku_apps.present?
186
+ @heroku_apps.each do |name|
187
+ app = HEROKU_SETTINGS['apps'][name]
188
+ yield(name, app, "git@heroku.com:#{app}.git")
189
+ end
190
+ puts
191
+ else
192
+ puts "You must first specify at least one Heroku app:
193
+ rake <app> [<app>] <command>
194
+ rake production restart
195
+ rake demo staging deploy"
196
+
197
+ puts "\nYou can use also command all Heroku apps for this project:
198
+ rake all heroku:share"
199
+
200
+ exit(1)
201
+ end
202
+ end
203
+ =======
1
204
  require File.expand_path(File.join(File.dirname(__FILE__), '..', 'heroku_san', 'tasks'))
205
+ >>>>>>> glennr/lib_task
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heroku_san
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Elijah Miller
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-06-18 00:00:00 +02:00
19
+ date: 2010-07-15 00:00:00 -04:00
20
20
  default_executable:
21
21
  dependencies: []
22
22