cicd-builder 0.9.31 → 0.9.32
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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/cicd/builder/mixlib/errors.rb +2 -0
- data/lib/cicd/builder/mixlib/repo/artifactory.rb +129 -66
- data/lib/cicd/builder/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d5b439d8599dc11343c4a867ba4395425a5bc2f
|
4
|
+
data.tar.gz: c179de346efe4964da6bfa8a88f11eb03fa52fad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48e143c0e1d50ab196f574b0fd7981b53dfc95d6ad7f4bcb9df48ce591b706c3c13de2ae19e80609b4944d002977091696c79f89df585945ec76b27306adca46
|
7
|
+
data.tar.gz: a5e8d8f8482081068b22d2e2412730514b8930847657fca4f8d1d2ecbd6960d3feb0b3e4a9066494adaa8fca88055bf82c542a913db0f74c2c0b840eb2295c4d
|
data/Gemfile.lock
CHANGED
@@ -75,17 +75,15 @@ module CiCd
|
|
75
75
|
end
|
76
76
|
# matrix = properties.map{|k,v| (v.nil? or v.empty?) ? nil : "#{k}=#{v}"}.join("\;").gsub(%r'^\;*(.*?)\;*$', '\1')
|
77
77
|
# @client.endpoint += ";#{matrix}"
|
78
|
-
manifest = {}
|
78
|
+
@manifest = {}
|
79
79
|
artifacts.each{|art|
|
80
80
|
data = art[:data]
|
81
|
-
objects = maybeArtifactoryObject(data)
|
82
|
-
upload = false
|
83
81
|
if data.has_key?(:data)
|
84
82
|
tempArtifactFile("manifest-#{data[:name]}", data)
|
85
83
|
end
|
86
84
|
if data.has_key?(:file)
|
87
|
-
sha1 = Digest::SHA1.file(data[:file]).hexdigest
|
88
|
-
md5 = Digest::MD5.file(data[:file]).hexdigest
|
85
|
+
data[:sha1] = Digest::SHA1.file(data[:file]).hexdigest
|
86
|
+
data[:md5] = Digest::MD5.file(data[:file]).hexdigest
|
89
87
|
else
|
90
88
|
raise 'Artifact does not have file or data?'
|
91
89
|
end
|
@@ -103,91 +101,156 @@ module CiCd
|
|
103
101
|
if file_name =~ %r'\.+'
|
104
102
|
raise "Unable to parse out file name in #{data[:file]}"
|
105
103
|
end
|
106
|
-
unless file_name.empty?
|
107
|
-
file_name =
|
104
|
+
unless file_name.empty?
|
105
|
+
file_name = '_'+file_name.gsub(%r'^(\.|-|)(\w)', '\2').gsub(%r'(\.|-)+', '_')
|
108
106
|
end
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
# Check the checksum of the artifact
|
117
|
-
matched = false
|
118
|
-
objects.each do |artifact|
|
119
|
-
@logger.debug "\tChecking: #{artifact.attributes.ai} for #{artifact_path}"
|
120
|
-
if artifact.uri.match(%r'#{artifact_path}$')
|
121
|
-
matched = true
|
122
|
-
@logger.info "\tMatched: #{artifact.attributes.select{|k,_| k != :client}.ai}"
|
123
|
-
if artifact.md5 != md5 or artifact.sha1 != sha1
|
124
|
-
upload = true
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
|
-
upload ||= (not matched)
|
107
|
+
maybeUploadArtifactoryObject(data, data[:name], data[:version] || @vars[:version], file_ext, file_name) # -#{@vars[:variant]
|
108
|
+
break unless @vars[:return_code] == 0
|
109
|
+
}
|
110
|
+
if @vars[:return_code] == 0
|
111
|
+
manifest_data = ''
|
112
|
+
@manifest.each do |k,v|
|
113
|
+
manifest_data += "#{k}=#{v}\n"
|
129
114
|
end
|
115
|
+
data = { data: manifest_data, version: @vars[:build_ver], build: @vars[:build_num], properties: @properties_matrix }
|
116
|
+
tempArtifactFile('manifest', data)
|
117
|
+
data[:sha1] = Digest::SHA1.file(data[:file]).hexdigest
|
118
|
+
data[:md5 ] = Digest::MD5.file(data[:file]).hexdigest
|
119
|
+
data[:name] = artifactory_manifest_name
|
120
|
+
maybeUploadArtifactoryObject(data, artifactory_manifest_name, data[:version] || @vars[:version], 'properties', '') # -#{@vars[:variant]}
|
121
|
+
end
|
122
|
+
@vars[:return_code]
|
123
|
+
end
|
130
124
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
125
|
+
def maybeUploadArtifactoryObject(data, artifact_module, artifact_version, file_ext, file_name)
|
126
|
+
artifact_name = getArtifactName(data[:name], file_name, artifact_version, file_ext) # artifact_path = "#{artifactory_org_path()}/#{data[:name]}/#{data[:version]}-#{@vars[:variant]}/#{artifact_name}"
|
127
|
+
artifact_path = getArtifactPath(artifact_module, artifact_version, artifact_name)
|
128
|
+
objects = maybeArtifactoryObject(artifact_module, artifact_version, false)
|
129
|
+
upload = false
|
130
|
+
matched = []
|
131
|
+
if objects.nil? or objects.size == 0
|
132
|
+
upload = true
|
133
|
+
else
|
134
|
+
@logger.info "#{artifactory_endpoint()}/#{artifactory_repo()}/#{artifact_path} exists - #{objects.size} results"
|
135
|
+
@logger.info "\t#{objects.map{|o| o.attributes[:uri]}.join("\t")}"
|
136
|
+
matched = matchArtifactoryObjects(artifact_path, data, objects)
|
137
|
+
upload ||= (matched.size == 0)
|
138
|
+
end
|
139
|
+
if upload
|
140
|
+
properties_matrix = {}
|
141
|
+
data.select{|k,_| not k.to_s.eql?('file')}.each do |k,v|
|
142
|
+
properties_matrix["product.#{k}"] = v
|
139
143
|
end
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
+
data[:properties] = properties_matrix.merge(@properties_matrix)
|
145
|
+
objects = uploadArtifact(artifact_module, artifact_version, artifact_path, data)
|
146
|
+
matched = matchArtifactoryObjects(artifact_path, data, objects)
|
147
|
+
else
|
148
|
+
@logger.info "Keep existing #{matched.map{|o| o.attributes[:uri]}.join("\t")}"
|
144
149
|
end
|
145
|
-
data = { data: manifest_data, version: @vars[:build_ver], build: @vars[:build_num], properties: @properties_matrix }
|
146
|
-
tempArtifactFile('manifest', data)
|
147
|
-
sha1 = Digest::SHA1.file(data[:file]).hexdigest
|
148
|
-
md5 = Digest::MD5.file(data[:file]).hexdigest
|
149
|
-
artifact_name = "#{artifactory_manifest_name}-#{data[:version]}-#{data[:variant]}.properties"
|
150
|
-
artifact_path = "#{artifactory_org_path()}/#{artifactory_manifest_module}/#{data[:version]}-#{@vars[:variant]}/#{artifact_name}"
|
151
|
-
uploadArtifact(artifact_path, data, md5, sha1)
|
152
150
|
if data[:temp]
|
153
151
|
File.unlink(data[:file])
|
154
152
|
end
|
155
|
-
0
|
153
|
+
@vars[:return_code] = Errors::ARTIFACT_NOT_UPLOADED unless matched.size > 0
|
154
|
+
if @vars[:return_code] == 0
|
155
|
+
artifact_version += "-#{data[:build] || @vars[:build_num]}"
|
156
|
+
artifact_name = getArtifactName(artifact_module, file_name, artifact_version, file_ext, )
|
157
|
+
artifact_path = getArtifactPath(artifact_module, artifact_version, artifact_name)
|
158
|
+
copies = maybeArtifactoryObject(artifact_module, artifact_version, false)
|
159
|
+
matched = matchArtifactoryObjects(artifact_path, data, copies)
|
160
|
+
upload = (matched.size == 0)
|
161
|
+
if upload
|
162
|
+
objects.each do |artifact|
|
163
|
+
copied = copyArtifact(artifact_module, artifact_version, artifact_path, artifact)
|
164
|
+
unless copied.size > 0
|
165
|
+
@vars[:return_code] = Errors::ARTIFACT_NOT_COPIED
|
166
|
+
break
|
167
|
+
end
|
168
|
+
end
|
169
|
+
else
|
170
|
+
@logger.info "Keep existing #{matched.map{|o| o.attributes[:uri]}.join("\t")}"
|
171
|
+
end
|
172
|
+
@manifest[data[:name]] = artifact_version
|
173
|
+
end
|
174
|
+
|
175
|
+
@vars[:return_code]
|
176
|
+
end
|
177
|
+
|
178
|
+
def matchArtifactoryObjects(artifact_path, data, objects)
|
179
|
+
# matched = false
|
180
|
+
objects.select do |artifact|
|
181
|
+
@logger.debug "\tChecking: #{artifact.attributes.ai} for #{artifact_path}"
|
182
|
+
# if artifact.uri.match(%r'#{artifact_path}$')
|
183
|
+
# @logger.info "\tMatched: #{artifact.attributes.select { |k, _| k != :client }.ai}"
|
184
|
+
# end
|
185
|
+
matched = (artifact.md5.eql?(data[:md5]) or artifact.sha1.eql?(data[:sha1]))
|
186
|
+
matched
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
def getArtifactPath(artifact_module, artifact_version, artifact_name)
|
191
|
+
artifact_path = "#{artifactory_org_path()}/#{artifact_module}/#{artifact_version}/#{artifact_name}"
|
156
192
|
end
|
157
193
|
|
158
|
-
def
|
194
|
+
def getArtifactName(name, file_name, artifact_version, file_ext)
|
195
|
+
artifact_name = "#{name}#{artifact_version.empty? ? '' : "-#{artifact_version}"}.#{file_ext}" # #{file_name}
|
196
|
+
end
|
197
|
+
|
198
|
+
# ---------------------------------------------------------------------------------------------------------------
|
199
|
+
def maybeArtifactoryObject(artifact_name,artifact_version,wide=true)
|
200
|
+
begin
|
201
|
+
# Get a list of matching artifacts in this repository
|
202
|
+
result = @client.artifact_gavc_search(group: artifactory_org_path(), name: artifact_name, version: "#{artifact_version}", repos: [artifactory_repo()])
|
203
|
+
if result.size > 0
|
204
|
+
@logger.info "Artifactory gavc_search match g=#{artifactory_org_path()},a=#{artifact_name},v=#{artifact_version},r=#{artifactory_repo()}: #{result}"
|
205
|
+
# raise "GAVC started working: #{result.ai}"
|
206
|
+
elsif wide
|
207
|
+
@logger.warn 'GAVC search came up empty!'
|
208
|
+
result = @client.artifact_search(name: artifact_name, repos: [artifactory_repo()])
|
209
|
+
@logger.info "Artifactory search match a=#{artifact_name},r=#{artifactory_repo()}: #{result}"
|
210
|
+
end
|
211
|
+
result
|
212
|
+
rescue Exception => e
|
213
|
+
@logger.error "Artifactory error: #{e.class.name} #{e.message}"
|
214
|
+
raise e
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
def uploadArtifact(artifact_module, artifact_version, artifact_path, data)
|
159
219
|
data[:size] = File.size(data[:file])
|
160
|
-
@logger.info "[#{Time.now.strftime('%Y-%m-%d %H:%M:%S %z')}] Start upload #{artifact_path} = #{data[:size]} bytes"
|
161
220
|
artifact = ::Artifactory::Resource::Artifact.new(local_path: data[:file], client: @client)
|
162
221
|
# noinspection RubyStringKeysInHashInspection
|
163
222
|
artifact.checksums = {
|
164
|
-
'md5' => md5,
|
165
|
-
'sha1' => sha1
|
223
|
+
'md5' => data[:md5],
|
224
|
+
'sha1' => data[:sha1],
|
166
225
|
}
|
167
226
|
artifact.size = data[:size]
|
227
|
+
@logger.info "[#{Time.now.strftime('%Y-%m-%d %H:%M:%S %z')}] Start upload #{artifact_path} = #{data[:size]} bytes"
|
168
228
|
result = artifact.upload(artifactory_repo(), "#{artifact_path}", data[:properties] || {})
|
169
229
|
@logger.info "[#{Time.now.strftime('%Y-%m-%d %H:%M:%S %z')}] Uploaded: #{result.attributes.select { |k, _| k != :client }.ai}"
|
170
|
-
artifact.upload_checksum(artifactory_repo(), "#{artifact_path}", :sha1, sha1)
|
171
|
-
artifact.upload_checksum(artifactory_repo(), "#{artifact_path}", :md5,
|
172
|
-
objects = maybeArtifactoryObject(
|
230
|
+
artifact.upload_checksum(artifactory_repo(), "#{artifact_path}", :sha1, data[:sha1])
|
231
|
+
artifact.upload_checksum(artifactory_repo(), "#{artifact_path}", :md5, data[:md5])
|
232
|
+
objects = maybeArtifactoryObject(artifact_module, artifact_version, false)
|
233
|
+
unless objects.size > 0
|
234
|
+
objects = maybeArtifactoryObject(artifact_module, artifact_version, true)
|
235
|
+
end
|
173
236
|
raise "Failed to upload '#{artifact_path}'" unless objects.size > 0
|
237
|
+
objects
|
174
238
|
end
|
175
239
|
|
176
|
-
def
|
240
|
+
def copyArtifact(artifact_module, artifact_version, artifact_path, artifact)
|
177
241
|
begin
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
@logger.info "
|
182
|
-
|
183
|
-
|
184
|
-
@logger.warn 'GAVC search came up empty!'
|
185
|
-
result = @client.artifact_search(name: data[:name], repos: [artifactory_repo()])
|
186
|
-
@logger.info "Artifactory search match a=#{data[:name]},r=#{artifactory_repo()}: #{result}"
|
242
|
+
if artifact.attributes[:uri].eql?(File.join(artifactory_endpoint, artifactory_repo, artifact_path))
|
243
|
+
@logger.info "Not copying (identical artifact): #{artifact_path}"
|
244
|
+
else
|
245
|
+
@logger.info "[#{Time.now.strftime('%Y-%m-%d %H:%M:%S %z')}] Start copy #{artifact_path} = #{artifact.attributes[:size]} bytes"
|
246
|
+
result = artifact.copy("#{artifactory_repo()}/#{artifact_path}")
|
247
|
+
@logger.info "[#{Time.now.strftime('%Y-%m-%d %H:%M:%S %z')}] Copied: #{result.ai}"
|
187
248
|
end
|
188
|
-
|
249
|
+
objects = maybeArtifactoryObject(artifact_module, artifact_version, false)
|
250
|
+
raise "Failed to copy '#{artifact_path}'" unless objects.size > 0
|
251
|
+
objects
|
189
252
|
rescue Exception => e
|
190
|
-
@logger.error "
|
253
|
+
@logger.error "Failed to copy #{artifact_path}: #{e.class.name} #{e.message}"
|
191
254
|
raise e
|
192
255
|
end
|
193
256
|
end
|
data/lib/cicd/builder/version.rb
CHANGED
@@ -4,7 +4,7 @@ module CiCd
|
|
4
4
|
# file = File.expand_path("#{File.dirname(__FILE__)}/../../../VERSION")
|
5
5
|
# lines = File.readlines(file)
|
6
6
|
# version = lines[0]
|
7
|
-
version = '0.9.
|
7
|
+
version = '0.9.32'
|
8
8
|
VERSION = version unless const_defined?('VERSION')
|
9
9
|
major, minor, tiny = VERSION.split('.')
|
10
10
|
MAJOR = major unless const_defined?('MAJOR')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cicd-builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.32
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christo De Lange
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: awesome_print
|