fezzik 0.6.4 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -17,7 +17,8 @@ Require Fezzik in your project Rakefile and define a destination:
17
17
  require "fezzik"
18
18
 
19
19
  Fezzik.destination :prod do
20
- set :domain, "root@myapp.com"
20
+ set :user, "root"
21
+ set :domain, "myapp.com"
21
22
  end
22
23
  ```
23
24
 
@@ -57,11 +58,11 @@ set :local_path, Dir.pwd
57
58
  set :user, "root"
58
59
 
59
60
  Fezzik.destination :staging do
60
- set :domain, "#{user}@myapp-staging.com"
61
+ set :domain, "myapp-staging.com"
61
62
  end
62
63
 
63
64
  Fezzik.destination :prod do
64
- set :domain, "#{user}@myapp.com"
65
+ set :domain, "myapp.com"
65
66
  end
66
67
  ```
67
68
 
@@ -116,7 +117,7 @@ $ fez get environment
116
117
 
117
118
  ```ruby
118
119
  Fezzik.destination :prod do
119
- set :domain, "#{user}@myapp.com"
120
+ set :domain, "myapp.com"
120
121
  Fezzik.env :rack_env, "production"
121
122
  end
122
123
  ```
@@ -137,7 +138,7 @@ You can assign different environments to a subset of the hosts you deploy to.
137
138
 
138
139
  ```ruby
139
140
  Fezzik.destination :prod do
140
- set :domain, ["#{user}@myapp1.com", "#{user}@myapp2.com"]
141
+ set :domain, ["myapp1.com", "myapp2.com"]
141
142
  Fezzik.env :rack_env, "production"
142
143
  Fezzik.env :is_canary, "true", :hosts => ["myapp1.com"]
143
144
  end
@@ -151,6 +152,54 @@ task :inspect_environment do
151
152
  end
152
153
  ```
153
154
 
155
+
156
+ ## Roles
157
+
158
+ Fezzik supports role deployments. Roles allow you to assign remote_tasks different configurations according
159
+ to their purpose. For example, you might want to perform your initial package installations as root, but run
160
+ your app as an unprivileged user.
161
+
162
+ ```ruby
163
+ Fezzik.destination :prod do
164
+ set :domain, "myapp.com"
165
+ Fezzik.role :root_user, :user => "root"
166
+ Fezzik.role :run_user, :user => "app"
167
+ end
168
+
169
+ remote_task :install, :roles => :root_user
170
+ # Install all the things.
171
+ end
172
+
173
+ remote_task :run, :roles => :run_user
174
+ # Run all the things.
175
+ end
176
+ ```
177
+
178
+ Or, you might have different domains for database deployment and app deployment.
179
+
180
+ ```ruby
181
+ Fezzik.destination :prod do
182
+ set :user, "root"
183
+ Fezzik.role :db, :domain => "db.myapp.com"
184
+ Fezzik.role :app, :domain => "myapp.com"
185
+ end
186
+ ```
187
+
188
+ Roles in destination blocks can override global role settings.
189
+
190
+ ```ruby
191
+ Fezzik.role :app, :domain => "localhost"
192
+
193
+ Fezzik.destination :prod do
194
+ Fezzik.role :app, :domain => "myapp.com"
195
+ end
196
+ ```
197
+
198
+ The `Fezzik.role` method accepts a role name and a hash of values that you want assigned with the
199
+ `set :var, value` syntax. These will override the global or destination settings when that remote_task is
200
+ run.
201
+
202
+
154
203
  ## Utilities
155
204
 
156
205
  Fezzik exposes some functions that can be useful when running remote tasks.
@@ -192,6 +241,7 @@ the following functions:
192
241
  ```
193
242
  destination
194
243
  env
244
+ role
195
245
  capture_output
196
246
  ```
197
247
 
@@ -202,9 +252,11 @@ include Fezzik::DSL
202
252
 
203
253
  destination :prod do
204
254
  env :rack_env, "production"
255
+ role :root_user, :user => "root"
205
256
  end
