depengine 3.0.20 → 3.0.21

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +8 -0
  3. data/.rubocop_todo.yml +52 -0
  4. data/Gemfile.lock +16 -1
  5. data/Rakefile +9 -9
  6. data/bin/cdb_crypt +2 -2
  7. data/bin/de +1 -1
  8. data/bin/depengine +2 -2
  9. data/bin/spec_setup +2 -2
  10. data/depengine.gemspec +22 -21
  11. data/lib/depengine/asserter/url.rb +8 -9
  12. data/lib/depengine/cli.rb +12 -14
  13. data/lib/depengine/dsl/cdb.rb +16 -17
  14. data/lib/depengine/dsl/deployment.rb +42 -50
  15. data/lib/depengine/dsl/dweb.rb +10 -11
  16. data/lib/depengine/dsl/executor.rb +5 -5
  17. data/lib/depengine/dsl/fileops.rb +3 -4
  18. data/lib/depengine/dsl/helper.rb +26 -28
  19. data/lib/depengine/dsl/iis.rb +21 -24
  20. data/lib/depengine/dsl/patch.rb +22 -46
  21. data/lib/depengine/dsl/publisher.rb +14 -14
  22. data/lib/depengine/dsl/remote.rb +11 -13
  23. data/lib/depengine/dsl/repository.rb +19 -21
  24. data/lib/depengine/dsl/template.rb +19 -19
  25. data/lib/depengine/dsl/zip.rb +24 -24
  26. data/lib/depengine/helper/cli_helper.rb +9 -11
  27. data/lib/depengine/helper/hudson.rb +15 -19
  28. data/lib/depengine/helper/mail.rb +19 -25
  29. data/lib/depengine/helper/properties.rb +33 -52
  30. data/lib/depengine/helper/smb.rb +19 -25
  31. data/lib/depengine/helper/validations.rb +7 -7
  32. data/lib/depengine/helper/yaml.rb +7 -9
  33. data/lib/depengine/log/log.rb +3 -6
  34. data/lib/depengine/processor/erb_template.rb +42 -47
  35. data/lib/depengine/processor/fileops.rb +39 -48
  36. data/lib/depengine/processor/local_execute.rb +6 -4
  37. data/lib/depengine/processor/properties.rb +34 -56
  38. data/lib/depengine/processor/sed.rb +8 -12
  39. data/lib/depengine/processor/tags.rb +9 -10
  40. data/lib/depengine/processor/template.rb +27 -32
  41. data/lib/depengine/processor/zip.rb +16 -20
  42. data/lib/depengine/provider/cdb.rb +64 -71
  43. data/lib/depengine/provider/cdb_filesystem.rb +18 -26
  44. data/lib/depengine/provider/git.rb +37 -42
  45. data/lib/depengine/provider/repository.rb +161 -176
  46. data/lib/depengine/publisher/dweb.rb +74 -90
  47. data/lib/depengine/publisher/iis.rb +23 -30
  48. data/lib/depengine/publisher/rsync.rb +14 -17
  49. data/lib/depengine/publisher/samba.rb +12 -14
  50. data/lib/depengine/publisher/sftp.rb +51 -61
  51. data/lib/depengine/publisher/ssh.rb +19 -22
  52. data/lib/depengine/publisher/tomcat.rb +19 -21
  53. data/lib/depengine/reporter/cdb.rb +2 -3
  54. data/lib/depengine/version.rb +1 -1
  55. data/lib/depengine.rb +1 -2
  56. data/spec/cdb_spec.rb +8 -10
  57. data/spec/demo_recipe/recipes/demo.rb +10 -10
  58. data/spec/deployhelper_spec.rb +20 -21
  59. data/spec/fileops_spec.rb +11 -12
  60. data/spec/git_spec.rb +8 -4
  61. data/spec/helper_spec.rb +75 -75
  62. data/spec/junit.rb +47 -49
  63. data/spec/local_execute.rb +7 -7
  64. data/spec/log_spec.rb +17 -18
  65. data/spec/properties_spec.rb +13 -15
  66. data/spec/recipe_spec.rb +15 -16
  67. data/spec/repository_spec.rb +20 -20
  68. data/spec/ssh_spec.rb +18 -19
  69. data/spec/template_spec.rb +30 -30
  70. data/spec/zip_spec.rb +7 -7
  71. metadata +18 -2
