deplomat 0.2.11 → 0.2.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e9219f57f21ff90282cc86893d24ba465a64d5af5328fa34ea178f1080f8b38
4
- data.tar.gz: 690b25723ba53be14fcd54770fdd3b994ddf516e74908d926c3e5cc48e4d856e
3
+ metadata.gz: c80211d4c464c085f43b19d2a27f2b82d5e066c1dc31b92caa5d2cf874353dc4
4
+ data.tar.gz: d53d94174f430d4331beaa60410cc0e404a279ed3d5ed3994ed7ff39b403b46e
5
5
  SHA512:
6
- metadata.gz: c24dd2f80073a91de3cb09b2780ff11ddc42e08e96fc3ce0d7d4f851175a1b9665c6f99bfd0a2684c43843fa740961f3e2272b6ade4680091bc787a027724f66
7
- data.tar.gz: ec174a32acce4e363e9dfc43f8efb8ca55f82feb93f36469c699630053d826f428b6e0307c38d9584a25509333fb26b9510609738c30903007c091fbb8569502
6
+ metadata.gz: aee786c6a683d0ba765f8288c8eda00c50d7cee11451a669262d42d740592fed3ebb3da442466d2e27a282b63a466c24eed09d2dc52c72168d28d66e9ed2f16a
7
+ data.tar.gz: b6b96a6b4889bd2243140c3429d59e88499ed1e1981ffc737d883a02df89f95d7b91dfe088ae8c17a21aa2f109cab92034b5ace88bee0d59b3819eff9ca7b4c5
@@ -0,0 +1,18 @@
1
+ # rcov generated
2
+ coverage
3
+ coverage.data
4
+
5
+ # rdoc generated
6
+ rdoc
7
+
8
+ # yard generated
9
+ doc
10
+ .yardoc
11
+
12
+ # bundler
13
+ .bundle
14
+
15
+ # jeweler generated
16
+ pkg
17
+
18
+ spec/fixtures/git_repo
data/Gemfile CHANGED
@@ -1,9 +1,3 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem "sys-proctable"
4
- gem "colorize"
5
-
6
- group :development do
7
- gem "bundler", "~> 1.0"
8
- gem "rspec"
9
- end
3
+ gemspec
@@ -1,9 +1,16 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ deplomat (0.2.16)
5
+ colorize
6
+ sys-proctable
7
+
1
8
  GEM
2
9
  remote: http://rubygems.org/
3
10
  specs:
4
11
  colorize (0.8.1)
5
12
  diff-lcs (1.3)
6
- ffi (1.11.1)
13
+ ffi (1.13.1)
7
14
  rspec (3.8.0)
8
15
  rspec-core (~> 3.8.0)
9
16
  rspec-expectations (~> 3.8.0)
@@ -17,17 +24,16 @@ GEM
17
24
  diff-lcs (>= 1.2.0, < 2.0)
18
25
  rspec-support (~> 3.8.0)
19
26
  rspec-support (3.8.2)
20
- sys-proctable (1.2.1)
27
+ sys-proctable (1.2.6)
21
28
  ffi
22
29
 
23
30
  PLATFORMS
24
31
  ruby
25
32
 
26
33
  DEPENDENCIES
27
- bundler (~> 1.0)
28
- colorize
34
+ bundler (~> 2.0)
35
+ deplomat!
29
36
  rspec
30
- sys-proctable
31
37
 
32
38
  BUNDLED WITH
33
- 1.17.2
39
+ 2.1.4
@@ -1,5 +1,3 @@
1
- Copyright (c) 2016 Roman Snitko
2
-
3
1
  Permission is hereby granted, free of charge, to any person obtaining
4
2
  a copy of this software and associated documentation files (the
5
3
  "Software"), to deal in the Software without restriction, including
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.11
1
+ 0.2.16
@@ -1,83 +1,25 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
5
- # stub: deplomat 0.2.10 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 |s|
8
- s.name = "deplomat".freeze
9
- s.version = "0.2.11"
10
-
11
- s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
- s.require_paths = ["lib".freeze]
13
- s.authors = ["Roman Snitko".freeze]
14
- s.date = "2019-06-16"
15
- s.description = "Stack agnostic deployment system that uses bash and ssh commands".freeze
16
- s.email = "roman.snitko@gmail.com".freeze
17
- s.extra_rdoc_files = [
18
- "LICENSE.txt",
19
- "README.md"
20
- ]
21
- s.files = [
22
- ".document",
23
- ".rspec",
24
- "Gemfile",
25
- "Gemfile.lock",
26
- "LICENSE.txt",
27
- "README.md",
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
- if s.respond_to? :specification_version then
60
- s.specification_version = 4
20
+ spec.add_dependency "colorize"
21
+ spec.add_dependency "sys-proctable"
61
22
 
62
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
63
- s.add_runtime_dependency(%q<sys-proctable>.freeze, [">= 0"])
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
-
@@ -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) # lose files whose consecutive requisite number is below or equals the counter
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 << log_requisites_count
88
+ log.unshift log_requisites_count
89
89
 
