marionetta 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -174,6 +174,38 @@ Create an issue and send a pull request if you get any bright
174
174
  ideas or have a fix. Feel free to create an issue and not send
175
175
  one too, feedback is always welcome.
176
176
 
177
+ ## Testing
178
+
179
+ To test run this on your command line:
180
+
181
+ ```
182
+ rake
183
+ ```
184
+
185
+ You need to ensure `spec/vagrant/key` has `0600` permissions.
186
+
187
+ ## Generating documentation
188
+
189
+ Generate documentation using the following command:
190
+
191
+ ```
192
+ rake doc
193
+ ```
194
+
195
+ Publishing the documentation to GitHub pages is a little messy
196
+ to say the least. Try this:
197
+
198
+ ```
199
+ rake doc
200
+ mv docs docs-new
201
+ git checkout gh-pages
202
+ rm -rf docs
203
+ mv -f docs-new docs
204
+ git add docs
205
+ git commit -m "Update documentation."
206
+ git push origin gh-pages
207
+ ```
208
+
177
209
  ## License
178
210
 
179
- Licensed under MIT by Luke Morton, 2012.
211
+ Licensed under MIT by Luke Morton, 2012.
data/Rakefile CHANGED
@@ -7,17 +7,26 @@ RSpec::Core::RakeTask.new(:spec)
7
7
 
8
8
  task(:default => :spec)
9
9
 
10
+ desc('Create .gem for version *committed* in lib/marionetta.rb')
10
11
  task(:gem => :spec) do
