deplomat 0.1.1 → 0.1.3

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
  SHA1:
3
- metadata.gz: 67aed2b09a78c6ff894531f065ba7db0bdc60e20
4
- data.tar.gz: 848f9cba73c651699f2496b5b871448fbc15fcb6
3
+ metadata.gz: 19c9e18dffd7b609ac6fa97ed1dfba3657dac02f
4
+ data.tar.gz: 56669fbf77b52f128336a5e2195df31bfc12dc9f
5
5
  SHA512:
6
- metadata.gz: 7723cc145303719df54eb436a43a012b02e5180ab8fc56d08d121fe3ec1ed6a4b1fffa8befa7dd4d4cb22db0178e9d214e480b4884a062ebe4b5a42357f1eb2e
7
- data.tar.gz: 6298c99481b28878c15763b0aeed01e99697c3621a677f35027cedb50410f9faaae0ab4f526e753be48d6741acbedd56f214d56f8c3422eef3c3252be32684d3
6
+ metadata.gz: 9aab773fa6a23eb5025dcd73bc83ab614d1c4e4c463bd436e3ed42d20ca81625abb9c25ff65be28b8c04b8f0b19815ffc5123726c5cb11c0140139a8378f333c
7
+ data.tar.gz: 3264cff003a6f8b327e98a516d97ee49b51aa8753035e003bacfbb42664b6844cf21cf0920f4aa487c52e369fbc95f638b941696d8e4bfa134d998e144b59fa9
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.3
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: deplomat 0.1.1 ruby lib
5
+ # stub: deplomat 0.1.3 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "deplomat"
9
- s.version = "0.1.1"
9
+ s.version = "0.1.3"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Roman Snitko"]
14
- s.date = "2016-07-05"
14
+ s.date = "2017-04-12"
15
15
  s.description = "Stack agnostic deployment system that uses bash and ssh commands"
16
16
  s.email = "roman.snitko@gmail.com"
