marionetta 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/marionetta/manipulators/deployer.rb +37 -10
- data/lib/marionetta/manipulators/puppet_manipulator.rb +6 -6
- data/lib/marionetta.rb +38 -4
- data/marionetta.gemspec +8 -3
- data/spec/app/after +1 -0
- data/spec/app/exclude/another.txt +1 -0
- data/spec/app/exclude.txt +1 -0
- data/spec/deployer_spec.rb +12 -0
- data/spec/spec_helper.rb +21 -14
- metadata +13 -5
@@ -24,11 +24,15 @@ module Marionetta
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def deploy()
|
27
|
+
run_script(:before)
|
28
|
+
|
27
29
|
release = timestamp
|
28
30
|
create_tmp_release_dir(release)
|
29
31
|
send_tmp_release_dir_as_archive(release)
|
30
32
|
extract_archive_into_release_dir(release)
|
31
33
|
symlink_release_dir(release)
|
34
|
+
|
35
|
+
run_script(:after)
|
32
36
|
end
|
33
37
|
|
34
38
|
def releases()
|
@@ -90,34 +94,57 @@ module Marionetta
|
|
90
94
|
"#{to_dir}/current"
|
91
95
|
end
|
92
96
|
|
97
|
+
def fatal(message)
|
98
|
+
server[:logger].fatal(cmd.last)
|
99
|
+
server[:logger].fatal(message)
|
100
|
+
exit(1)
|
101
|
+
end
|
102
|
+
|
103
|
+
def run_script(script)
|
104
|
+
script_key = "#{script}_script".to_sym
|
105
|
+
|
106
|
+
if server[:deployer].has_key?(script_key)
|
107
|
+
script = server[:deployer][script_key]
|
108
|
+
cmd.put(script, '/tmp')
|
109
|
+
tmp_script = "/tmp/#{File.basename(script)}"
|
110
|
+
cmd.ssh("chmod +x #{tmp_script} && exec #{tmp_script}")
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
93
114
|
def create_tmp_release_dir(release)
|
94
|
-
|
115
|
+
tmp_release_dir = tmp_release_dir(release)
|
116
|
+
cmd.system("cp -r #{from_dir} #{tmp_release_dir}")
|
117
|
+
|
118
|
+
if server[:deployer].has_key?(:exclude)
|
119
|
+
exclude_files = server[:deployer][:exclude]
|
120
|
+
exclude_files.map! {|f| "#{tmp_release_dir}/#{f}"}
|
121
|
+
cmd.system("rm -rf #{exclude_files.join(' ')}")
|
122
|
+
end
|
95
123
|
end
|
96
124
|
|
97
125
|
def send_tmp_release_dir_as_archive(release)
|
98
126
|
release_archive = tmp_release_archive(release)
|
99
|
-
|
127
|
+
|
128
|
+
unless cmd.archive(tmp_release_dir(release), release_archive)
|
129
|
+
fatal('Could not create archive')
|
130
|
+
end
|
131
|
+
|
100
132
|
cmd.put(release_archive)
|
101
133
|
end
|
102
134
|
|
103
135
|
def extract_archive_into_release_dir(release)
|
104
136
|
release_archive = tmp_release_archive(release)
|
105
|
-
release_dir = release_dir(release)
|
106
137
|
|
107
138
|
unless cmd.ssh_extract(release_archive, release_dir)
|
108
|
-
|
109
|
-
server[:logger].fatal('Could not extract archive')
|
110
|
-
exit(1)
|
139
|
+
fatal('Could not extract archive')
|
111
140
|
end
|
112
141
|
end
|
113
142
|
|
114
143
|
def symlink_release_dir(release)
|
115
144
|
release_dir = release_dir(release)
|
116
145
|
|
117
|
-
unless cmd.ssh("rm -
|
118
|
-
|
119
|
-
server[:logger].fatal('Could not symlink release as current')
|
120
|
-
exit(1)
|
146
|
+
unless cmd.ssh("rm -f #{current_dir} && ln -s #{release_dir} #{current_dir}")
|
147
|
+
fatal('Could not symlink release as current')
|
121
148
|
end
|
122
149
|
end
|
123
150
|
|
@@ -89,19 +89,19 @@ module Marionetta
|
|
89
89
|
cmd.ssh_extract('/tmp/puppet.tar.gz')
|
90
90
|
cmds = ['cd /tmp/puppet']
|
91
91
|
|
92
|
-
puppet_cmd = 'sudo puppet apply
|
92
|
+
puppet_cmd = ['sudo puppet apply']
|
93
93
|
|
94
94
|
if server[:puppet].has_key?(:modules)
|
95
|
-
puppet_cmd
|
95
|
+
puppet_cmd << '--modulepath=/tmp/puppet/modules'
|
96
96
|
end
|
97
97
|
|
98
|
-
puppet_cmd
|
98
|
+
puppet_cmd << 'manifest.pp'
|
99
99
|
|
100
|
-
if server[:puppet].has_key?(:
|
101
|
-
puppet_cmd
|
100
|
+
if server[:puppet].has_key?(:flags)
|
101
|
+
puppet_cmd << server[:puppet][:flags]
|
102
102
|
end
|
103
103
|
|
104
|
-
cmds << puppet_cmd
|
104
|
+
cmds << puppet_cmd.flatten.join(' ')
|
105
105
|
|
106
106
|
cmd.ssh(cmds.join(' && '))
|
107
107
|
end
|
data/lib/marionetta.rb
CHANGED
@@ -1,9 +1,43 @@
|
|
1
|
+
# Marionetta is a ruby library for executing commands to one
|
2
|
+
# or more remote machines via SSH.
|
3
|
+
#
|
4
|
+
# It provides puppet provisioning without the need for a
|
5
|
+
# puppet master and can also deploy your application code
|
6
|
+
# (with rollbacks) via rsync. With a RakeHelper you can
|
7
|
+
# integrate it into your workflow with ease.
|
8
|
+
#
|
9
|
+
# Installing the gem is the best way to start using
|
10
|
+
# Marionetta. You can do this from command line:
|
11
|
+
#
|
12
|
+
# gem install marionetta
|
13
|
+
#
|
14
|
+
# Or – better yet – in your Gemfile:
|
15
|
+
#
|
16
|
+
# source "http://rubygems.org"
|
17
|
+
# gem 'marionetta'
|
18
|
+
#
|
19
|
+
# Marionetta is written by [Luke Morton][author] and licensed
|
20
|
+
# under the MIT license. The project is [hosted on github][github]
|
21
|
+
# where you can report issues and send your well thought out
|
22
|
+
# pull requests.
|
23
|
+
#
|
24
|
+
# [author]: http://lukemorton.co.uk
|
25
|
+
# [github]: https://github.com/DrPheltRight/marionetta
|
1
26
|
module Marionetta
|
2
|
-
VERSION
|
3
|
-
DESCRIPTION = 'For lightweight puppet mastery. Organise
|
4
|
-
multiple machines via rsync and SSH rather
|
5
|
-
than using puppet master'
|
27
|
+
VERSION = '0.3.3'
|
6
28
|
|
29
|
+
# In order to connect to servers you must define configs for
|
30
|
+
# each. This method provides a default map describing some
|
31
|
+
# common settings including command binaries, default flags
|
32
|
+
# and more.
|
33
|
+
#
|
34
|
+
# One interesting this to note is a logger is set, pointing
|
35
|
+
# to `STDOUT`.
|
36
|
+
#
|
37
|
+
# Do not get too caught up in this method, it is called
|
38
|
+
# elsewhere in Marionetta where you can better define your
|
39
|
+
# servers. You should consult this method in order to see
|
40
|
+
# the defaults.
|
7
41
|
def self.default_server()
|
8
42
|
{
|
9
43
|
:logger => Logger.new($stdout),
|
data/marionetta.gemspec
CHANGED
@@ -6,9 +6,14 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.homepage = 'https://github.com/DrPheltRight/marionetta'
|
7
7
|
s.authors = ["Luke Morton"]
|
8
8
|
s.email = ["lukemorton.dev@gmail.com"]
|
9
|
-
s.summary =
|
10
|
-
s.description = Marionetta
|
11
|
-
|
9
|
+
s.summary = "Provision using puppet and deploy your servers over SSH."
|
10
|
+
s.description = "Marionetta is a ruby library for executing commands to one
|
11
|
+
or more remote machines via SSH. It provides puppet
|
12
|
+
provisioning without the need for a puppet master and can
|
13
|
+
also deploy your application code (with rollbacks) via
|
14
|
+
rsync. With a RakeHelper you can integrate it into your
|
15
|
+
workflow with ease."
|
16
|
+
|
12
17
|
s.files = `git ls-files`.split("\n")
|
13
18
|
s.test_files = `git ls-files -- spec/*`.split("\n")
|
14
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map {|f| File.basename(f)}
|
data/spec/app/after
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
cp ~/app/current/app.rb ~/app/current/app-copy.rb
|
@@ -0,0 +1 @@
|
|
1
|
+
exclude me
|
@@ -0,0 +1 @@
|
|
1
|
+
exclude me
|
data/spec/deployer_spec.rb
CHANGED
@@ -6,9 +6,21 @@ def deployer()
|
|
6
6
|
Marionetta::Manipulators::Deployer.new(server)
|
7
7
|
end
|
8
8
|
|
9
|
+
def cmd()
|
10
|
+
Marionetta::CommandRunner.new(server)
|
11
|
+
end
|
12
|
+
|
9
13
|
describe Marionetta::Manipulators::Deployer do
|
10
14
|
it 'should deploy' do
|
15
|
+
cmd.ssh('rm -rf ~/app')
|
11
16
|
deployer.deploy
|
17
|
+
cmd.ssh("[ -d ~/app/current ]").should == true
|
18
|
+
cmd.ssh("[ -d ~/app/releases ]").should == true
|
19
|
+
cmd.ssh("[ -f ~/app/current/app.rb ]").should == true
|
20
|
+
cmd.ssh("[ -f ~/app/current/app-copy.rb ]").should == true
|
21
|
+
cmd.ssh("[ -f ~/app/current/exclude.txt ]").should_not == true
|
22
|
+
cmd.ssh("[ -f ~/app/current/exclude/another.txt ]").should_not == true
|
23
|
+
cmd.ssh("[ -f ~/app/current/after ]").should_not == true
|
12
24
|
end
|
13
25
|
|
14
26
|
it 'should list releases' do
|
data/spec/spec_helper.rb
CHANGED
@@ -8,23 +8,30 @@ env = Vagrant::Environment.new(:cwd => File.dirname(__FILE__)+'/vagrant')
|
|
8
8
|
env.cli('up')
|
9
9
|
|
10
10
|
def server()
|
11
|
-
|
11
|
+
s = Marionetta.default_server
|
12
12
|
|
13
|
-
|
14
|
-
ssh_key_path = File.dirname(__FILE__)+'/vagrant/key'
|
15
|
-
s[:ssh][:flags] = ['-i', ssh_key_path]
|
16
|
-
s[:rsync][:flags] = ['-azP', '-e', "ssh -i #{ssh_key_path}", '--delete']
|
13
|
+
# s[:logger].level = Logger::INFO
|
17
14
|
|
18
|
-
|
19
|
-
s[:deployer][:to] = '/home/vagrant'
|
15
|
+
s[:hostname] = 'vagrant@192.168.33.11'
|
20
16
|
|
21
|
-
|
22
|
-
|
23
|
-
|
17
|
+
ssh_key_path = File.dirname(__FILE__)+'/vagrant/key'
|
18
|
+
s[:ssh][:flags] = ['-i', ssh_key_path]
|
19
|
+
s[:rsync][:flags] = ['-azP', '-e', "ssh -i #{ssh_key_path}", '--delete']
|
24
20
|
|
25
|
-
|
26
|
-
:manifest => File.dirname(__FILE__)+'/puppet/manifest.pp',
|
27
|
-
}
|
21
|
+
app_dir = File.dirname(__FILE__)+'/app'
|
28
22
|
|
29
|
-
|
23
|
+
s[:deployer][:from] = app_dir
|
24
|
+
s[:deployer][:to] = '~/app'
|
25
|
+
s[:deployer][:exclude] = ['exclud*', 'before', 'after']
|
26
|
+
s[:deployer][:after_script] = "#{app_dir}/after"
|
27
|
+
|
28
|
+
s[:debloyer][:from] = app_dir
|
29
|
+
s[:debloyer][:to] = '~/app-deb'
|
30
|
+
s[:debloyer][:name] = 'test'
|
31
|
+
|
32
|
+
s[:puppet] = {
|
33
|
+
:manifest => File.dirname(__FILE__)+'/puppet/manifest.pp',
|
34
|
+
}
|
35
|
+
|
36
|
+
return s
|
30
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.3.
|
4
|
+
version: 0.3.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -107,8 +107,11 @@ dependencies:
|
|
107
107
|
- - ! '>='
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
|
-
description: ! "
|
111
|
-
machines via
|
110
|
+
description: ! "Marionetta is a ruby library for executing commands to one\n or
|
111
|
+
more remote machines via SSH. It provides puppet\n provisioning
|
112
|
+
without the need for a puppet master and can\n also deploy your
|
113
|
+
application code (with rollbacks) via\n rsync. With a RakeHelper
|
114
|
+
you can integrate it into your\n workflow with ease."
|
112
115
|
email:
|
113
116
|
- lukemorton.dev@gmail.com
|
114
117
|
executables: []
|
@@ -128,7 +131,10 @@ files:
|
|
128
131
|
- lib/marionetta/manipulators/puppet_manipulator.rb
|
129
132
|
- lib/marionetta/rake_helper.rb
|
130
133
|
- marionetta.gemspec
|
134
|
+
- spec/app/after
|
131
135
|
- spec/app/app.rb
|
136
|
+
- spec/app/exclude.txt
|
137
|
+
- spec/app/exclude/another.txt
|
132
138
|
- spec/debloyer_spec.rb
|
133
139
|
- spec/deployer_spec.rb
|
134
140
|
- spec/group_spec.rb
|
@@ -164,10 +170,12 @@ rubyforge_project:
|
|
164
170
|
rubygems_version: 1.8.24
|
165
171
|
signing_key:
|
166
172
|
specification_version: 3
|
167
|
-
summary:
|
168
|
-
SSH rather than using puppet master
|
173
|
+
summary: Provision using puppet and deploy your servers over SSH.
|
169
174
|
test_files:
|
175
|
+
- spec/app/after
|
170
176
|
- spec/app/app.rb
|
177
|
+
- spec/app/exclude.txt
|
178
|
+
- spec/app/exclude/another.txt
|
171
179
|
- spec/debloyer_spec.rb
|
172
180
|
- spec/deployer_spec.rb
|
173
181
|
- spec/group_spec.rb
|