90
90
  return { counter: (files ? (counter + files.size) : 0), log: log }
91
91
 
@@ -2,8 +2,7 @@ module Deplomat
2
2
 
3
3
  class Node
4
4
 
5
- attr_accessor :log_to, :raise_exceptions, :logfile, :wrap_in
6
- attr_reader :current_path
5
+ attr_accessor :log_to, :raise_exceptions, :logfile, :wrap_in, :current_path
7
6
  attr_writer :stdout_lines_to_ignore
8
7
 
9
8
  def stdout_lines_to_ignore
@@ -18,7 +17,7 @@ module Deplomat
18
17
  @log_to = log_to
19
18
  @logfile = logfile
20
19
  @raise_exceptions = raise_exceptions
21
- @current_path = path if path_exist?(path)
20
+ @current_path = path.sub(/\/+\Z/, '') if !path.nil? && path_exist?(path)
22
21
  end
23
22
 
24
23
  def execute(command, path=@current_path, message: [], stdout_source: :stdout, log_command: true, _raise_exceptions: @raise_exceptions)
@@ -51,10 +50,11 @@ module Deplomat
51
50
  self.stdout_lines_to_ignore.each do |line_to_ignore|
52
51
  line_to_ignore = line_to_ignore.to_a if line_to_ignore.kind_of?(Range)
53
52
  line_to_ignore = [line_to_ignore] if line_to_ignore.kind_of?(Integer)
54
- unless line_to_ignore.include?(i+1)
55
- out << line
56
- log(" #{line}") if log_command
57
- end
53
+ line = nil if line_to_ignore.include?(i+1)
54
+ end
55
+ if line
56
+ out << line
57
+ log(" #{line}") if log_command
58
58
  end
59
59
  end
60
60
 
@@ -122,11 +122,11 @@ module Deplomat
122
122
  @current_path = if path =~ /\A[\/~]/ || path.nil?
123
123
  path
124
124
  else
125
- File.expand_path("#{@current_path}#{path}")
125
+ File.expand_path("#{@current_path}/#{path}")
126
126
  end
127
127
 
128
- # Making sure we don't end up with double // at the end of the path
129
- @current_path = @current_path.chomp("/") + "/"
128
+ # Remove / from the end of the current path
129
+ @current_path.sub!(/\/+\Z/, '')
130
130
  end
131
131
 
132
132
  def git_push(remote="origin", branch="master")
@@ -183,7 +183,7 @@ module Deplomat
183
183
  entries_by_date.reverse! if leave[1] == :first
184
184
  entries_by_date = entries_by_date[leave[0]..entries_by_date.length]
185
185
  end
186
- entries_by_date.each { |entry| remove("#{path}#{entry}") } if entries_by_date
186
+ entries_by_date.each { |entry| remove("#{path}/#{entry}") } if entries_by_date
187
187
  end
188
188
  end
189
189
 
@@ -24,8 +24,7 @@ module Deplomat
24
24
  end
25
25
  @pids.compact!
26
26
  if @pids.empty?
27
- log("ERROR: no ssh pid found for\n\t#{first_ssh_command}.\nThis is weird.", color: "red")
28
- exit 1
27
+ raise Deplomat::ExecutionError.new("ERROR: no ssh pid found for\n\t#{first_ssh_command}.\nThis is weird.")
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")
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.11
4
+ version: 0.2.16
5
5
  platform: ruby
6
6
  authors:
7
- - Roman Snitko
7
+ - romanitup
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-16 00:00:00.000000000 Z
11
+ date: 2020-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: sys-proctable
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: colorize
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: '1.0'
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: '1.0'
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: roman.snitko@gmail.com
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
- - spec/deployment_requisites/1_req.rb
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,8 +109,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
109
  - !ruby/object:Gem::Version
139
110
  version: '0'
140
111
  requirements: []
141
- rubygems_version: 3.0.3
112
+ rubygems_version: 3.1.2
142
113
  signing_key:
143
114
  specification_version: 4
144
- summary: Stack agnostic deployment system that uses bash and ssh commands
115
+ summary: Deplomat
145
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
@@ -1,3 +0,0 @@
1
- before_task(:task1, 1) do
2
- $deployment_requisites_test_file1 = true
3
- end
@@ -1,3 +0,0 @@
1
- before_task(:task2, 2) do
2
- $deployment_requisites_test_file2 = true
3
- end
File without changes
@@ -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
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -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
@@ -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
@@ -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
@@ -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