17
17
  s.extra_rdoc_files = [
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
27
27
  "README.rdoc",
28
28
  "Rakefile",
29
29
  "VERSION",
30
+ "deplomat.gemspec",
30
31
  "examples/simple_deploy.rb",
31
32
  "lib/deplomat.rb",
32
33
  "lib/deplomat/directives.rb",
@@ -38,6 +39,7 @@ Gem::Specification.new do |s|
38
39
  "spec/fixtures/cleaning/.keep",
39
40
  "spec/fixtures/dir1/file1",
40
41
  "spec/fixtures/dir1/file2",
42
+ "spec/fixtures/upload1/except1",
41
43
  "spec/fixtures/upload1/uploaded_file1",
42
44
  "spec/fixtures/upload1/uploaded_file2",
43
45
  "spec/local_node_spec.rb",
@@ -2,6 +2,10 @@ module Deplomat
2
2
 
3
3
  class LocalNode < Node
4
4
 
5
+ def initialize(logfile: "#{Dir.pwd}/deplomat.log", log_to: [:stdout], path: Dir.pwd, raise_exceptions: true)
6
+ super
7
+ end
8
+
5
9
  private
6
10
 
7
11
  def path_exist?(path)
@@ -5,9 +5,11 @@ module Deplomat
5
5
  attr_accessor :log_to, :raise_exceptions, :logfile
6
6
  attr_reader :current_path
7
7
 
8
- def initialize(logfile: "#{Dir.pwd}/deplomat.log", log_to: [:stdout])
9
- @log_to = log_to
10
- @logfile = logfile
8
+ def initialize(logfile: "#{Dir.pwd}/deplomat.log", log_to: [:stdout], path: nil, raise_exceptions: true)
9
+ @log_to = log_to
10
+ @logfile = logfile
11
+ @raise_exceptions = raise_exceptions
12
+ self.cd(path) if path
11
13
  end
12
14
 
13
15
  def execute(command, path=@current_path, message: [], stdout_source: :stdout, log_command: true)
@@ -45,7 +47,7 @@ module Deplomat
45
47
  log(error_out + "\n", color: 'red')
46
48
  if @raise_exceptions
47
49
  self.close if self.respond_to?(:close)
48
- raise Deplomat::ExecutionError
50
+ raise Deplomat::ExecutionError
49
51
  end
50
52
  end
51
53
  yield if block_given?
@@ -99,7 +101,7 @@ module Deplomat
99
101
  end
100
102
 
101
103
  def git_push(remote="origin", branch="master")
102
- execute("git push -u #{remote} #{branch}")
104
+ execute("git push #{remote} #{branch}")
103
105
  end
104
106
 
105
107
  def git_pull(remote="origin", branch="master")
@@ -126,13 +128,13 @@ module Deplomat
126
128
  entries_by_date.each { |entry| remove("#{path}#{entry}") }
127
129
  end
128
130
 
129
- private
131
+ def log(line, color: 'light_black')
132
+ @message_color = color
133
+ # Only calls log methods mentioned in the @log_to property
134
+ @log_to.each { |logger| self.send("log_to_#{logger}", line) }
135
+ end
130
136
 
131
- def log(line, color: 'light_black')
132
- @message_color = color
133
- # Only calls log methods mentioned in the @log_to property
134
- @log_to.each { |logger| self.send("log_to_#{logger}", line) }
135
- end
137
+ private
136
138
 
137
139
  def log_to_file(line)
138
140
  if @logfile
@@ -1,8 +1,8 @@
1
1
  module Deplomat
2
2
  class RemoteNode < Node
3
3
 
4
- def initialize(host:, port: 22, user: "deploy")
5
- super()
4
+ def initialize(host:, port: 22, user: "deploy", raise_exceptions: true)
5
+ super(logfile: '~/deplomat.log')
6
6
 
7
7
  # Create ControlMasters dir, user might not have it
8
8
  unless File.exists?("#{ENV['HOME']}/.ssh/controlmasters/")
@@ -30,16 +30,17 @@ module Deplomat
30
30
  end
31
31
 
32
32
  alias :local_execute :execute
33
- def execute(command, path=@current_path, message: [], env_vars: '', login_shell: false, stdout_source: :stdout)
33
+ def execute(command, path=@current_path, message: [], env_vars: '', login_shell: false, stdout_source: :stdout, log_command: true)
34
34
 
35
- log("(#{@host}) --> " + command + "\n", color: "white")
35
+ log("(#{@host}) --> " + command + "\n", color: "white") if log_command
36
36
  command = "#{env_vars} cd #{path} && #{command}" if path
37
37
  command = "bash -l -c \"#{command}\"" if login_shell
38
38
  super("#{@ssh_command} '#{command}'", nil, message: message, stdout_source: stdout_source, log_command: false)
39
39
  end
40
40
 
41
- def upload(what, where)
42
- local_execute "rsync -arz #{what} #{@user}@#{@host}:#{where} --port=#{@port}"
41
+ def upload(what, where, except: nil)
42
+ except = "--exclude '#{except}'" if except
43
+ local_execute "rsync -arzve 'ssh -p #{@port}' #{except} --delete #{what} #{@user}@#{@host}:#{where}", nil
43
44
  end
44
45
 
45
46
  def close
@@ -56,7 +57,7 @@ module Deplomat
56
57
  def path_exist?(path)
57
58
  old_raise_exceptions = @raise_exceptions
58
59
  @raise_exceptions = false
59
- !(execute("ls #{path}", nil){ @raise_exceptions = old_raise_exceptions}[:status] > 0)
60
+ !(execute("ls #{path}", nil, log_command: false){ @raise_exceptions = old_raise_exceptions}[:status] > 0)
60
61
  end
61
62
 
62
63
  end
File without changes
@@ -48,8 +48,9 @@ describe Deplomat::RemoteNode do
48
48
  end
49
49
 
50
50
  it "uploads files from localhost to the node" do
51
- @node.upload("#{@local_fixtures_dir}/upload1/*", "#{@fixtures_dir}/uploaded1/")
51
+ @node.upload("#{@local_fixtures_dir}/upload1/*", "#{@fixtures_dir}/uploaded1/", except: 'except1')
52
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")
53
54
  end
54
55
 
55
56
  it "changes current directory" do
@@ -81,6 +82,12 @@ describe Deplomat::RemoteNode do
81
82
  expect(@node.execute("ls dir1")[:out]).to have_files("file1", "file2", "subdir1")
82
83
  end
83
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
+
84
91
  end
85
92
 
86
93
  describe "handling status and errors" do
@@ -15,3 +15,17 @@ RSpec::Matchers.define :have_files do |*expected|
15
15
  "expected these files in the directory:\n\t#{actual.split("\n").inspect}\nwould include all of these:\n\t#{expected.inspect}"
16
16
  end
17
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
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deplomat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman Snitko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-05 00:00:00.000000000 Z
11
+ date: 2017-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sys-proctable
@@ -108,6 +108,7 @@ files:
108
108
  - spec/fixtures/cleaning/.keep
109
109
  - spec/fixtures/dir1/file1
110
110
  - spec/fixtures/dir1/file2
111
+ - spec/fixtures/upload1/except1
111
112
  - spec/fixtures/upload1/uploaded_file1
112
113
  - spec/fixtures/upload1/uploaded_file2
113
114
  - spec/local_node_spec.rb