11
- cmd = [
12
+ stash_cmd = [
12
13
  'git add -A',
13
14
  'git stash',
14
- 'gem build marionetta.gemspec',
15
- 'git stash pop',
16
- 'git reset',
17
15
  ]
18
- system(cmd.join(' && '))
16
+ system(stash_cmd.join(' && '))
17
+
18
+ begin
19
+ system('gem build marionetta.gemspec')
20
+ ensure
21
+ unstash_cmd = [
22
+ 'git stash pop',
23
+ 'git reset',
24
+ ]
25
+ system(unstash_cmd.join(' && '))
26
+ end
19
27
  end
20
28
 
29
+ desc('Publish version *committed* in lib/marionetta.rb')
21
30
  task(:publish => :gem) do
22
31
  version = Marionetta::VERSION
23
32
  git_tag = "v#{version}"
@@ -34,6 +43,7 @@ task(:publish => :gem) do
34
43
  system(cmd.join(' && '))
35
44
  end
36
45
 
46
+ desc('Create documentation for current working directory')
37
47
  task(:doc) do
38
48
  docs_cmd = [
39
49
  'rm -rf docs',
@@ -43,6 +53,7 @@ task(:doc) do
43
53
  system(docs_cmd.join(' && '))
44
54
  end
45
55
 
56
+ desc('Remove *.gem')
46
57
  task(:clean) do
47
58
  system('rm *.gem')
48
- end
59
+ end
@@ -153,11 +153,13 @@ module Marionetta
153
153
  # rsync('/var/www/logs', '/var/backups/www/logs')
154
154
  # rsync('/var/www/logs', 'ubuntu@example.com:/var/backups/www/logs')
155
155
  #
156
- def rsync(from, to)
156
+ def rsync(from, to, *additional_flags)
157
157
  rsync_cmd = [server[:rsync][:command]]
158
158
 
159
159
  if server[:rsync].has_key?(:flags)
160
- rsync_cmd << server[:rsync][:flags]
160
+ flags = server[:rsync][:flags].clone
161
+ flags.concat(additional_flags) unless additional_flags.empty?
162
+ rsync_cmd << flags
161
163
  end
162
164
 
163
165
  rsync_cmd << [from, to]
@@ -169,20 +171,20 @@ module Marionetta
169
171
  # to the same location on the local machine unless a path
170
172
  # is specified.
171
173
  #
172
- def get(file_path, save_to = File.dirname(file_path))
173
- rsync("#{server[:hostname]}:#{file_path}", save_to)
174
+ def get(file_path, save_to = File.dirname(file_path), *additional_flags)
175
+ rsync("#{server[:hostname]}:#{file_path}", save_to, *additional_flags)
174
176
  end
175
177
 
176
178
  # Short hand for putting a file to `:hostname` from the
177
179
  # local machine to the same location on the remote
178
180
  # machine unless a path is specified.
179
181
  #
180
- def put(file_path, save_to = File.dirname(file_path))
181
- rsync(file_path, "#{server[:hostname]}:#{save_to}")
182
+ def put(file_path, save_to = File.dirname(file_path), *additional_flags)
183
+ rsync(file_path, "#{server[:hostname]}:#{save_to}", *additional_flags)
182
184
  end
183
185
 
184
186
  private
185
187
 
186
188
  attr_reader :server
187
189
  end
188
- end
190
+ end
@@ -71,12 +71,8 @@ module Marionetta
71
71
  #
72
72
  def deploy()
73
73
  release = timestamp
74
- create_tmp_release_dir(release)
75
- cmd.ssh("mkdir -p #{release_dir}")
76
74
 
77
- unless cmd.put(tmp_release_dir(release), release_dir)
78
- fatal('Could not rsync release')
79
- end
75
+ send_files(release)
80
76
 
81
77
  run_script(:before, release)
82
78
  symlink_release_dir(release)
@@ -90,7 +86,7 @@ module Marionetta
90
86
  def releases()
91
87
  releases = []
92
88
 
93
- cmd.ssh("ls -m #{release_dir}") do |stdout|
89
+ cmd.ssh("ls -m #{releases_dir}") do |stdout|
94
90
  stdout.read.split(/[,\s]+/).each do |release|
95
91
  releases << release unless release.index('skip-') == 0
96
92
  end
@@ -135,18 +131,16 @@ module Marionetta
135
131
  server[:deployer][:from]
136
132
  end
137
133
 
138
- def tmp_release_dir(release)
139
- "/tmp/#{server[:hostname]}/#{release}"
140
- end
141
-
142
134
  def to_dir()
143
135
  server[:deployer][:to]
144
136
  end
145
137
 
146
- def release_dir(release=nil)
147
- dir = "#{to_dir}/releases"
148
- dir << "/#{release}" unless release.nil?
149
- return dir
138
+ def releases_dir()
139
+ "#{to_dir}/releases"
140
+ end
141
+
142
+ def release_dir(release)
143
+ "#{releases_dir}/#{release}"
150
144
  end
151
145
 
152
146
  def current_dir()
@@ -159,6 +153,31 @@ module Marionetta
159
153
  exit(1)
160
154
  end
161
155
 
156
+ def rsync_exclude_flags(exclude_files)
157
+ exclude_files = exclude_files.clone
158
+ exclude_files.map! {|f| Dir["#{from_dir}/#{f}"]}
159
+ exclude_files.flatten!
160
+ exclude_files.map! {|f| f.sub(from_dir+'/', '')}
161
+ exclude_files.map! {|f| ['--exclude', f]}
162
+ exclude_files.flatten!
163
+ return exclude_files
164
+ end
165
+
166
+ def send_files(release)
167
+ release_dir = release_dir(release)
168
+ cmd.ssh("mkdir -p #{release_dir}")
169
+
170
+ args = [Dir[from_dir+'/*'], release_dir]
171
+
172
+ if server[:deployer].has_key?(:exclude)
173
+ args.concat(rsync_exclude_flags(server[:deployer][:exclude]))
174
+ end
175
+
176
+ unless cmd.put(*args)
177
+ fatal('Could not rsync release')
178
+ end
179
+ end
180
+
162
181
  def run_script(script, release)
163
182
  script_key = "#{script}_script".to_sym
164
183
 
@@ -170,24 +189,6 @@ module Marionetta
170
189
  end
171
190
  end
172
191
 
173
- def create_tmp_release_dir(release)
174
- tmp_release_dir = tmp_release_dir(release)
175
-
176
- create_tmp_dir_cmds = [
177
- "mkdir -p #{File.dirname(tmp_release_dir)}",
178
- "cp -rf #{from_dir} #{tmp_release_dir}",
179
- ]
180
- cmd.system(create_tmp_dir_cmds.join(' && '))
181
-
182
- if server[:deployer].has_key?(:exclude)
183
- exclude_files = server[:deployer][:exclude]
184
- exclude_files.map! {|f| Dir["#{tmp_release_dir}/#{f}"]}
185
- exclude_files.flatten!
186
-
187
- cmd.system("rm -rf #{exclude_files.join(' ')}") unless exclude_files.empty?
188
- end
189
- end
190
-
191
192
  def symlink_release_dir(release)
192
193
  release_dir = release_dir(release)
193
194
 
@@ -201,4 +202,4 @@ module Marionetta
201
202
  end
202
203
  end
203
204
  end
204
- end
205
+ end
data/lib/marionetta.rb CHANGED
@@ -27,7 +27,7 @@
27
27
  #
28
28
  module Marionetta
29
29
 
30
- VERSION = '0.4.3'
30
+ VERSION = '0.4.4'
31
31
 
32
32
  ### Defining Servers
33
33
 
@@ -1,9 +1,9 @@
1
1
  require 'spec_helper'
2
- require "marionetta"
3
- require "marionetta/manipulators/debloyer"
2
+ require_relative '../lib/marionetta'
3
+ require_relative '../lib/marionetta/manipulators/debloyer'
4
4
 
5
5
  describe Marionetta::Manipulators::Debloyer do
6
6
  it 'should deploy a deb' do
7
7
  Marionetta::Manipulators::Debloyer.new(server).deploy
8
8
  end
9
- end
9
+ end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
- require "marionetta"
3
- require "marionetta/manipulators/deployer"
2
+ require_relative '../lib/marionetta'
3
+ require_relative '../lib/marionetta/manipulators/deployer'
4
4
 
5
5
  def deployer()
6
6
  Marionetta::Manipulators::Deployer.new(server)
@@ -14,7 +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
- cmd.ssh("[ -d ~/app/current ]").should == true
17
+ cmd.ssh("[ -L ~/app/current ]").should == true
18
18
  cmd.ssh("[ -d ~/app/releases ]").should == true
19
19
  cmd.ssh("[ -f ~/app/current/app.rb ]").should == true
20
20
  cmd.ssh("[ -f ~/app/current/app-copy.rb ]").should == true
@@ -30,4 +30,4 @@ describe Marionetta::Manipulators::Deployer do
30
30
  it 'should rollback' do
31
31
  deployer.rollback
32
32
  end
33
- end
33
+ end
data/spec/group_spec.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- require 'marionetta/group'
2
+ require_relative '../lib/marionetta/group'
3
3
 
4
4
  describe Marionetta::Group do
5
5
  it 'should add server map' do
@@ -88,4 +88,4 @@ describe Marionetta::Group do
88
88
  releases.length.should > 0
89
89
  end
90
90
  end
91
- end
91
+ end
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
- require 'marionetta/manipulators'
2
+ require_relative '../lib/marionetta/manipulators'
3
3
 
4
4
  describe Marionetta::Manipulators do
5
5
  it 'should maintain a list of manipulators' do
6
6
  Marionetta::Manipulators.all.count.should > 0
7
7
  end
8
- end
8
+ end
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
- require 'marionetta'
2
+ require_relative '../lib/marionetta'
3
3
 
4
4
  describe Marionetta do
5
5
  it 'should provide a default SSH map' do
6
6
  Marionetta.default_server
7
7
  end
8
- end
8
+ end
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
- require 'marionetta/manipulators/puppet_manipulator'
2
+ require_relative '../lib/marionetta/manipulators/puppet_manipulator'
3
3
 
4
4
  describe Marionetta::Manipulators::PuppetManipulator do
5
5
  it 'should manipulate one server map' do
6
6
  Marionetta::Manipulators::PuppetManipulator.new(server).update
7
7
  end
8
- end
8
+ end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
- require 'marionetta/group'
3
- require 'marionetta/rake_helper'
2
+ require_relative '../lib/marionetta/group'
3
+ require_relative '../lib/marionetta/rake_helper'
4
4
 
5
5
  describe Marionetta::RakeHelper do
6
6
  it 'should install rake tasks' do
@@ -14,4 +14,4 @@ describe Marionetta::RakeHelper do
14
14
  Rake::Task['deployer:vagrant:deploy'].invoke
15
15
  Rake::Task['deployer:vagrant:rollback'].invoke
16
16
  end
17
- end
17
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'vagrant'
2
2
  require 'celluloid'
3
- require 'marionetta'
3
+ require_relative '../lib/marionetta'
4
4
 
5
5
  LIB = File.dirname(__FILE__)+'/../lib'
6
6
 
@@ -34,4 +34,4 @@ def server()
34
34
  }
35
35
 
36
36
  return s
37
- end
37
+ end
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.3
4
+ version: 0.4.4
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-13 00:00:00.000000000 Z
12
+ date: 2012-11-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: open4