@@ -3,47 +3,47 @@ module Provider
3
3
  attr_accessor :repository_url
4
4
  attr_accessor :repository_local_dir
5
5
 
6
- def fetch(options={})
7
- Helper.validates_presence_of repository_url, "repository_url not set"
8
- Helper.validates_presence_of repository_local_dir, "repository_local_dir not set"
6
+ def fetch(_options = {})
7
+ Helper.validates_presence_of repository_url, 'repository_url not set'
8
+ Helper.validates_presence_of repository_local_dir, 'repository_local_dir not set'
9
9
 
10
10
  # Make sure directory exists
11
- if not File.exists? repository_local_dir
11
+ unless File.exist? repository_local_dir
12
12
  FileUtils.mkdir_p(repository_local_dir)
13
13
  end
14
14
 
15
15
  # Fetch (or clone)
16
16
  Dir.chdir(repository_local_dir) do
17
- if not File.exists? ".git"
18
- $log.writer.info "Clone git repository"
17
+ if !File.exist? '.git'
18
+ $log.writer.info 'Clone git repository'
19
19
  shell_cmd = "git clone #{repository_url} ."
20
20
  output = system shell_cmd
21
- if not output
21
+ unless output
22
22
  current_directory = Dir.getwd
23
23
  $log.writer.error "Unable to clone repository #{repository_url} into #{current_directory}"
24
24
  exit 1
25
25
  end
26
26
  else
27
- $log.writer.info "Fetch git repository"
28
- shell_cmd = "git fetch origin"
27
+ $log.writer.info 'Fetch git repository'
28
+ shell_cmd = 'git fetch origin'
29
29
  output = system shell_cmd
30
- if not output
31
- $log.writer.error "Unable to fetch from origin"
30
+ unless output
31
+ $log.writer.error 'Unable to fetch from origin'
32
32
  exit 1
33
33
  end
34
34
  end
35
- end
35
+ end
36
36
  end
37
37
 
38
- def checkout(branch_name, options={})
39
- Helper.validates_presence_of repository_url, "repository_url not set"
40
- Helper.validates_presence_of repository_local_dir, "repository_local_dir not set"
38
+ def checkout(branch_name, _options = {})
39
+ Helper.validates_presence_of repository_url, 'repository_url not set'
40
+ Helper.validates_presence_of repository_local_dir, 'repository_local_dir not set'
41
41
 
42
42
  Dir.chdir(repository_local_dir) do
43
43
  # Pull
44
- shell_cmd = "git pull origin master"
44
+ shell_cmd = 'git pull origin master'
45
45
  output = system shell_cmd
46
- if not output
46
+ unless output
47
47
  $log.writer.error "Unable to pull branch #{branch_name}"
48
48
  exit 1
49
49
  end
@@ -51,56 +51,53 @@ module Provider
51
51
  # Checkout
52
52
  shell_cmd = "git checkout -f #{branch_name}"
53
53
  output = system shell_cmd
54
- if not output
54
+ unless output
55
55
  $log.writer.error "Unable to checkout branch #{branch_name}"
56
56
  exit 1
57
57
  end
58
58
  end
59
59
  end
60
60
 
61
- def submodule(submodule_option, options={})
62
- Helper.validates_presence_of repository_url, "repository_url not set"
63
- Helper.validates_presence_of repository_local_dir, "repository_local_dir not set"
61
+ def submodule(submodule_option, _options = {})
62
+ Helper.validates_presence_of repository_url, 'repository_url not set'
63
+ Helper.validates_presence_of repository_local_dir, 'repository_local_dir not set'
64
64
 
65
65
  Dir.chdir(repository_local_dir) do