206
257
  ```
207
258
 
259
+
208
260
  ## Tasks
209
261
 
210
262
  Fezzik has a number of useful tasks other than deploy.rake and environment.rake. These can also be downloaded
data/bin/fez CHANGED
@@ -67,8 +67,8 @@ def run_fezzik_tasks
67
67
  begin
68
68
  tasks = ARGV[1..-1]
69
69
  tasks.each do |task_with_params|
70
- task, params = Fezzik::Util.split_task_and_params(task_with_params)
71
- Rake::Task["fezzik:#{task}"].invoke(params)
70
+ task_name, params = Fezzik::Util.split_task_and_params(task_with_params)
71
+ Rake::Task["fezzik:#{task_name}"].invoke(params)
72
72
  end
73
73
  puts "[success]".green
74
74
  rescue SystemExit, Rake::CommandFailedError => e
@@ -6,6 +6,7 @@ require "colorize"
6
6
  require "fezzik/base"
7
7
  require "fezzik/dsl"
8
8
  require "fezzik/environment"
9
+ require "fezzik/role"
9
10
  require "fezzik/io"
10
11
  require "fezzik/util"
11
12
  require "fezzik/version"
@@ -1,15 +1,13 @@
1
1
  module Fezzik
2
2
  module DSL
3
- def destination(name, &block)
4
- Fezzik.destination(name, &block)
5
- end
6
-
7
- def env(*args)
8
- Fezzik.env(*args)
9
- end
10
-
11
- def capture_output(&block)
12
- Fezzik::Util.capture_output(&block)
3
+ # This is necessary to override Rake::RemoteTask's globally eval'ed method definitions.
4
+ def self.included(klass)
5
+ klass.class_eval do
6
+ def role(*args) Fezzik.role(*args) end
7
+ end
13
8
  end
9
+ def destination(name, &block) Fezzik.destination(name, &block) end
10
+ def env(*args) Fezzik.env(*args) end
11
+ def capture_output(&block) Fezzik::Util.capture_output(&block) end
14
12
  end
15
13
  end
@@ -0,0 +1,39 @@
1
+ module Fezzik
2
+ def self.role(role_name, settings)
3
+ @roles ||= {}
4
+ @roles[role_name] = settings
5
+ end
6
+
7
+ def self.roles() @roles ||= {} end
8
+
9
+ def self.with_role(role_name, &block)
10
+ return block.call if roles[role_name].nil?
11
+
12
+ old_settings = Hash[roles[role_name].map { |setting, value| [setting, self.send(setting)] }]
13
+ override_settings(roles[role_name])
14
+ begin
15
+ block.call
16
+ ensure
17
+ override_settings(old_settings)
18
+ end
19
+ end
20
+
21
+ def self.override_settings(settings)
22
+ settings.each { |setting, value| self.send(:set, setting, value) }
23
+ end
24
+ end
25
+
26
+ module Rake
27
+ class RemoteTask
28
+ def defined_target_hosts?() true end
29
+ def target_hosts() domain end
30
+
31
+ alias remote_task_execute execute
32
+ def execute(args = nil)
33
+ return Fezzik::Util.with_prepended_user { remote_task_execute(args) } if options[:roles].empty?
34
+ options[:roles].each do |role|
35
+ Fezzik.with_role(role) { Fezzik::Util.with_prepended_user { remote_task_execute(args) } }
36
+ end
37
+ end
38
+ end
39
+ end
@@ -20,5 +20,21 @@ module Fezzik
20
20
  end
21
21
  [task, params]
22
22
  end
23
+
24
+ # Blocks passed to this function will ensure `domain` is always an Array. In addition, if `user` is set it
25
+ # will automatically prepend the value of `user` to the front of any domains missing a username. This allows a
26
+ # fezzik user to write the following in their configuration and have it "just work":
27
+ # set :domain, ["example.com", "test@example2.com"]
28
+ # set :user, "root"
29
+ # `domain` will be equal to ["root@example.com", "test@example2.com"]
30
+ def self.with_prepended_user(&block)
31
+ old_domain = domain
32
+ begin
33
+ set :domain, Array(domain).map { |d| (defined?(user) && !d.include?("@")) ? "#{user}@#{d}" : d }
34
+ block.call
35
+ ensure
36
+ set :domain, old_domain
37
+ end
38
+ end
23
39
  end
24
40
  end
@@ -1,3 +1,3 @@
1
1
  module Fezzik
2
- VERSION = "0.6.4"
2
+ VERSION = "0.7.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fezzik
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4
4
+ version: 0.7.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-05-17 00:00:00.000000000Z
13
+ date: 2012-05-30 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
17
- requirement: &12238520 !ruby/object:Gem::Requirement
17
+ requirement: &70336101632020 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 0.8.7
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *12238520
25
+ version_requirements: *70336101632020
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rake-remote_task
28
- requirement: &12236440 !ruby/object:Gem::Requirement
28
+ requirement: &70336101631220 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 2.0.2
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *12236440
36
+ version_requirements: *70336101631220
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: colorize
39
- requirement: &12233680 !ruby/object:Gem::Requirement
39
+ requirement: &70336101630760 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,7 +44,7 @@ dependencies:
44
44
  version: 0.5.8
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *12233680
47
+ version_requirements: *70336101630760
48
48
  description: A light deployment system that gets out of your way
49
49
  email: dmacdougall@gmail.com
50
50
  executables:
@@ -64,6 +64,7 @@ files:
64
64
  - lib/fezzik/dsl.rb
65
65
  - lib/fezzik/environment.rb
66
66
  - lib/fezzik/io.rb
67
+ - lib/fezzik/role.rb
67
68
  - lib/fezzik/util.rb
68
69
  - lib/fezzik/version.rb
69
70
  - tasks/command.rake