deplomat 0.2.9 → 0.2.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +18 -0
- data/Gemfile +1 -8
- data/Gemfile.lock +23 -65
- data/LICENSE.txt +0 -2
- data/VERSION +1 -1
- data/deplomat.gemspec +21 -79
- data/lib/deplomat/directives.rb +3 -3
- data/lib/deplomat/node.rb +28 -7
- data/lib/deplomat/remote_node.rb +7 -8
- metadata +12 -42
- data/Rakefile +0 -25
- data/spec/deployment_requisites/1_req.rb +0 -3
- data/spec/deployment_requisites/2_req.rb +0 -3
- data/spec/deployment_requisites/not_a_task.rb +0 -0
- data/spec/directives_spec.rb +0 -64
- data/spec/fixtures/.deployment_requisites_counter +0 -1
- data/spec/fixtures/cleaning/.keep +0 -0
- data/spec/fixtures/dir1/file1 +0 -0
- data/spec/fixtures/dir1/file2 +0 -0
- data/spec/fixtures/upload1/except1 +0 -0
- data/spec/fixtures/upload1/uploaded_file1 +0 -0
- data/spec/fixtures/upload1/uploaded_file2 +0 -0
- data/spec/local_node_spec.rb +0 -180
- data/spec/node_spec.rb +0 -65
- data/spec/remote_node_spec.rb +0 -139
- data/spec/spec_helper.rb +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb0da56b82a705d6aff60ad4b01fd47941634521c963c08ae946b51167b26d6b
|
4
|
+
data.tar.gz: 57ae983297c8fdc9e4e13cb6a7265b6b81a334a8aef551feb88ce9227b48451f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2599a82810507c798ec4f739707cf3390c0ae15d068d4638cd6f50aab8ebed90affb0f5285f4b14102c308bf5727481dec068459b22ac010fa71347201b86346
|
7
|
+
data.tar.gz: 3ef9941798ebc7328780d6b48bad5280ac4603d9f0eb198919a232e416e4ab706ee4cd79e6a9ec5c79e6c4618bbcb87855d3a4ef2d95b90d9ecb362756ba91d5
|
data/.gitignore
ADDED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,81 +1,39 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
Deplomat (0.2.13)
|
5
|
+
colorize
|
6
|
+
sys-proctable
|
7
|
+
|
1
8
|
GEM
|
2
9
|
remote: http://rubygems.org/
|
3
10
|
specs:
|
4
|
-
addressable (2.4.0)
|
5
|
-
builder (3.2.3)
|
6
11
|
colorize (0.8.1)
|
7
|
-
descendants_tracker (0.0.4)
|
8
|
-
thread_safe (~> 0.3, >= 0.3.1)
|
9
12
|
diff-lcs (1.3)
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
hashie (>= 3.4)
|
19
|
-
mime-types (>= 1.16, < 3.0)
|
20
|
-
oauth2 (~> 1.0)
|
21
|
-
hashie (3.5.7)
|
22
|
-
highline (1.7.10)
|
23
|
-
jeweler (2.3.9)
|
24
|
-
builder
|
25
|
-
bundler
|
26
|
-
git (>= 1.2.5)
|
27
|
-
github_api (~> 0.16.0)
|
28
|
-
highline (>= 1.6.15)
|
29
|
-
nokogiri (>= 1.5.10)
|
30
|
-
psych
|
31
|
-
rake
|
32
|
-
rdoc
|
33
|
-
semver2
|
34
|
-
jwt (1.5.6)
|
35
|
-
mime-types (2.99.3)
|
36
|
-
mini_portile2 (2.3.0)
|
37
|
-
multi_json (1.13.1)
|
38
|
-
multi_xml (0.6.0)
|
39
|
-
multipart-post (2.0.0)
|
40
|
-
nokogiri (1.8.2)
|
41
|
-
mini_portile2 (~> 2.3.0)
|
42
|
-
oauth2 (1.4.0)
|
43
|
-
faraday (>= 0.8, < 0.13)
|
44
|
-
jwt (~> 1.0)
|
45
|
-
multi_json (~> 1.3)
|
46
|
-
multi_xml (~> 0.5)
|
47
|
-
rack (>= 1.2, < 3)
|
48
|
-
psych (3.0.2)
|
49
|
-
rack (2.0.6)
|
50
|
-
rake (12.3.1)
|
51
|
-
rdoc (6.0.4)
|
52
|
-
rspec (3.7.0)
|
53
|
-
rspec-core (~> 3.7.0)
|
54
|
-
rspec-expectations (~> 3.7.0)
|
55
|
-
rspec-mocks (~> 3.7.0)
|
56
|
-
rspec-core (3.7.1)
|
57
|
-
rspec-support (~> 3.7.0)
|
58
|
-
rspec-expectations (3.7.0)
|
13
|
+
ffi (1.12.2)
|
14
|
+
rspec (3.8.0)
|
15
|
+
rspec-core (~> 3.8.0)
|
16
|
+
rspec-expectations (~> 3.8.0)
|
17
|
+
rspec-mocks (~> 3.8.0)
|
18
|
+
rspec-core (3.8.2)
|
19
|
+
rspec-support (~> 3.8.0)
|
20
|
+
rspec-expectations (3.8.4)
|
59
21
|
diff-lcs (>= 1.2.0, < 2.0)
|
60
|
-
rspec-support (~> 3.
|
61
|
-
rspec-mocks (3.
|
22
|
+
rspec-support (~> 3.8.0)
|
23
|
+
rspec-mocks (3.8.1)
|
62
24
|
diff-lcs (>= 1.2.0, < 2.0)
|
63
|
-
rspec-support (~> 3.
|
64
|
-
rspec-support (3.
|
65
|
-
|
66
|
-
sys-proctable (1.2.0)
|
25
|
+
rspec-support (~> 3.8.0)
|
26
|
+
rspec-support (3.8.2)
|
27
|
+
sys-proctable (1.2.2)
|
67
28
|
ffi
|
68
|
-
thread_safe (0.3.6)
|
69
29
|
|
70
30
|
PLATFORMS
|
71
31
|
ruby
|
72
32
|
|
73
33
|
DEPENDENCIES
|
74
|
-
|
75
|
-
|
76
|
-
jeweler
|
34
|
+
Deplomat!
|
35
|
+
bundler (~> 2.0)
|
77
36
|
rspec
|
78
|
-
sys-proctable
|
79
37
|
|
80
38
|
BUNDLED WITH
|
81
|
-
|
39
|
+
2.0.2
|
data/LICENSE.txt
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.14
|
data/deplomat.gemspec
CHANGED
@@ -1,83 +1,25 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: deplomat 0.2.9 ruby lib
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
3
|
|
7
|
-
Gem::Specification.new do |
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
"
|
20
|
-
|
21
|
-
|
22
|
-
".document",
|
23
|
-
".rspec",
|
24
|
-
"Gemfile",
|
25
|
-
"Gemfile.lock",
|
26
|
-
"LICENSE.txt",
|
27
|
-
"README.rdoc",
|
28
|
-
"Rakefile",
|
29
|
-
"VERSION",
|
30
|
-
"deplomat.gemspec",
|
31
|
-
"examples/simple_deploy.rb",
|
32
|
-
"lib/deplomat.rb",
|
33
|
-
"lib/deplomat/directives.rb",
|
34
|
-
"lib/deplomat/exceptions.rb",
|
35
|
-
"lib/deplomat/local_node.rb",
|
36
|
-
"lib/deplomat/node.rb",
|
37
|
-
"lib/deplomat/remote_node.rb",
|
38
|
-
"spec/deployment_requisites/1_req.rb",
|
39
|
-
"spec/deployment_requisites/2_req.rb",
|
40
|
-
"spec/deployment_requisites/not_a_task.rb",
|
41
|
-
"spec/directives_spec.rb",
|
42
|
-
"spec/fixtures/.deployment_requisites_counter",
|
43
|
-
"spec/fixtures/cleaning/.keep",
|
44
|
-
"spec/fixtures/dir1/file1",
|
45
|
-
"spec/fixtures/dir1/file2",
|
46
|
-
"spec/fixtures/upload1/except1",
|
47
|
-
"spec/fixtures/upload1/uploaded_file1",
|
48
|
-
"spec/fixtures/upload1/uploaded_file2",
|
49
|
-
"spec/local_node_spec.rb",
|
50
|
-
"spec/node_spec.rb",
|
51
|
-
"spec/remote_node_spec.rb",
|
52
|
-
"spec/spec_helper.rb"
|
53
|
-
]
|
54
|
-
s.homepage = "http://github.com/snitko/deplomat".freeze
|
55
|
-
s.licenses = ["MIT".freeze]
|
56
|
-
s.rubygems_version = "2.7.6".freeze
|
57
|
-
s.summary = "Stack agnostic deployment system that uses bash and ssh commands".freeze
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "deplomat"
|
6
|
+
spec.description = "Stack agnostic deployment system that uses bash and ssh commands".freeze
|
7
|
+
spec.summary = "Deplomat".freeze
|
8
|
+
spec.homepage = "https://gitlab.com/hodlhodl-public/deplomat"
|
9
|
+
spec.license = "MIT"
|
10
|
+
spec.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if spec.respond_to? :required_rubygems_version=
|
11
|
+
spec.require_paths = ["lib".freeze]
|
12
|
+
spec.authors = ["romanitup".freeze]
|
13
|
+
spec.extra_rdoc_files = [ "LICENSE.txt", "README.md"]
|
14
|
+
spec.version = File.readlines(File.expand_path(File.dirname(__FILE__)) + "/VERSION")[0]
|
15
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
16
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
end
|
18
|
+
spec.require_paths = ["lib"]
|
58
19
|
|
59
|
-
|
60
|
-
|
20
|
+
spec.add_dependency "colorize"
|
21
|
+
spec.add_dependency "sys-proctable"
|
61
22
|
|
62
|
-
|
63
|
-
|
64
|
-
s.add_runtime_dependency(%q<colorize>.freeze, [">= 0"])
|
65
|
-
s.add_development_dependency(%q<bundler>.freeze, ["~> 1.0"])
|
66
|
-
s.add_development_dependency(%q<jeweler>.freeze, [">= 0"])
|
67
|
-
s.add_development_dependency(%q<rspec>.freeze, [">= 0"])
|
68
|
-
else
|
69
|
-
s.add_dependency(%q<sys-proctable>.freeze, [">= 0"])
|
70
|
-
s.add_dependency(%q<colorize>.freeze, [">= 0"])
|
71
|
-
s.add_dependency(%q<bundler>.freeze, ["~> 1.0"])
|
72
|
-
s.add_dependency(%q<jeweler>.freeze, [">= 0"])
|
73
|
-
s.add_dependency(%q<rspec>.freeze, [">= 0"])
|
74
|
-
end
|
75
|
-
else
|
76
|
-
s.add_dependency(%q<sys-proctable>.freeze, [">= 0"])
|
77
|
-
s.add_dependency(%q<colorize>.freeze, [">= 0"])
|
78
|
-
s.add_dependency(%q<bundler>.freeze, ["~> 1.0"])
|
79
|
-
s.add_dependency(%q<jeweler>.freeze, [">= 0"])
|
80
|
-
s.add_dependency(%q<rspec>.freeze, [">= 0"])
|
81
|
-
end
|
23
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
24
|
+
spec.add_development_dependency "rspec"
|
82
25
|
end
|
83
|
-
|
data/lib/deplomat/directives.rb
CHANGED
@@ -66,14 +66,14 @@ def load_requisites!(counter, requisites_path: "#{Dir.pwd}/deployment_requisites
|
|
66
66
|
log_requisites_count = "Checking #{requisites_path} dir for requisites..."
|
67
67
|
files = Dir["#{requisites_path}/*.rb"].map do |fn|
|
68
68
|
number = fn.split("/").last.match(/\A\d+_/).to_a.first&.chomp("_")
|
69
|
-
number ? [number, fn] : nil
|
69
|
+
number ? [number.to_i, fn] : nil
|
70
70
|
end
|
71
71
|
|
72
72
|
if files
|
73
73
|
files = files.compact # ignore files that don't start with a number
|
74
74
|
.sort { |x,y| x.first <=> y.first } # Sort files according to the number in front of their names
|
75
75
|
.map { |fn| fn.last } # lose the folded Array we used to store the consecutive requisite number
|
76
|
-
.slice(counter..-1)
|
76
|
+
.slice(counter..-1) # lose files whose consecutive requisite number is below or equals the counter
|
77
77
|
end
|
78
78
|
|
79
79
|
if files && files.size > 0
|
@@ -85,7 +85,7 @@ def load_requisites!(counter, requisites_path: "#{Dir.pwd}/deployment_requisites
|
|
85
85
|
else
|
86
86
|
log_requisites_count += "no files found"
|
87
87
|
end
|
88
|
-
log
|
88
|
+
log.unshift log_requisites_count
|
89
89
|
|
90
90
|
return { counter: (files ? (counter + files.size) : 0), log: log }
|
91
91
|
|
data/lib/deplomat/node.rb
CHANGED
@@ -2,8 +2,17 @@ module Deplomat
|
|
2
2
|
|
3
3
|
class Node
|
4
4
|
|
5
|
-
attr_accessor :log_to, :raise_exceptions, :logfile
|
5
|
+
attr_accessor :log_to, :raise_exceptions, :logfile, :wrap_in
|
6
6
|
attr_reader :current_path
|
7
|
+
attr_writer :stdout_lines_to_ignore
|
8
|
+
|
9
|
+
def stdout_lines_to_ignore
|
10
|
+
if @stdout_lines_to_ignore.kind_of?(Array)
|
11
|
+
@stdout_lines_to_ignore
|
12
|
+
else
|
13
|
+
[@stdout_lines_to_ignore]
|
14
|
+
end.compact
|
15
|
+
end
|
7
16
|
|
8
17
|
def initialize(logfile: "#{Dir.pwd}/deplomat.log", log_to: [:stdout], path: nil, raise_exceptions: true)
|
9
18
|
@log_to = log_to
|
@@ -14,13 +23,18 @@ module Deplomat
|
|
14
23
|
|
15
24
|
def execute(command, path=@current_path, message: [], stdout_source: :stdout, log_command: true, _raise_exceptions: @raise_exceptions)
|
16
25
|
|
26
|
+
original_command = command
|
27
|
+
if @wrap_in
|
28
|
+
command = @wrap_in.sub("_command_", command)
|
29
|
+
end
|
30
|
+
|
17
31
|
message = [message] if message.kind_of?(String)
|
18
32
|
log(message[0] + "\n", color: 'white') unless message.empty? || message.nil?
|
19
33
|
|
20
34
|
# Respect current_path
|
21
|
-
command_to_log =
|
35
|
+
command_to_log = original_command
|
22
36
|
if path
|
23
|
-
command_to_log = "#{
|
37
|
+
command_to_log = "#{original_command}\n(in #{path})"
|
24
38
|
command = "cd #{path} && #{command}"
|
25
39
|
end
|
26
40
|
|
@@ -30,12 +44,19 @@ module Deplomat
|
|
30
44
|
|
31
45
|
# Sometimes, programs write in stderr, although there are no errors.
|
32
46
|
# rake assets:precompile does that, for example.
|
33
|
-
stdout_source_object = (stdout_source == :stderr ? stderr : stdout)
|
47
|
+
stdout_source_object = (stdout_source == :stderr ? stderr : stdout)
|
34
48
|
|
35
49
|
log("--> " + command_to_log + "\n", color: "white") if log_command
|
36
|
-
|
37
|
-
|
38
|
-
|
50
|
+
stdout_source_object.readlines.each_with_index do |line, i|
|
51
|
+
self.stdout_lines_to_ignore.each do |line_to_ignore|
|
52
|
+
line_to_ignore = line_to_ignore.to_a if line_to_ignore.kind_of?(Range)
|
53
|
+
line_to_ignore = [line_to_ignore] if line_to_ignore.kind_of?(Integer)
|
54
|
+
line = nil if line_to_ignore.include?(i+1)
|
55
|
+
end
|
56
|
+
if line
|
57
|
+
out << line
|
58
|
+
log(" #{line}") if log_command
|
59
|
+
end
|
39
60
|
end
|
40
61
|
|
41
62
|
error_out = ""
|
data/lib/deplomat/remote_node.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Deplomat
|
2
2
|
class RemoteNode < Node
|
3
3
|
|
4
|
-
def initialize(host:, port:
|
4
|
+
def initialize(host:, port: nil, user: "deploy", raise_exceptions: true, path: nil, logfile: '~/deplomat.log', log_to: [:stdout])
|
5
5
|
|
6
6
|
@log_to = log_to
|
7
7
|
@logfile = logfile
|
@@ -12,20 +12,19 @@ module Deplomat
|
|
12
12
|
end
|
13
13
|
|
14
14
|
# Establish connection
|
15
|
-
first_ssh_command = "ssh -MNfS #{ENV['HOME']}/.ssh/controlmasters/%r@%h:%p #{user}@#{host} -p #{port} -o ControlPersist=10m"
|
15
|
+
first_ssh_command = "ssh -MNfS #{ENV['HOME']}/.ssh/controlmasters/%r@%h:%p #{user}@#{host} #{port ? "-p #{port.to_s} " : ""}-o ControlPersist=10m"
|
16
16
|
system first_ssh_command
|
17
17
|
|
18
18
|
# get background process id by the full command name
|
19
19
|
@pids = []
|
20
20
|
Sys::ProcTable.ps.each do |process|
|
21
21
|
if process.cmdline.match(first_ssh_command)
|
22
|
-
@pids << process.pid.to_i
|
22
|
+
@pids << process.pid.to_i
|
23
23
|
end
|
24
24
|
end
|
25
25
|
@pids.compact!
|
26
26
|
if @pids.empty?
|
27
|
-
|
28
|
-
exit 1
|
27
|
+
raise Deplomat::ExecutionError.new("ERROR: no ssh pid found for\n\t#{first_ssh_command}.\nThis is weird.", color: "red")
|
29
28
|
elsif @pids.length > 1
|
30
29
|
log("Connected with ssh, host #{host}, but looks like another connection has been opened before...", color: "white")
|
31
30
|
log("connection pids: #{@pids.join(", ")}. We'll be closing them all when finished.", color: "white")
|
@@ -33,7 +32,7 @@ module Deplomat
|
|
33
32
|
log("Connected with ssh, host #{host}, pid #{@pids.first}", color: "white")
|
34
33
|
end
|
35
34
|
|
36
|
-
@ssh_command = "ssh -S #{ENV['HOME']}/.ssh/controlmasters/%r@%h:%p #{user}@#{host} -p #{port}"
|
35
|
+
@ssh_command = "ssh -S #{ENV['HOME']}/.ssh/controlmasters/%r@%h:%p #{user}@#{host} #{port ? "-p #{port.to_s} " : ""}"
|
37
36
|
|
38
37
|
@host = host
|
39
38
|
@user = user
|
@@ -53,12 +52,12 @@ module Deplomat
|
|
53
52
|
|
54
53
|
def upload(what, where, except: nil)
|
55
54
|
except = "--exclude '#{except}'" if except
|
56
|
-
local_execute "rsync -arzve 'ssh -p #{@port}' #{except} --delete #{what} #{@user}@#{@host}:#{where}", nil
|
55
|
+
local_execute "rsync -arzve 'ssh #{@port ? "-p #{@port.to_s} " : ""}' #{except} --delete #{what} #{@user}@#{@host}:#{where}", nil
|
57
56
|
end
|
58
57
|
|
59
58
|
def download(what, where, except: nil)
|
60
59
|
except = "--exclude '#{except}'" if except
|
61
|
-
local_execute "rsync -arzve 'ssh -p #{@port}' #{except} --delete #{@user}@#{@host}:#{what} #{where}", nil
|
60
|
+
local_execute "rsync -arzve 'ssh #{@port ? "-p #{@port.to_s} " : ""}' #{except} --delete #{@user}@#{@host}:#{what} #{where}", nil
|
62
61
|
end
|
63
62
|
|
64
63
|
def close
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deplomat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- romanitup
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: colorize
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: sys-proctable
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -44,28 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '2.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: jeweler
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
54
|
+
version: '2.0'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: rspec
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -81,7 +67,7 @@ dependencies:
|
|
81
67
|
- !ruby/object:Gem::Version
|
82
68
|
version: '0'
|
83
69
|
description: Stack agnostic deployment system that uses bash and ssh commands
|
84
|
-
email:
|
70
|
+
email:
|
85
71
|
executables: []
|
86
72
|
extensions: []
|
87
73
|
extra_rdoc_files:
|
@@ -89,12 +75,12 @@ extra_rdoc_files:
|
|
89
75
|
- README.md
|
90
76
|
files:
|
91
77
|
- ".document"
|
78
|
+
- ".gitignore"
|
92
79
|
- ".rspec"
|
93
80
|
- Gemfile
|
94
81
|
- Gemfile.lock
|
95
82
|
- LICENSE.txt
|
96
83
|
- README.md
|
97
|
-
- Rakefile
|
98
84
|
- VERSION
|
99
85
|
- deplomat.gemspec
|
100
86
|
- examples/simple_deploy.rb
|
@@ -104,22 +90,7 @@ files:
|
|
104
90
|
- lib/deplomat/local_node.rb
|
105
91
|
- lib/deplomat/node.rb
|
106
92
|
- lib/deplomat/remote_node.rb
|
107
|
-
|
108
|
-
- spec/deployment_requisites/2_req.rb
|
109
|
-
- spec/deployment_requisites/not_a_task.rb
|
110
|
-
- spec/directives_spec.rb
|
111
|
-
- spec/fixtures/.deployment_requisites_counter
|
112
|
-
- spec/fixtures/cleaning/.keep
|
113
|
-
- spec/fixtures/dir1/file1
|
114
|
-
- spec/fixtures/dir1/file2
|
115
|
-
- spec/fixtures/upload1/except1
|
116
|
-
- spec/fixtures/upload1/uploaded_file1
|
117
|
-
- spec/fixtures/upload1/uploaded_file2
|
118
|
-
- spec/local_node_spec.rb
|
119
|
-
- spec/node_spec.rb
|
120
|
-
- spec/remote_node_spec.rb
|
121
|
-
- spec/spec_helper.rb
|
122
|
-
homepage: http://github.com/snitko/deplomat
|
93
|
+
homepage: https://gitlab.com/hodlhodl-public/deplomat
|
123
94
|
licenses:
|
124
95
|
- MIT
|
125
96
|
metadata: {}
|
@@ -138,9 +109,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
109
|
- !ruby/object:Gem::Version
|
139
110
|
version: '0'
|
140
111
|
requirements: []
|
141
|
-
|
142
|
-
rubygems_version: 2.7.6
|
112
|
+
rubygems_version: 3.1.4
|
143
113
|
signing_key:
|
144
114
|
specification_version: 4
|
145
|
-
summary:
|
115
|
+
summary: Deplomat
|
146
116
|
test_files: []
|
data/Rakefile
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'bundler'
|
5
|
-
begin
|
6
|
-
Bundler.setup(:default, :development)
|
7
|
-
rescue Bundler::BundlerError => e
|
8
|
-
$stderr.puts e.message
|
9
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
-
exit e.status_code
|
11
|
-
end
|
12
|
-
require 'rake'
|
13
|
-
|
14
|
-
require 'jeweler'
|
15
|
-
Jeweler::Tasks.new do |gem|
|
16
|
-
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
|
17
|
-
gem.name = "deplomat"
|
18
|
-
gem.homepage = "http://github.com/snitko/deplomat"
|
19
|
-
gem.license = "MIT"
|
20
|
-
gem.summary = %Q{Stack agnostic deployment system that uses bash and ssh commands}
|
21
|
-
gem.description = %Q{Stack agnostic deployment system that uses bash and ssh commands}
|
22
|
-
gem.email = "roman.snitko@gmail.com"
|
23
|
-
gem.authors = ["Roman Snitko"]
|
24
|
-
# dependencies defined in Gemfile
|
25
|
-
end
|
File without changes
|
data/spec/directives_spec.rb
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "directives" do
|
4
|
-
|
5
|
-
before(:each) do
|
6
|
-
$deplomat_tasks = []
|
7
|
-
end
|
8
|
-
|
9
|
-
it "executes arbitrary ruby code in a particular environment" do
|
10
|
-
$env = 'staging'
|
11
|
-
expect(self).to receive(:hello).exactly(1).times
|
12
|
-
execute_in(env: 'staging') { hello() }
|
13
|
-
execute_in(env: 'production') { hello() }
|
14
|
-
end
|
15
|
-
|
16
|
-
it "creates a partial" do
|
17
|
-
partial("hello_partial") { hello() }
|
18
|
-
expect($partials["hello_partial"][:block]).to be_kind_of(Proc)
|
19
|
-
end
|
20
|
-
|
21
|
-
it "executes a partial" do
|
22
|
-
expect(self).to receive(:hello).with("hello").exactly(1).times
|
23
|
-
partial("hello_partial") { |args| hello(args[:x]) }
|
24
|
-
execute_partial "hello_partial", x: 'hello'
|
25
|
-
end
|
26
|
-
|
27
|
-
it "executes tasks consecutively, running before and after callbacks" do
|
28
|
-
|
29
|
-
$out = ""
|
30
|
-
def task1; $out += "task1"; end
|
31
|
-
def task2; $out += "task2"; end
|
32
|
-
def task3; $out += ",task3"; end
|
33
|
-
|
34
|
-
before_task(:task1, 1) { $out += "before_task1:" }
|
35
|
-
after_task(:task1, 2) { $out += ":after_task1," }
|
36
|
-
before_task(:task2, 3) { $out += "before_task2:" }
|
37
|
-
after_task(:task2, 4) { $out += ":after_task2" }
|
38
|
-
before_task(:task4, 5) { $out += "before_task4:" }
|
39
|
-
after_task(:task4, 6) { $out += ":after_task4" }
|
40
|
-
|
41
|
-
add_task :task1, :task2, :task3
|
42
|
-
|
43
|
-
execute_tasks!
|
44
|
-
expect($out).to eq("before_task1:task1:after_task1,before_task2:task2:after_task2,task3")
|
45
|
-
|
46
|
-
end
|
47
|
-
|
48
|
-
it "loads and runs requisites" do
|
49
|
-
|
50
|
-
def task1;end
|
51
|
-
def task2;end
|
52
|
-
|
53
|
-
add_task :task1, :task2
|
54
|
-
|
55
|
-
result = load_requisites!(1, requisites_path: "#{File.expand_path(File.dirname(__FILE__))}/deployment_requisites")
|
56
|
-
expect(result[:counter]).to eq(2)
|
57
|
-
expect(result[:log].last).to eq("Loading requisite: 2_req.rb")
|
58
|
-
execute_tasks!
|
59
|
-
expect($deployment_requisites_test_file1).to be_nil
|
60
|
-
expect($deployment_requisites_test_file2).to be_truthy
|
61
|
-
|
62
|
-
end
|
63
|
-
|
64
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
1
|
File without changes
|
data/spec/fixtures/dir1/file1
DELETED
File without changes
|
data/spec/fixtures/dir1/file2
DELETED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/spec/local_node_spec.rb
DELETED
@@ -1,180 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Deplomat::LocalNode do
|
4
|
-
|
5
|
-
before(:each) do
|
6
|
-
@fixtures_dir = Dir.pwd + "/spec/fixtures"
|
7
|
-
@localhost = Deplomat::LocalNode.new
|
8
|
-
@localhost.log_to = []
|
9
|
-
@localhost.raise_exceptions = false
|
10
|
-
end
|
11
|
-
|
12
|
-
after(:each) do
|
13
|
-
FileUtils.rm_r(Dir.glob("#{@fixtures_dir}/dir2/*"))
|
14
|
-
end
|
15
|
-
|
16
|
-
describe "filesystem operations" do
|
17
|
-
|
18
|
-
it "copies files to another folder" do
|
19
|
-
@localhost.copy("#{@fixtures_dir}/dir1/*", "#{@fixtures_dir}/dir2/")
|
20
|
-
expect(File.exist?("#{@fixtures_dir}/dir2/file1")).to be_truthy
|
21
|
-
expect(File.exist?("#{@fixtures_dir}/dir2/file2")).to be_truthy
|
22
|
-
end
|
23
|
-
|
24
|
-
it "moves files and dirs to another directory" do
|
25
|
-
@localhost.move("#{@fixtures_dir}/dir1/*", "#{@fixtures_dir}/dir2/")
|
26
|
-
expect(File.exist?("#{@fixtures_dir}/dir2/file1")).to be_truthy
|
27
|
-
expect(File.exist?("#{@fixtures_dir}/dir2/file2")).to be_truthy
|
28
|
-
expect(File.exist?("#{@fixtures_dir}/dir2/subdir1")).to be_truthy
|
29
|
-
expect(File.exist?("#{@fixtures_dir}/dir1/file1")).to be_falsy
|
30
|
-
expect(File.exist?("#{@fixtures_dir}/dir1/file2")).to be_falsy
|
31
|
-
expect(File.exist?("#{@fixtures_dir}/dir1/subdir1")).to be_falsy
|
32
|
-
|
33
|
-
@localhost.move("#{@fixtures_dir}/dir2/*", "#{@fixtures_dir}/dir1/")
|
34
|
-
expect(File.exist?("#{@fixtures_dir}/dir1/file1")).to be_truthy
|
35
|
-
expect(File.exist?("#{@fixtures_dir}/dir1/file2")).to be_truthy
|
36
|
-
expect(File.exist?("#{@fixtures_dir}/dir1/subdir1")).to be_truthy
|
37
|
-
expect(File.exist?("#{@fixtures_dir}/dir2/file1")).to be_falsy
|
38
|
-
expect(File.exist?("#{@fixtures_dir}/dir2/file2")).to be_falsy
|
39
|
-
expect(File.exist?("#{@fixtures_dir}/dir2/subdir1")).to be_falsy
|
40
|
-
end
|
41
|
-
|
42
|
-
it "removes files and dirs" do
|
43
|
-
@localhost.copy("#{@fixtures_dir}/dir1/*", "#{@fixtures_dir}/dir2/")
|
44
|
-
@localhost.remove("#{@fixtures_dir}/dir2/*")
|
45
|
-
expect(File.exist?("#{@fixtures_dir}/dir2/file1")).to be_falsy
|
46
|
-
expect(File.exist?("#{@fixtures_dir}/dir2/file2")).to be_falsy
|
47
|
-
expect(File.exist?("#{@fixtures_dir}/dir2/subdir1")).to be_falsy
|
48
|
-
end
|
49
|
-
|
50
|
-
it "changes current directory" do
|
51
|
-
@localhost.cd("/etc")
|
52
|
-
expect(@localhost.current_path).to eq("/etc/")
|
53
|
-
expect(-> { @localhost.cd("/non-existent-path") }).to raise_exception(Deplomat::NoSuchPathError)
|
54
|
-
end
|
55
|
-
|
56
|
-
it "executes commands from the current directory" do
|
57
|
-
@localhost.cd("#{@fixtures_dir}/dir1")
|
58
|
-
expect(@localhost.execute("ls")[:out]).to eq("file1\nfile2\nsubdir1\n")
|
59
|
-
end
|
60
|
-
|
61
|
-
it "creates an empty file" do
|
62
|
-
@localhost.cd("#{@fixtures_dir}/dir2")
|
63
|
-
@localhost.touch("myfile")
|
64
|
-
expect(@localhost.execute("ls")[:out]).to have_files("myfile")
|
65
|
-
end
|
66
|
-
|
67
|
-
it "creates a directory" do
|
68
|
-
@localhost.cd("#{@fixtures_dir}/dir2")
|
69
|
-
@localhost.mkdir("mydir")
|
70
|
-
expect(@localhost.execute("ls")[:out]).to have_files("mydir")
|
71
|
-
end
|
72
|
-
|
73
|
-
it "creates a symlink" do
|
74
|
-
@localhost.cd("#{@fixtures_dir}/dir2")
|
75
|
-
@localhost.create_symlink("../dir1", "./")
|
76
|
-
expect(@localhost.execute("ls dir1")[:out]).to have_files("file1", "file2", "subdir1")
|
77
|
-
end
|
78
|
-
|
79
|
-
end
|
80
|
-
|
81
|
-
describe "handling status and errors" do
|
82
|
-
|
83
|
-
it "returns the status" do
|
84
|
-
expect(@localhost.execute("ls #{@fixtures_dir}/dir1/")[:status]).to eq(0)
|
85
|
-
expect(@localhost.execute("ls #{@fixtures_dir}/non-existent-dir/")[:status]).to eq(2)
|
86
|
-
end
|
87
|
-
|
88
|
-
it "raises execution error when command fails" do
|
89
|
-
@localhost.raise_exceptions = true
|
90
|
-
expect( -> { @localhost.execute("ls #{@fixtures_dir}/non-existent-dir/")[:status] }).to raise_exception(Deplomat::ExecutionError)
|
91
|
-
end
|
92
|
-
|
93
|
-
end
|
94
|
-
|
95
|
-
describe "cleaning" do
|
96
|
-
|
97
|
-
before(:each) do
|
98
|
-
@localhost.cd("#{@fixtures_dir}/cleaning")
|
99
|
-
@localhost.execute("touch file1 file2 file3")
|
100
|
-
@localhost.execute("mkdir current")
|
101
|
-
sleep(0.01)
|
102
|
-
@localhost.execute("mkdir dir1 dir2 dir3")
|
103
|
-
end
|
104
|
-
|
105
|
-
after(:each) do
|
106
|
-
@localhost.execute("rm -rf #{@fixtures_dir}/cleaning/*")
|
107
|
-
end
|
108
|
-
|
109
|
-
it "cleans all the files and dirs in a given directory" do
|
110
|
-
@localhost.clean
|
111
|
-
expect(@localhost.execute('ls')[:out]).to be_empty
|
112
|
-
end
|
113
|
-
|
114
|
-
it "cleans all but last 3 entries in a given directory" do
|
115
|
-
@localhost.clean(leave: [3, :last])
|
116
|
-
expect(@localhost.execute('ls')[:out]).to eq("dir1\ndir2\ndir3\n")
|
117
|
-
end
|
118
|
-
|
119
|
-
it "cleans all, but :except entries in a given directory" do
|
120
|
-
@localhost.clean(except: ["current"])
|
121
|
-
expect(@localhost.execute('ls')[:out]).to eq("current\n")
|
122
|
-
end
|
123
|
-
|
124
|
-
end
|
125
|
-
|
126
|
-
describe "git commands" do
|
127
|
-
|
128
|
-
before(:all) do
|
129
|
-
@fixtures_dir = Dir.pwd + "/spec/fixtures"
|
130
|
-
@localhost_git = Deplomat::LocalNode.new
|
131
|
-
@localhost_git.log_to = [:stdout]
|
132
|
-
@localhost_git.cd(@fixtures_dir)
|
133
|
-
@localhost_git.mkdir("git_repo")
|
134
|
-
@localhost_git.cd("git_repo")
|
135
|
-
@localhost_git.touch("file1")
|
136
|
-
@localhost_git.execute("git init && git add .")
|
137
|
-
@localhost_git.execute("git remote add origin deploy@deplomat-test-node:/home/deploy/deplomat/.git_repo")
|
138
|
-
@remote_node = Deplomat::RemoteNode.new(host: "deplomat-test-node", user: "deploy")
|
139
|
-
@remote_node.log_to = [:stdout]
|
140
|
-
@remote_node.execute("cd ~/deplomat && mkdir .git_repo && cd .git_repo && git --bare init")
|
141
|
-
@localhost_git.cd("#{@fixtures_dir}/git_repo")
|
142
|
-
@localhost_git.execute("git commit -m \"Initial commit\"")
|
143
|
-
|
144
|
-
@localhost_git.raise_exceptions = true
|
145
|
-
@remote_node.raise_exceptions = true
|
146
|
-
end
|
147
|
-
|
148
|
-
after(:all) do
|
149
|
-
@remote_node.remove("~/deplomat/.git_repo")
|
150
|
-
@localhost_git.remove("#{@fixtures_dir}/git_repo")
|
151
|
-
end
|
152
|
-
|
153
|
-
it "pushes to remote" do
|
154
|
-
expect(@localhost_git.git_push[:status]).to eq(0)
|
155
|
-
end
|
156
|
-
|
157
|
-
it "pulls from remote" do
|
158
|
-
expect(@localhost_git.git_pull[:status]).to eq(0)
|
159
|
-
end
|
160
|
-
|
161
|
-
it "merges branches" do
|
162
|
-
@localhost_git.execute("git checkout -b dev1")
|
163
|
-
@localhost_git.touch("file2")
|
164
|
-
@localhost_git.execute("git add . && git commit -m \"adding file2\"")
|
165
|
-
@localhost_git.execute("git checkout master")
|
166
|
-
expect(@localhost_git.git_merge("dev1", "master")[:status]).to eq(0)
|
167
|
-
expect(File.exist?("#{@fixtures_dir}/git_repo/file2")).to be_truthy
|
168
|
-
end
|
169
|
-
|
170
|
-
it "checks out into a branch" do
|
171
|
-
@localhost_git.execute("git branch dev2")
|
172
|
-
@localhost_git.touch("file3")
|
173
|
-
@localhost_git.execute("git add . && git commit -m \"adding file3\"")
|
174
|
-
@localhost_git.git_checkout("dev2")
|
175
|
-
expect(File.exist?("#{@fixtures_dir}/git_repo/file3")).to be_falsy
|
176
|
-
end
|
177
|
-
|
178
|
-
end
|
179
|
-
|
180
|
-
end
|
data/spec/node_spec.rb
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Deplomat::Node do
|
4
|
-
|
5
|
-
before(:each) do
|
6
|
-
@fixtures_dir = Dir.pwd + "/spec/fixtures"
|
7
|
-
@node = Deplomat::Node.new(logfile: "#{@fixtures_dir}/deplomat.log", log_to: [:file, :stdout])
|
8
|
-
end
|
9
|
-
|
10
|
-
it "checks if file exists" do
|
11
|
-
expect(@node.file_exists?("#{@fixtures_dir}/existing_file.txt")).to be_falsey
|
12
|
-
expect(@node.file_exists?("/non-existent-path")).to be_falsey
|
13
|
-
FileUtils.touch("#{@fixtures_dir}/existing_file.txt")
|
14
|
-
expect(@node.file_exists?("#{@fixtures_dir}/existing_file.txt")).to be_truthy
|
15
|
-
FileUtils.rm("#{@fixtures_dir}/existing_file.txt")
|
16
|
-
end
|
17
|
-
|
18
|
-
describe "logging" do
|
19
|
-
|
20
|
-
after(:each) do
|
21
|
-
@node.log_to = []
|
22
|
-
@node.remove("#{@fixtures_dir}/deplomat.log")
|
23
|
-
end
|
24
|
-
|
25
|
-
it "logs to the stdout" do
|
26
|
-
expect($stdout).to receive(:print).exactly(4).times
|
27
|
-
@node.execute("ls #{@fixtures_dir}/dir1")
|
28
|
-
end
|
29
|
-
|
30
|
-
it "logs to a log file" do
|
31
|
-
@node.log_to = [:file]
|
32
|
-
@node.execute("ls #{@fixtures_dir}/dir1")
|
33
|
-
log = File.readlines("#{@fixtures_dir}/deplomat.log")
|
34
|
-
expect(log.size).to eq(4)
|
35
|
-
end
|
36
|
-
|
37
|
-
it "puts additional messages into the terminal when required" do
|
38
|
-
expect($stdout).to receive(:print).once.with("hello\n".white)
|
39
|
-
expect($stdout).to receive(:print).once.with("--> ls #{@fixtures_dir}/dir1\n".white)
|
40
|
-
expect($stdout).to receive(:print).once.with(" file1\n".light_black)
|
41
|
-
expect($stdout).to receive(:print).once.with(" file2\n".light_black)
|
42
|
-
expect($stdout).to receive(:print).once.with(" subdir1\n".light_black)
|
43
|
-
expect($stdout).to receive(:print).once.with("bye\n".white)
|
44
|
-
@node.execute("ls #{@fixtures_dir}/dir1", message: ["hello", "bye"])
|
45
|
-
end
|
46
|
-
|
47
|
-
it "updates requisite counter" do
|
48
|
-
@node.log_to = []
|
49
|
-
|
50
|
-
requisites_counter_fn = "#{Dir.pwd}/spec/.deployment_requisites_counter"
|
51
|
-
@node.cd Dir.pwd + "/spec"
|
52
|
-
|
53
|
-
File.open(requisites_counter_fn, "w") { |f| f.puts 1 }
|
54
|
-
@node.update_requisite_number!(2)
|
55
|
-
expect(File.readlines(requisites_counter_fn).first.to_i).to eq(2)
|
56
|
-
|
57
|
-
expect(-> { @node.update_requisite_number!(1) }).to raise_exception(SystemExit)
|
58
|
-
|
59
|
-
File.unlink(requisites_counter_fn)
|
60
|
-
expect(-> { @node.update_requisite_number!(3) }).to raise_exception(SystemExit)
|
61
|
-
end
|
62
|
-
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
data/spec/remote_node_spec.rb
DELETED
@@ -1,139 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Deplomat::RemoteNode do
|
4
|
-
|
5
|
-
before(:all) do
|
6
|
-
@fixtures_dir = "/home/deploy/deplomat"
|
7
|
-
@local_fixtures_dir = Dir.pwd + "/spec/fixtures"
|
8
|
-
@node = Deplomat::RemoteNode.new(host: "deplomat-test-node", user: "deploy")
|
9
|
-
@node.log_to = []
|
10
|
-
end
|
11
|
-
|
12
|
-
before(:each) do
|
13
|
-
@node.raise_exceptions = true
|
14
|
-
end
|
15
|
-
|
16
|
-
after(:all) do
|
17
|
-
@node.close
|
18
|
-
end
|
19
|
-
|
20
|
-
after(:each) do
|
21
|
-
@node.raise_exceptions = false
|
22
|
-
@node.execute("rm -rf #{@fixtures_dir}/dir2/*")
|
23
|
-
@node.execute("rm -rf #{@fixtures_dir}/uploaded1/*")
|
24
|
-
@node.execute("rm -rf #{@fixtures_dir}/uploaded2/*")
|
25
|
-
end
|
26
|
-
|
27
|
-
describe "filesystem operations" do
|
28
|
-
|
29
|
-
it "copies files to another folder" do
|
30
|
-
@node.copy("#{@fixtures_dir}/dir1/*", "#{@fixtures_dir}/dir2/")
|
31
|
-
expect(@node.execute("ls #{@fixtures_dir}/dir2/")[:out]).to have_files("file1", "file2", "subdir1")
|
32
|
-
end
|
33
|
-
|
34
|
-
it "moves files and dirs from one directory into another" do
|
35
|
-
@node.move("#{@fixtures_dir}/dir1/*", "#{@fixtures_dir}/dir2/")
|
36
|
-
expect(@node.execute("ls #{@fixtures_dir}/dir1/")[:out]).to eq("")
|
37
|
-
expect(@node.execute("ls #{@fixtures_dir}/dir2/")[:out]).to have_files("file1", "file2", "subdir1")
|
38
|
-
@node.move("#{@fixtures_dir}/dir2/*", "#{@fixtures_dir}/dir1/")
|
39
|
-
expect(@node.execute("ls #{@fixtures_dir}/dir2/")[:out]).to eq("")
|
40
|
-
expect(@node.execute("ls #{@fixtures_dir}/dir1/")[:out]).to have_files("file1", "file2", "subdir1")
|
41
|
-
end
|
42
|
-
|
43
|
-
it "removes files and dirs" do
|
44
|
-
@node.copy("#{@fixtures_dir}/dir1/*", "#{@fixtures_dir}/dir2/")
|
45
|
-
expect(@node.execute("ls #{@fixtures_dir}/dir2/")[:out]).to have_files("file1", "file2", "subdir1")
|
46
|
-
@node.remove("#{@fixtures_dir}/dir2/*")
|
47
|
-
expect(@node.execute("ls #{@fixtures_dir}/dir2/")[:out]).to eq("")
|
48
|
-
end
|
49
|
-
|
50
|
-
it "uploads files from localhost to the node" do
|
51
|
-
@node.upload("#{@local_fixtures_dir}/upload1/*", "#{@fixtures_dir}/uploaded1/", except: 'except1')
|
52
|
-
expect(@node.execute("ls #{@fixtures_dir}/uploaded1/")[:out]).to have_files("uploaded_file1", "uploaded_file2")
|
53
|
-
expect(@node.execute("ls #{@fixtures_dir}/uploaded1/")[:out]).to not_have_files("except1")
|
54
|
-
end
|
55
|
-
|
56
|
-
it "changes current directory" do
|
57
|
-
#@node.cd("/etc")
|
58
|
-
#expect(@node.current_path).to eq("/etc/")
|
59
|
-
expect(-> { @node.cd("/non-existent-path") }).to raise_exception(Deplomat::NoSuchPathError)
|
60
|
-
end
|
61
|
-
|
62
|
-
it "executes commands from the current directory" do
|
63
|
-
@node.cd("#{@fixtures_dir}/dir1")
|
64
|
-
expect(@node.execute("ls")[:out]).to have_files("file1", "file2", "subdir1")
|
65
|
-
end
|
66
|
-
|
67
|
-
it "creates an empty file" do
|
68
|
-
@node.cd("#{@fixtures_dir}/dir2")
|
69
|
-
@node.touch("myfile")
|
70
|
-
expect(@node.execute("ls")[:out]).to have_files("myfile")
|
71
|
-
end
|
72
|
-
|
73
|
-
it "creates a directory" do
|
74
|
-
@node.cd("#{@fixtures_dir}/dir2")
|
75
|
-
@node.mkdir("mydir")
|
76
|
-
expect(@node.execute("ls")[:out]).to have_files("mydir")
|
77
|
-
end
|
78
|
-
|
79
|
-
it "creates a symlink" do
|
80
|
-
@node.cd("#{@fixtures_dir}/dir2")
|
81
|
-
@node.create_symlink("../dir1", "./")
|
82
|
-
expect(@node.execute("ls dir1")[:out]).to have_files("file1", "file2", "subdir1")
|
83
|
-
end
|
84
|
-
|
85
|
-
it "doesn't log ls command when checking if folder exists in `cd`" do
|
86
|
-
expect(@node).to receive(:log).with("(deplomat-test-node) --> ls /home/deploy/deplomat/dir2\n", { color: "white"}).exactly(0).times
|
87
|
-
@node.cd("#{@fixtures_dir}/dir2")
|
88
|
-
allow(@node).to receive(:log)
|
89
|
-
end
|
90
|
-
|
91
|
-
end
|
92
|
-
|
93
|
-
describe "handling status and errors" do
|
94
|
-
|
95
|
-
it "returns the status" do
|
96
|
-
@node.raise_exceptions = false
|
97
|
-
expect(@node.execute("ls #{@fixtures_dir}/dir1/")[:status]).to eq(0)
|
98
|
-
expect(@node.execute("ls #{@fixtures_dir}/non-existent-dir/")[:status]).to eq(2)
|
99
|
-
end
|
100
|
-
|
101
|
-
it "raises execution error when command fails" do
|
102
|
-
@node.raise_exceptions = true
|
103
|
-
expect( -> { @node.execute("ls #{@fixtures_dir}/non-existent-dir/")[:status] }).to raise_exception(Deplomat::ExecutionError)
|
104
|
-
end
|
105
|
-
|
106
|
-
end
|
107
|
-
|
108
|
-
describe "cleaning" do
|
109
|
-
|
110
|
-
before(:each) do
|
111
|
-
@node.cd("#{@fixtures_dir}/cleaning")
|
112
|
-
@node.execute("touch file1 file2 file3")
|
113
|
-
@node.execute("mkdir current")
|
114
|
-
sleep(0.01)
|
115
|
-
@node.execute("mkdir dir1 dir2 dir3")
|
116
|
-
end
|
117
|
-
|
118
|
-
after(:each) do
|
119
|
-
@node.execute("rm -rf #{@fixtures_dir}/cleaning/*")
|
120
|
-
end
|
121
|
-
|
122
|
-
it "cleans all the files and dirs in a given directory" do
|
123
|
-
@node.clean
|
124
|
-
expect(@node.execute('ls')[:out]).to be_empty
|
125
|
-
end
|
126
|
-
|
127
|
-
it "cleans all but last 3 entries in a given directory" do
|
128
|
-
@node.clean(leave: [3, :last])
|
129
|
-
expect(@node.execute('ls')[:out]).to eq("dir1\ndir2\ndir3\n")
|
130
|
-
end
|
131
|
-
|
132
|
-
it "cleans all, but :except entries in a given directory" do
|
133
|
-
@node.clean(except: ["current"])
|
134
|
-
expect(@node.execute('ls')[:out]).to eq("current\n")
|
135
|
-
end
|
136
|
-
|
137
|
-
end
|
138
|
-
|
139
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'rspec/expectations'
|
2
|
-
require "fileutils"
|
3
|
-
require_relative "../lib/deplomat"
|
4
|
-
|
5
|
-
RSpec::Matchers.define :have_files do |*expected|
|
6
|
-
match do |actual|
|
7
|
-
actual = actual.split("\n")
|
8
|
-
actual.pop if actual.last == ""
|
9
|
-
expected.each do |e|
|
10
|
-
return false unless actual.include?(e)
|
11
|
-
end
|
12
|
-
true
|
13
|
-
end
|
14
|
-
failure_message do |actual|
|
15
|
-
"expected these files in the directory:\n\t#{actual.split("\n").inspect}\nwould include all of these:\n\t#{expected.inspect}"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
RSpec::Matchers.define :not_have_files do |*expected|
|
20
|
-
match do |actual|
|
21
|
-
actual = actual.split("\n")
|
22
|
-
actual.pop if actual.last == ""
|
23
|
-
expected.each do |e|
|
24
|
-
return false if actual.include?(e)
|
25
|
-
end
|
26
|
-
true
|
27
|
-
end
|
28
|
-
failure_message do |actual|
|
29
|
-
"expected these files in the directory:\n\t#{actual.split("\n").inspect}\nwould NOT include any of these:\n\t#{expected.inspect}"
|
30
|
-
end
|
31
|
-
end
|