66
66
  # Submodule init
67
- shell_cmd = "git submodule init"
68
- output = system shell_cmd
69
-
67
+ shell_cmd = 'git submodule init'
68
+ system(shell_cmd)
69
+
70
70
  # git submodule update --recursive
71
71
  shell_cmd = "git submodule update #{submodule_option}"
72
72
  output = system shell_cmd
73
- if not output
74
- $log.writer.error "Unable to pull submodule"
73
+ unless output
74
+ $log.writer.error 'Unable to pull submodule'
75
75
  exit 1
76
76
  end
77
77
  end
78
78
  end
79
79
 
80
-
81
- def tag(tag_name, options={})
82
- Helper.validates_presence_of repository_url, "repository_url not set"
83
- Helper.validates_presence_of repository_local_dir, "repository_local_dir not set"
80
+ def tag(tag_name, options = {})
81
+ Helper.validates_presence_of repository_url, 'repository_url not set'
82
+ Helper.validates_presence_of repository_local_dir, 'repository_local_dir not set'
84
83
 
85
84
  Dir.chdir(repository_local_dir) do
86
85
  # Create tag
87
86
  shell_cmd = "git tag #{tag_name}"
88
- if not options[:hash].nil?
89
- shell_cmd << " #{options[:hash]}"
90
- end
87
+ shell_cmd << " #{options[:hash]}" if options[:hash]
91
88
 
92
89
  output = system shell_cmd
93
- if not output
90
+ unless output
94
91
  $log.writer.error "Unable to create tag #{tag_name}"
95
- exit 1
92
+ fail "Unable to create tag #{tag_name}"
96
93
  end
97
94
 
98
95
  # Push tag
99
- shell_cmd = "git push -f --tags origin"
96
+ shell_cmd = 'git push -f --tags origin'
100
97
  output = system shell_cmd
101
- if not output
102
- $log.writer.error "Unable to push to origin"
103
- exit 1
98
+ unless output
99
+ $log.writer.error 'Unable to push to origin'
100
+ fail 'Unable to push to origin'
104
101
  end
105
102
  end
106
103
  end
@@ -111,14 +108,12 @@ module Provider
111
108
  # * +:r2+ - Include commits that are reachable from r2
112
109
  # * +:r1+ - but exclude those that are reachable from r1.
113
110
  # Please see `GITREVISIONS(7)` for more info on how to specify a revision range.
114
- def history(r1='',r2='HEAD')
111
+ def history(r1 = '', r2 = 'HEAD')
115
112
  rev_range = r1.empty? ? '' : "#{r1}..#{r2}"
116
113
 
117
114
  Dir.chdir(@repository_local_dir) do
118
115
  Processor.local_execute(["git log --oneline #{rev_range}"])
119
116
  end
120
117
  end
121
-
122
118
  end
123
119
  end
124
-
@@ -1,202 +1,187 @@
1
1
  module Provider
2
- class Repository
3
-
4
- attr_accessor :repository
5
- attr_accessor :worker
6
- attr_accessor :method
7
- attr_accessor :user
8
- attr_accessor :password
9
- attr_accessor :host
10
- attr_accessor :sshkey
11
- attr_accessor :svnbinary
12
- attr_accessor :svncmd
13
- attr_accessor :samba_mountpoints
14
-
15
- def initialize()
16
- repository = ""
17
- method = ""
18
- user = ""
19
- password = ""
20
- host = ""
21
- sshkey = ""
22
- svnbinary = ""
23
- svncmd = ""
24
- samba_mountpoints = ""
2
+ class Repository
3
+ attr_accessor :repository
4
+ attr_accessor :worker
5
+ attr_accessor :method
6
+ attr_accessor :user
7
+ attr_accessor :password
8
+ attr_accessor :host
9
+ attr_accessor :sshkey
10
+ attr_accessor :svnbinary
11
+ attr_accessor :svncmd
12
+ attr_accessor :samba_mountpoints
13
+
14
+ def initialize
15
+ @repository = ''
16
+ @method = ''
17
+ @user = ''
18
+ @password = ''
19
+ @host = ''
20
+ @sshkey = ''
21
+ @svnbinary = ''
22
+ @svncmd = ''
23
+ @samba_mountpoints = ''
25
24
  end
