marionetta 0.4.4 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,6 +4,7 @@
4
4
  # Using a directory structure similar to capistrano `Deployer`
5
5
  # maintains a folder of releases so you may rollback quickly.
6
6
  #
7
+ require 'marionetta'
7
8
  require 'marionetta/command_runner'
8
9
 
9
10
  module Marionetta
@@ -54,9 +55,10 @@ module Marionetta
54
55
  # Call `.deploy()` to run a deploy to your remote
55
56
  # server. The process involves:
56
57
  #
57
- # - `:from` directory copied to temporary directory
58
- # - `:exclude` files are removed
59
- # - rsync'd to a releases directory
58
+ # - `:from` directory rsync'd to remote cache directory
59
+ # with `:exclude` files being ignored
60
+ # - cache directory copied on remote machine to
61
+ # releases directory
60
62
  # - `:before_script` run
61
63
  # - release directory symlinked to a current directory
62
64
  # - `:after_script` run
@@ -64,16 +66,20 @@ module Marionetta
64
66
  # The directory structure under `server[:deployer][:to]`
65
67
  # looks something like this:
66
68
  #
67
- # current/ -> ./releases/2012-09-20_14:04:39
68
- # releases/
69
- # 2012-09-20_13:59:15
70
- # 2012-09-20_14:04:39
69
+ # cache/
70
+ # current/ -> ./releases/2012-09-20_14:04:39
71
+ # releases/
72
+ # 2012-09-20_13:59:15
73
+ # 2012-09-20_14:04:39
71
74
  #
72
75
  def deploy()
73
- release = timestamp
76
+ release = create_release_name()
74
77
 
75
- send_files(release)
78
+ create_cache_dir()
79
+ sync_cache_dir()
80
+ copy_cache_dir_to_release(release)
76
81
 
82
+ send_scripts()
77
83
  run_script(:before, release)
78
84
  symlink_release_dir(release)
79
85
  run_script(:after, release)
@@ -135,6 +141,18 @@ module Marionetta
135
141
  server[:deployer][:to]
136
142
  end
137
143
 
144
+ def tmp_dir()
145
+ if server[:deployer].has_key?(:tmp)
146
+ server[:deployer][:tmp]
147
+ else
148
+ Marionetta.default_server[:deployer][:tmp]
149
+ end
150
+ end
151
+
152
+ def cache_dir()
153
+ "#{to_dir}/cache"
154
+ end
155
+
138
156
  def releases_dir()
139
157
  "#{to_dir}/releases"
140
158
  end
@@ -153,6 +171,10 @@ module Marionetta
153
171
  exit(1)
154
172
  end
155
173
 
174
+ def create_release_name()
175
+ timestamp
176
+ end
177
+
156
178
  def rsync_exclude_flags(exclude_files)
157
179
  exclude_files = exclude_files.clone
158
180
  exclude_files.map! {|f| Dir["#{from_dir}/#{f}"]}
@@ -163,18 +185,40 @@ module Marionetta
163
185
  return exclude_files
164
186
  end
165
187
 
166
- def send_files(release)
167
- release_dir = release_dir(release)
168
- cmd.ssh("mkdir -p #{release_dir}")
188
+ def create_cache_dir()
189
+ cmd.ssh("test -d #{cache_dir} || mkdir -p #{cache_dir}")
190
+ end
169
191
 
170
- args = [Dir[from_dir+'/*'], release_dir]
192
+ def sync_cache_dir()
193
+ args = [Dir[from_dir+'/*'], cache_dir]
171
194
 
172
195
  if server[:deployer].has_key?(:exclude)
173
196
  args.concat(rsync_exclude_flags(server[:deployer][:exclude]))
174
197
  end
175
198
 
176
199
  unless cmd.put(*args)
177
- fatal('Could not rsync release')
200
+ fatal('Could not rsync cache dir')
201
+ end
202
+ end
203
+
204
+ def copy_cache_dir_to_release(release)
205
+ release_dir = release_dir(release)
206
+ cmd.ssh("mkdir -p #{releases_dir} && cp -r #{cache_dir} #{release_dir}")
207
+ end
208
+
209
+ def send_scripts()
210
+ files = []
211
+
212
+ [:before, :after].each do |script|
213
+ script_key = "#{script}_script".to_sym
214
+
215
+ if server[:deployer].has_key?(script_key)
216
+ files << server[:deployer][script_key]
217
+ end
218
+ end
219
+
220
+ unless files.empty?
221
+ cmd.put(files, tmp_dir)
178
222
  end
179
223
  end
180
224
 
@@ -183,8 +227,7 @@ module Marionetta
183
227
 
184
228
  if server[:deployer].has_key?(script_key)
185
229
  script = server[:deployer][script_key]
186
- cmd.put(script, '/tmp')
187
- tmp_script = "/tmp/#{File.basename(script)}"
230
+ tmp_script = "#{tmp_dir}/#{File.basename(script)}"
188
231
  cmd.ssh("chmod +x #{tmp_script} && exec #{tmp_script} #{release}")
189
232
  end
190
233
  end
data/lib/marionetta.rb CHANGED
@@ -27,7 +27,7 @@
27
27
  #
28
28
  module Marionetta
29
29
 
30
- VERSION = '0.4.4'
30
+ VERSION = '0.4.5'
31
31
 
32
32
  ### Defining Servers
33
33
 
@@ -74,7 +74,9 @@ module Marionetta
74
74
 
75
75
  :puppet => {},
76
76
 
77
- :deployer => {},
77
+ :deployer => {
78
+ :tmp => '/tmp'
79
+ },
78
80
 
79
81
  :debloyer => {
80
82
  :name => 'debloyer',
@@ -14,6 +14,7 @@ describe Marionetta::Manipulators::Deployer do
14
14
  it 'should deploy' do
15
15
  cmd.ssh('rm -rf ~/app')
16
16
  deployer.deploy
17
+ deployer.deploy
17
18
  cmd.ssh("[ -L ~/app/current ]").should == true
18
19
  cmd.ssh("[ -d ~/app/releases ]").should == true
19
20
  cmd.ssh("[ -f ~/app/current/app.rb ]").should == true
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marionetta
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-28 00:00:00.000000000 Z
12
+ date: 2012-12-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: open4