26
25
 
27
-
28
- def get_from_repository(from, to)
29
-
30
-
31
- ### get from maven
32
- if method == "maven"
33
- res = nil
34
- response = nil
35
- req = nil
36
-
37
- target = to
38
- string_array = from.split('/')
39
- file_name = string_array[string_array.length - 1]
40
- target = target << "/" if target[target.length - 1,1] != "/"
41
- target = target + file_name
26
+ def get_from_maven(from, to)
27
+ response = nil
28
+ req = nil
29
+ target = to
30
+ string_array = from.split('/')
31
+ file_name = string_array[string_array.length - 1]
32
+ target = target << '/' if target[target.length - 1, 1] != '/'
33
+ target = target + file_name
34
+
35
+ #### create target directory
36
+ unless File.directory?(to)
37
+ unless FileUtils.mkdir_p(to)
38
+ $log.writer.error "Unable to create directory #{to}"
39
+ exit 1
40
+ end
41
+ end
42
+
43
+ url = URI.parse(repository + from)
44
+ http = Net::HTTP.new(url.host, url.port)
45
+ if url.scheme == 'https'
46
+ http.use_ssl = true
47
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
48
+ end
42
49
 
43
- #### create target directory
44
- if not File.directory?(to)
45
- if not FileUtils.mkdir_p(to)
46
- $log.writer.error "Unable to create directory #{to}"
50
+ begin
51
+ http.start do |connection|
52
+ req = Net::HTTP::Get.new(url.path)
53
+ # req.basic_auth user, password
54
+ response = connection.request(req)
55
+ body = response.body
56
+
57
+ case response
58
+ when Net::HTTPSuccess
59
+ # OK
60
+ File.open(target, 'w') { |f| f.write body }
61
+ else
62
+ $log.writer.error 'Can not get file from ' + url.scheme + '://' + url.host + url.path
47
63
  exit 1
48
64
  end
49
65
  end
50
-
51
- url = URI.parse(repository + from)
52
- http = Net::HTTP.new(url.host, url.port)
53
- if url.scheme == 'https'
54
- http.use_ssl = true
55
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
56
- end
57
- begin
58
- http.start do |http|
59
- req = Net::HTTP::Get.new(url.path)
60
- #req.basic_auth user, password
61
- response = http.request(req)
62
- body = response.body
63
-
64
- case response
65
- when Net::HTTPSuccess
66
- # OK
67
- File.open(target, 'w') {|f|
68
- f.write body
69
- }
70
- else
71
- $log.writer.error "Can not get file from " + url.scheme + "://" + url.host + url.path
72
- exit 1
73
- end
74
- end
75
- rescue Exception => e
76
- $log.writer.error "Can not make a HTTP connection to #{url.host}"
66
+ rescue
67
+ $log.writer.error "Can not make a HTTP connection to #{url.host}"
68
+ exit 1
69
+ end
70
+ end
71
+
72
+ def get_from_scp(from, to)
73
+ unless File.file? sshkey
74
+ $log.writer.error "Keyfile #{File.expand_path sshkey} does not exists"
75
+ exit 1
76
+ end
77
+
78
+ #### create target directory
79
+ unless File.directory?(to)
80
+ unless FileUtils.mkdir_p(to)
81
+ $log.writer.error "Unable to create directory #{to}"
77
82
  exit 1
78
83
  end
79
- end
84
+ end
80
85
 
81
- ### get via scp
82
- if method == "scp"
86
+ begin
87
+ Net::SCP.start(host, user, keys: [sshkey], host_key: 'ssh-rsa', auth_methods: ['publickey']) do |scp|
88
+ scp.download!(from, to, recursive: true)
89
+ end
90
+ rescue => e
91
+ $log.writer.error "Can not copy #{host}:#{from} to #{to}"
92
+ $log.writer.error e.message
93
+ exit 1
94
+ end
95
+ end
83
96
 
84
- if not File.file? sshkey
85
- $log.writer.error "Keyfile #{File.expand_path sshkey} does not exists"
86
- exit 1
87
- end
97
+ def get_from_svn(from, to)
98
+ ### svn command not set
99
+ if svncmd.empty?
100
+ $log.writer.error 'No svn command defined'
101
+ exit 1
102
+ end
88
103
 
89
- #### create target directory
90
- if not File.directory?(to)
91
- if not FileUtils.mkdir_p(to)
92
- $log.writer.error "Unable to create directory #{to}"
93
- exit 1
94
- end
95
- end
96
-
97
- begin
98
- Net::SCP.start(host, user, :keys => [ sshkey ], :host_key => "ssh-rsa", :auth_methods => [ "publickey" ]) do |scp|
99
- scp.download!(from, to, :recursive => true)
100
- end
101
- rescue Exception => e
102
- $log.writer.error "Can not copy #{host}:#{from} to #{to}"
103
- $log.writer.error e.message
104
- exit 1
105
- end
106
- end
107
-
108
- ### get from svn
109
- if method == "svn"
110
-
111
- ### svn command not set
112
- if svncmd.empty?
113
- $log.writer.error "No svn command defined"
104
+ ### get svn info (file or directory
105
+ shell_cmd = create_svn_cmd('info', from, '')
106
+ output = `#{shell_cmd}`
107
+ doc = REXML::Document.new output
108
+ root = doc.root
109
+ target = to
110
+ if root.elements['/info/entry'].attributes['kind'] == 'fil e'
111
+ string_array = from.split('/ ')
112
+ file_name = string_array[string_array.length - 1]
113
+ target = target << '/' if target[target.length - 1, 1] != ' /'
114
+ target = target + file_name
115
+ end
116
+
117
+ #### create target directory
118
+ unless File.directory?(to)
119
+ unless FileUtils.mkdir_p(to)
120
+ $log.writer.error "Unable to create directory #{to}"
114
121
  exit 1
115
122
  end
116
-
117
- ### get svn info (file or directory
118
- shell_cmd = create_svn_cmd('info',from,"")
119
- output = %x[#{shell_cmd}]
120
- doc = REXML::Document.new output
121
- root = doc.root
122
- target = to
123
- if root.elements["/info/entry"].attributes["kind"] == "file"
124
- string_array = from.split('/')
125
- file_name = string_array[string_array.length - 1]
126
- target = target << "/" if target[target.length - 1,1] != "/"
127
- target = target + file_name
128
- end
129
-
130
- #### create target directory
131
- if not File.directory?(to)
132
- if not FileUtils.mkdir_p(to)
133
- $log.writer.error "Unable to create directory #{to}"
134
- exit 1
135
- end
123
+ end
124
+
125
+ shell_cmd = create_svn_cmd(svncmd, from, target)
126
+ $log.writer.debug "Execute command: #{shell_cmd}"
127
+ output = system shell_cmd
128
+ return if output
129
+ $log.writer.error "svn #{svncmd} failed"
130
+ fail "svn #{svncmd} failed"
131
+ end
132
+
133
+ def get_from_samba(from, to)
134
+ #### create target directory
135
+ unless File.directory?(to)
136
+ unless FileUtils.mkdir_p(to)
137
+ $log.writer.error "Unable to create target directory #{to}"
138
+ fail "Unable to create target directory #{to}"
136
139
  end
137
-
138
- shell_cmd = create_svn_cmd(svncmd,from,target)
140
+ end
141
+ begin
142
+ worker.samba_mount(repository, "#{samba_mountpoints}/#{repository}")
143
+
144
+ # local rsync
145
+ shell_cmd = "rsync -va --delete #{samba_mountpoints}/#{repository}/#{from}/ #{to}"
139
146
  $log.writer.debug "Execute command: #{shell_cmd}"
140
147
  output = system shell_cmd
141
- if not output
142
- $log.writer.error "svn #{svncmd} failed"
143
- exit 1
148
+ unless output
149
+ $log.writer.error "#{method} #{shell_cmd} failed"
150
+ fail "#{method} #{shell_cmd} failed"
144
151
  end
152
+ $log.writer.info output
145
153
 
146
- end
147
- if method == "samba"
148
- #### create target directory
149
- if not File.directory?(to)
150
- if not FileUtils.mkdir_p(to)
151
- $log.writer.error "Unable to create target directory #{to}"
152
- exit 1
153
- end
154
- end
155
- begin
156
- worker.samba_mount(repository,"#{samba_mountpoints}/#{repository}")
157
-
158
- # local rsync
159
- shell_cmd = "rsync -va --delete #{samba_mountpoints}/#{repository}/#{from}/ #{to}"
160
- $log.writer.debug "Execute command: #{shell_cmd}"
161
- output = system shell_cmd
162
- if not output
163
- $log.writer.error "#{method} #{shell_cmd} failed"
164
- exit 1
165
- end
166
- $log.writer.info output
167
-
168
- # umount
169
- worker.samba_umount("#{samba_mountpoints}/#{repository}")
170
-
171
- rescue Exception => e
172
- $log.writer.error "Can not provide files using #{method}"
173
- $log.writer.error e.message
174
- $log.writer.error e.backtrace.join("\n")
175
- worker.samba_umount("#{samba_mountpoints}/#{repository}")
176
- exit 1
177
- end
178
- end
179
- end
154
+ # umount
155
+ worker.samba_umount("#{samba_mountpoints}/#{repository}")
180
156
 
181
- ### create svn command
182
- def create_svn_cmd(svncmd,from,target)
183
- shell_cmd = svnbinary + " " + svncmd
184
- shell_cmd = shell_cmd + " --force" if svncmd == "checkout" or svncmd == "export"
185
- shell_cmd = shell_cmd + " --xml" if svncmd == "info"
186
-
157
+ rescue => e
158
+ $log.writer.error "Can not provide files using #{method}"
159
+ $log.writer.error e.message
160
+ $log.writer.error e.backtrace.join("\n")
161
+ worker.samba_umount("#{samba_mountpoints}/#{repository}")
162
+ exit 1
163
+ end
164
+ end
187
165
 
188
- if not user.empty? and not password.empty?
189
- shell_cmd = shell_cmd + " --username " + user + \
190
- " --password " + password
191
- end
166
+ def get_from_repository(from, to)
167
+ get_from_maven(from, to) if method == 'maven'
168
+ get_from_scp(from, to) if method == 'scp'
169
+ get_from_svn(from, to) if method == 'svn'
170
+ get_from_samba(from, to) if method == 'samba'
171
+ end
172
+
173
+ def create_svn_cmd(svncmd, from, target)
174
+ shell_cmd = svnbinary + ' ' + svncmd
175
+ shell_cmd = shell_cmd + ' --force' if svncmd == 'checkout' or svncmd == 'export'
176
+ shell_cmd = shell_cmd + ' --xml' if svncmd == 'info'
192
177
 
193
- shell_cmd = shell_cmd + " " + repository + "/" + from
194
- if svncmd =~ /^checkout/ or svncmd =~ /^export/
195
- shell_cmd = shell_cmd + " " + target.to_s
178
+ if not user.empty? and not password.empty?
179
+ shell_cmd = shell_cmd + ' --username ' + user + \
180
+ ' --password ' + password
196
181
  end
197
- return shell_cmd
198
- end
199
182
 
183
+ shell_cmd = shell_cmd + ' ' + repository + '/' + from
184
+ shell_cmd = shell_cmd + ' ' + target.to_s if svncmd =~ /^checkout/ or svncmd =~ /^export/ # rubocop:disable Lint/UselessAssignment
185
+ end
200
186
  end
201
187
  end
202
-