cicd-builder 0.9.48 → 0.9.50

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: efea1243d554e4bd293069c488335f978a95d8ef
4
- data.tar.gz: c4039129628cefe72a3031486aff4513dcaf3321
3
+ metadata.gz: 812b59bab3245bb65e3da40f49e995d6d01faac3
4
+ data.tar.gz: c0067b69de71de70310fa48ca7e27dd03eb9f7c5
5
5
  SHA512:
6
- metadata.gz: 14e82811801393c612a1f974b736df6e421f8d3ce23cf029f1cf5227ae454d5e52520b3d4be4ba20acc273d96241f4c75c44e9ff10ba49f1988a040a8b59b819
7
- data.tar.gz: c907b107fbe092c5683dba750d95433d60b91ad2dd062db1c516357a61f88a42f6ab13485becc8085fee55b935310b98e500c00ef46d3c357085eed0415620ea
6
+ metadata.gz: f04f159999011737a30a0202b145d5e60ed7dcc1bf163c1931c597d4c925b4897b75751e61fbb49a6c9c8c428b03741249b1a4c36f6e605e72ac3cdc56bf879e
7
+ data.tar.gz: adb4d7f0a922036ae3e8ea04de849d3a6727ac9b25e6b8aa94ddc4a34dc5aef0e7fbae3bb73d8ce55ec3fc55500463d0d9b43f1e55bcace29cb55919c82b15ae
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cicd-builder (0.9.48)
4
+ cicd-builder (0.9.50)
5
5
  artifactory (>= 2.2.1, < 2.3)
6
6
  awesome_print (>= 1.6, < 2.0)
7
7
  aws-sdk (>= 2.0, < 2.1)
@@ -10,6 +10,8 @@ PATH
10
10
  inifile (>= 3.0.0, < 3.1)
11
11
  json (>= 1.8.1, < 1.9)
12
12
  logging (>= 1.8.2, < 1.9)
13
+ parallel (>= 1.4.1, < 1.5)
14
+ ruby-progressbar (>= 1.7.5, < 2)
13
15
  semverse (>= 1.2.1, < 1.3)
14
16
  yajl-ruby (>= 1.2.1, < 1.3)
15
17
 
@@ -18,14 +20,14 @@ GEM
18
20
  specs:
19
21
  artifactory (2.2.1)
20
22
  awesome_print (1.6.1)
21
- aws-sdk (2.0.39)
22
- aws-sdk-resources (= 2.0.39)
23
- aws-sdk-core (2.0.39)
23
+ aws-sdk (2.0.41)
24
+ aws-sdk-resources (= 2.0.41)
25
+ aws-sdk-core (2.0.41)
24
26
  builder (~> 3.0)
25
27
  jmespath (~> 1.0)
26
28
  multi_json (~> 1.0)
27
- aws-sdk-resources (2.0.39)
28
- aws-sdk-core (= 2.0.39)
29
+ aws-sdk-resources (2.0.41)
30
+ aws-sdk-core (= 2.0.41)
29
31
  builder (3.2.2)
30
32
  chef (12.0.3)
31
33
  chef-zero (~> 3.2)
@@ -78,7 +80,7 @@ GEM
78
80
  little-plugger (>= 1.1.3)
79
81
  multi_json (>= 1.8.4)
80
82
  method_source (0.8.2)
81
- mime-types (2.4.3)
83
+ mime-types (2.5)
82
84
  mixlib-authentication (1.3.0)
83
85
  mixlib-log
84
86
  mixlib-cli (1.5.0)
@@ -92,7 +94,7 @@ GEM
92
94
  net-ssh-multi (1.2.1)
93
95
  net-ssh (>= 2.6.5)
94
96
  net-ssh-gateway (>= 1.2.0)
95
- ohai (8.2.0)
97
+ ohai (8.3.0)
96
98
  ffi (~> 1.9)
97
99
  ffi-yajl (>= 1.1, < 3.0)
98
100
  ipaddress
@@ -104,6 +106,7 @@ GEM
104
106
  rake (~> 10.1)
105
107
  systemu (~> 2.6.4)
106
108
  wmi-lite (~> 1.0)
109
+ parallel (1.4.1)
107
110
  plist (3.1.0)
108
111
  pry (0.10.1)
109
112
  coderay (~> 1.1.0)
@@ -111,6 +114,7 @@ GEM
111
114
  slop (~> 3.4)
112
115
  rack (1.6.0)
113
116
  rake (10.3.2)
117
+ ruby-progressbar (1.7.5)
114
118
  rubygems-tasks (0.2.4)
115
119
  semverse (1.2.1)
116
120
  slop (3.6.0)
data/cicd-builder.gemspec CHANGED
@@ -27,6 +27,8 @@ Gem::Specification.new do |gem|
27
27
  gem.add_dependency 'git', '>= 1.2.7', '< 1.3'
28
28
  gem.add_dependency 'semverse', '>= 1.2.1', '< 1.3'
29
29
  gem.add_dependency 'artifactory', '>= 2.2.1', '< 2.3'
30
+ gem.add_dependency 'parallel', '>= 1.4.1', '< 1.5'
31
+ gem.add_dependency 'ruby-progressbar', '>= 1.7.5', '< 2'
30
32
 
31
33
  gem.add_development_dependency 'bundler', '>= 1.7', '< 1.8'
32
34
  gem.add_development_dependency 'rake', '>= 10.3', '< 11'
@@ -5,7 +5,7 @@ module CiCd
5
5
 
6
6
  # ---------------------------------------------------------------------------------------------------------------
7
7
  def cleanupBuild()
8
- @logger.step __method__.to_s
8
+ @logger.info CLASS+'::'+__method__.to_s
9
9
  [ :build_pkg, :build_chk, :build_mdf, :build_mff ].each do |fil|
10
10
  if File.exists?(@vars[fil])
11
11
  begin
@@ -31,7 +31,7 @@ module CiCd
31
31
 
32
32
  # ---------------------------------------------------------------------------------------------------------------
33
33
  def prepareBuild()
34
- @logger.step __method__.to_s
34
+ @logger.step CLASS+'::'+__method__.to_s
35
35
  meta = {}
36
36
  @vars[:return_code] = 0
37
37
  %w[ WORKSPACE PROJECT_NAME ].each do |e|
@@ -105,7 +105,7 @@ module CiCd
105
105
 
106
106
  # ---------------------------------------------------------------------------------------------------------------
107
107
  def makeBuild()
108
- @logger.step __method__.to_s
108
+ @logger.step CLASS+'::'+__method__.to_s
109
109
  if @vars.has_key?(:build_dir) and @vars.has_key?(:build_pkg)
110
110
  begin
111
111
  do_build = false
@@ -208,7 +208,7 @@ module CiCd
208
208
 
209
209
  # ---------------------------------------------------------------------------------------------------------------
210
210
  def packageBuild()
211
- @logger.step __method__.to_s
211
+ @logger.info CLASS+'::'+__method__.to_s
212
212
  excludes=%w(*.iml *.txt *.sh *.md .gitignore .editorconfig .jshintrc *.deprecated adminer doc)
213
213
  excludes = excludes.map{ |e| "--exclude=#{@vars[:build_nam]}/#{e}" }.join(' ')
214
214
  cmd = %(cd #{ENV['WORKSPACE']}; tar zcvf #{@vars[:build_pkg]} #{excludes} #{@vars[:build_nam]} 1>#{@vars[:build_pkg]}.manifest)
@@ -222,7 +222,7 @@ module CiCd
222
222
 
223
223
  # ---------------------------------------------------------------------------------------------------------------
224
224
  def createMetaData()
225
- @logger.step __method__.to_s
225
+ @logger.info CLASS+'::'+__method__.to_s
226
226
  @vars[:build_mdd].merge!({
227
227
  :Generation => @options[:gen],
228
228
  :Project => @vars[:project_name],
@@ -1,10 +1,11 @@
1
1
  module CiCd
2
2
  module Builder
3
3
  require 'awesome_print'
4
+ CLASS = 'CiCd::Builder'
4
5
 
5
6
  # ---------------------------------------------------------------------------------------------------------------
6
7
  def checkEnvironment()
7
- @logger.step __method__.to_s
8
+ @logger.step CLASS+'::'+__method__.to_s
8
9
  # [2013-12-30 Christo] Detect CI ...
9
10
  unless ENV.has_key?('JENKINS_HOME')
10
11
  @logger.error "Sorry, your CI environment is not supported at this time (2013-12-30) ... Christo De Lange\n"+
@@ -31,7 +32,7 @@ module CiCd
31
32
 
32
33
  # ---------------------------------------------------------------------------------------------------------------
33
34
  def getVars()
34
- @logger.step __method__.to_s
35
+ @logger.step CLASS+'::'+__method__.to_s
35
36
  @vars ||= {}
36
37
  @vars[:release] = 'latest'
37
38
  @vars[:build_store] = '/tmp'
@@ -142,7 +143,7 @@ module CiCd
142
143
 
143
144
  # ---------------------------------------------------------------------------------------------------------------
144
145
  def saveEnvironment(ignored=ENV_IGNORED)
145
- @logger.step __method__.to_s
146
+ @logger.info CLASS+'::'+__method__.to_s
146
147
  @logger.info "Save environment to #{@vars[:vars_fil]}"
147
148
  vstr = ['[global]']
148
149
  ENV.to_hash.sort.each{|k,v|
@@ -155,7 +156,7 @@ module CiCd
155
156
 
156
157
  # ---------------------------------------------------------------------------------------------------------------
157
158
  def saveBuild()
158
- @logger.step __method__.to_s
159
+ @logger.step CLASS+'::'+__method__.to_s
159
160
  begin
160
161
  raise 'ERROR: Checksum not read' unless @vars.has_key?(:latest_sha)
161
162
  raise 'ERROR: Checksum not calculated' unless @vars.has_key?(:build_sha)
@@ -34,6 +34,7 @@ module CiCd
34
34
  BAD_ARTIFACTS = i+=1
35
35
  ARTIFACT_NOT_FOUND = i+=1
36
36
  ARTIFACT_CHECKSUM_BAD = i+=1
37
+ ARTIFACT_MULTI_MATCH = i+=1
37
38
  SAVE_LATEST_VARS = i+=1
38
39
  SAVE_ENVIRONMENT_VARS = i+=1
39
40
  NO_ARTIFACTS = i+=1
@@ -44,7 +45,7 @@ module CiCd
44
45
  PRUNE_NO_TREE = i+=1
45
46
  PRUNE_NO_VARIANT = i+=1
46
47
  PRUNE_NO_PRUNER = i+=1
47
- PRUNE_TOO_OLD = i+=1
48
+ REPO_TOO_OLD = i+=1
48
49
  PRUNE_VARIANT_MIA = i+=1
49
50
  PRUNE_BAD_BRANCH = i+=1
50
51
  PRUNE_BAD_VERSION = i+=1
@@ -53,6 +54,12 @@ module CiCd
53
54
  SYNC_BAD_PRODUCT = i+=1
54
55
  SYNC_NO_VARIANT = i+=1
55
56
  SYNC_NO_DRAWER = i+=1
57
+ REPO_NO_VARIANT = i+=1
58
+ REPO_BAD_VERSION = i+=1
59
+ REPO_BAD_BRANCH = i+=1
60
+ REPO_NO_BUILD = i+=1
61
+
62
+ PRUNE_TOO_OLD = REPO_TOO_OLD
56
63
 
57
64
  require 'awesome_print'
58
65
 
@@ -12,12 +12,9 @@ module CiCd
12
12
 
13
13
  # ---------------------------------------------------------------------------------------------------------------
14
14
  def getRepoClass(type = nil)
15
- @logger.info __method__.to_s
15
+ @logger.info CLASS+'::'+__method__.to_s
16
16
  if type.nil?
17
17
  type ||= 'S3'
18
- if ENV.has_key?('REPO_TYPE')
19
- type = ENV['REPO_TYPE']
20
- end
21
18
  end
22
19
 
23
20
  @logger.info "#{type} repo interface"
@@ -32,15 +29,33 @@ module CiCd
32
29
  end
33
30
 
34
31
  # ---------------------------------------------------------------------------------------------------------------
35
- def performOnRepoInstance(verb)
36
- @logger.step __method__.to_s + ' ' + verb
37
- clazz = getRepoClass()
32
+ def getRepoInstance(type = nil)
33
+ @logger.info CLASS+'::'+__method__.to_s
34
+ if type.nil?
35
+ type ||= 'S3'
36
+ if ENV.has_key?('REPO_TYPE')
37
+ type = ENV['REPO_TYPE']
38
+ end
39
+ end
40
+ clazz = getRepoClass(type)
38
41
  if clazz.is_a?(Class) and not clazz.nil?
39
42
  @repo = clazz.new(self)
43
+ else
44
+ @logger.error "#{clazz.name.to_s} is not a valid repo class"
45
+ @vars[:return_code] = Errors::BUILDER_REPO_TYPE
46
+ end
47
+ @vars[:return_code]
48
+ end
49
+
50
+ # ---------------------------------------------------------------------------------------------------------------
51
+ def performOnRepoInstance(verb)
52
+ @logger.info CLASS+'::'+__method__.to_s
53
+ getRepoInstance()
54
+ if 0 == @vars[:return_code]
40
55
  method = @repo.method(verb)
41
56
  if @repo.respond_to?(verb)
42
- unless method.owner == clazz
43
- @logger.warn "#{clazz.name.to_s} does not override action #{verb}"
57
+ unless method.owner == @repo.class
58
+ @logger.warn "#{@repo.class.name} does not override action #{verb}"
44
59
  # else
45
60
  # @logger.error "#{clazz.name.to_s} does not implement action #{verb}"
46
61
  # @vars[:return_code] = Errors::BUILDER_REPO_ACTION
@@ -50,45 +65,43 @@ module CiCd
50
65
  @logger.fatal "'#{verb}' not implemented!"
51
66
  @vars[:return_code] = Errors::BUILDER_REPO_ACTION
52
67
  end
53
- else
54
- @logger.error "#{clazz.name.to_s} is not a valid repo class"
55
- @vars[:return_code] = Errors::BUILDER_REPO_TYPE
56
68
  end
57
69
  @vars[:return_code]
58
70
  end
59
71
 
60
72
  # ---------------------------------------------------------------------------------------------------------------
61
73
  def uploadBuildArtifacts()
62
- @logger.step __method__.to_s
74
+ @logger.step CLASS+'::'+__method__.to_s
63
75
  performOnRepoInstance(__method__.to_s)
64
76
  end
65
77
 
66
78
  # ---------------------------------------------------------------------------------------------------------------
67
79
  def analyzeInventory()
68
- @logger.step __method__.to_s
80
+ @logger.step CLASS+'::'+__method__.to_s
69
81
  performOnRepoInstance(__method__.to_s)
70
82
  end
71
83
 
72
84
  # ---------------------------------------------------------------------------------------------------------------
73
85
  def pruneInventory()
74
- @logger.step __method__.to_s
86
+ @logger.step CLASS+'::'+__method__.to_s
75
87
  performOnRepoInstance(__method__.to_s)
76
88
  end
77
89
 
78
90
  # ---------------------------------------------------------------------------------------------------------------
79
91
  def syncInventory()
80
- @logger.step __method__.to_s
92
+ @logger.step CLASS+'::'+__method__.to_s
81
93
  performOnRepoInstance(__method__.to_s)
82
94
  end
83
95
 
84
96
  # ---------------------------------------------------------------------------------------------------------------
85
97
  def syncRepo()
86
- @logger.step __method__.to_s
98
+ @logger.step CLASS+'::'+__method__.to_s
87
99
  performOnRepoInstance(__method__.to_s)
88
100
  end
89
101
 
90
102
  # ---------------------------------------------------------------------------------------------------------------
91
103
  def manifestMetadata
104
+ @logger.info CLASS+'::'+__method__.to_s
92
105
  manifest = @vars[:build_mdd].dup
93
106
 
94
107
  manifest[:manifest] = getBuilderVersion
@@ -339,9 +339,9 @@ EC2 Instance profile
339
339
  end
340
340
 
341
341
  # ---------------------------------------------------------------------------------------------------------------
342
- def pullInventory()
342
+ def pullInventory(product=nil)
343
343
  json = nil
344
- key, s3_obj = checkForInventory()
344
+ key, s3_obj = checkForInventory(product)
345
345
  # If the inventory has started then add to it else create a new one
346
346
  if s3_obj.nil?
347
347
  # Start a new inventory
@@ -370,8 +370,11 @@ EC2 Instance profile
370
370
  end
371
371
 
372
372
  # ---------------------------------------------------------------------------------------------------------------
373
- def checkForInventory
374
- key = "#{@vars[:project_name]}/INVENTORY.json"
373
+ def checkForInventory(product=nil)
374
+ if product.nil?
375
+ product = @vars[:project_name]
376
+ end
377
+ key = "#{product}/INVENTORY.json"
375
378
  s3_obj = maybeS3Object(key)
376
379
  return key, s3_obj
377
380
  end
@@ -406,7 +409,7 @@ EC2 Instance profile
406
409
 
407
410
  # ---------------------------------------------------------------------------------------------------------------
408
411
  def uploadBuildArtifacts()
409
- @logger.step __method__.to_s
412
+ @logger.step CLASS+'::'+__method__.to_s
410
413
  if @vars.has_key?(:build_dir) and @vars.has_key?(:build_pkg)
411
414
  artifacts = @vars[:artifacts] rescue []
412
415
 
@@ -623,29 +626,7 @@ EC2 Instance profile
623
626
  puts "\t#{varianth['builds'].size} builds"
624
627
  puts "\t#{varianth['branches'].size} branches:\n#{varianth['branches'].ai}"
625
628
  # puts "\t#{varianth['versions'].size} versions:\n#{varianth['versions'].ai}"
626
- versions = {}
627
- releases = {}
628
- versrels = {}
629
- bmin = -1
630
- bmax = -1
631
- varianth['builds'].each do |bld|
632
- releases[bld['release']] ||= 0
633
- releases[bld['release']] += 1
634
- unless bld['build_number'].nil?
635
- bnum = bld['build_number'].to_i
636
- if bmin < 0 or bnum < bmin
637
- bmin = bnum
638
- end
639
- if bnum > bmax
640
- bmax = bnum
641
- end
642
- end
643
- ver = _getMatches(@vars, bld['build_name'], :version)
644
- versions[ver] ||= 0
645
- versions[ver] += 1
646
- versrels["#{ver}-#{bld['release']}"] ||= 0
647
- versrels["#{ver}-#{bld['release']}"] += 1
648
- end
629
+ bmax, bmin, releases, versions, versrels = getVariantVersionsAndReleases(varianth)
649
630
  puts "\t#{versions.size} versions:\n#{versions.ai}"
650
631
  puts "\t#{releases.size} releases:\n#{releases.ai}"
651
632
  puts "\t#{versrels.size} version-releases:\n#{versrels.ai}"
@@ -677,6 +658,34 @@ EC2 Instance profile
677
658
  @vars[:return_code]
678
659
  end
679
660
 
661
+ # ---------------------------------------------------------------------------------------------------------------
662
+ def getVariantVersionsAndReleases(varianth)
663
+ versions = {}
664
+ releases = {}
665
+ versrels = {}
666
+ bmin = -1
667
+ bmax = -1
668
+ varianth['builds'].each do |bld|
669
+ releases[bld['release']] ||= 0
670
+ releases[bld['release']] += 1
671
+ unless bld['build_number'].nil?
672
+ bnum = bld['build_number'].to_i
673
+ if bmin < 0 or bnum < bmin
674
+ bmin = bnum
675
+ end
676
+ if bnum > bmax
677
+ bmax = bnum
678
+ end
679
+ end
680
+ ver = _getMatches(@vars, bld['build_name'], :version)
681
+ versions[ver] ||= 0
682
+ versions[ver] += 1
683
+ versrels["#{ver}-#{bld['release']}"] ||= 0
684
+ versrels["#{ver}-#{bld['release']}"] += 1
685
+ end
686
+ return bmax, bmin, releases, versions, versrels
687
+ end
688
+
680
689
  # ---------------------------------------------------------------------------------------------------------------
681
690
  def pruneInventory()
682
691
  @logger.step __method__.to_s
@@ -1060,7 +1069,7 @@ EC2 Instance profile
1060
1069
  varianth['branches'] = Hash[branches.map.with_index.to_a].keys
1061
1070
  end
1062
1071
 
1063
- private :_update, :checkForInventory, :pullInventory, :_update, :_updateBranches, :_updateLatest, :_updateVersions
1072
+ protected :_update, :_update, :_updateBranches, :_updateLatest, :_updateVersions
1064
1073
 
1065
1074
  end
1066
1075
  end
@@ -1,4 +1,61 @@
1
1
  require 'artifactory'
2
+ require 'artifactory/version'
3
+ require 'parallel'
4
+ require 'ruby-progressbar'
5
+
6
+ raise "Need to check compatibility of monkey patch for Artifactory.VERSION == #{::Artifactory::VERSION}" unless ::Artifactory::VERSION == '2.2.1'
7
+ module Artifactory
8
+ module Defaults
9
+ class << self
10
+ #
11
+ # Reset all configuration options to their default values.
12
+ #
13
+ # @example Reset all settings
14
+ # Artifactory.reset!
15
+ #
16
+ # @return [self]
17
+ #
18
+ def reset!
19
+ @_options = nil
20
+ options
21
+ end
22
+ alias_method :setup, :reset!
23
+ #
24
+ # Number of seconds to wait for a response from Artifactory
25
+ #
26
+ # @return [Integer, nil]
27
+ #
28
+ def read_timeout
29
+ ENV['ARTIFACTORY_READ_TIMEOUT'].to_s.to_i || 120
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ module Artifactory
36
+ #
37
+ # A re-usable class containing configuration information for the {Client}. See
38
+ # {Defaults} for a list of default values.
39
+ #
40
+ module Configurable
41
+ #
42
+ # Reset all configuration options to their default values.
43
+ #
44
+ # @example Reset all settings
45
+ # Artifactory.reset!
46
+ #
47
+ # @return [self]
48
+ #
49
+ def reset!
50
+ Defaults.reset!
51
+ Artifactory::Configurable.keys.each do |key|
52
+ instance_variable_set(:"@#{key}", Defaults.options[key])
53
+ end
54
+ self
55
+ end
56
+ alias_method :setup, :reset!
57
+ end
58
+ end
2
59
 
3
60
  module CiCd
4
61
  module Builder
@@ -48,6 +105,16 @@ module CiCd
48
105
  # # config.proxy_address = 'my.proxy.server'
49
106
  # # config.proxy_port = '8080'
50
107
  # end
108
+ if ENV['ARTIFACTORY_READ_TIMEOUT']
109
+ # [2015-04-29 Christo] Sometimes you just have to shake your head ...
110
+ # a) The Artifactory object does it's setup and read ENV variables during require phase ...
111
+ # b) They do not check if the passed value is valid ( in range or even a number at all ) and they don't convert it to an int
112
+ # c) ENV does not allow one to do this: ENV['ARTIFACTORY_READ_TIMEOUT'] = ENV['ARTIFACTORY_READ_TIMEOUT'].to_s.to_i
113
+ # d) ::Artifactory.setup and ::Artifactory.reset! does not reread those options!!!! OMG!
114
+ # Only resort: Open ::Artifactory class and override the method with the code it should have had ... %)
115
+ ::Artifactory.setup
116
+ end
117
+
51
118
  @client = ::Artifactory::Client.new()
52
119
  end
53
120
 
@@ -86,7 +153,7 @@ module CiCd
86
153
  else
87
154
  raise 'Artifact does not have file or data?'
88
155
  end
89
- file_name, file_ext = get_artifact_file_name_ext(data)
156
+ file_name, file_ext = (data[:file_name] and data[:file_ext]) ? [data[:file_name], data[:file_ext]] : get_artifact_file_name_ext(data)
90
157
  if file_name =~ %r'\.+'
91
158
  raise "Unable to parse out file name in #{data[:file]}"
92
159
  end
@@ -210,22 +277,61 @@ module CiCd
210
277
  def maybeArtifactoryObject(artifact_name,artifact_version,wide=true)
211
278
  begin
212
279
  # Get a list of matching artifacts in this repository
213
- result = @client.artifact_gavc_search(group: artifactory_org_path(), name: artifact_name, version: "#{artifact_version}", repos: [artifactory_repo()])
214
- if result.size > 0
215
- @logger.info "Artifactory gavc_search match g=#{artifactory_org_path()},a=#{artifact_name},v=#{artifact_version},r=#{artifactory_repo()}: #{result}"
216
- # raise "GAVC started working: #{result.ai}"
280
+ @logger.info "Artifactory gavc_search g=#{artifactory_org_path()},a=#{artifact_name},v=#{artifact_version},r=#{artifactory_repo()}"
281
+ @arti_search_result = []
282
+ # results = ::Parallel.map([:search,:progress], preserve_results: true, in_threads: 2) { |task|
283
+ # if task == :search
284
+ # @logger.debug 'searching ... '
285
+ # @arti_search_result = @client.artifact_gavc_search(group: artifactory_org_path(), name: artifact_name, version: "#{artifact_version}", repos: [artifactory_repo()])
286
+ # @logger.debug 'searching complete!'
287
+ # raise ::Parallel::Kill
288
+ # # raise ::Parallel::Break # -> stops after all current items are finished
289
+ # else
290
+ # progressbar = ::ProgressBar.create(:title => 'artifact_gavc_search', progress_mark: '=', length: 30, remainder_mark: '.')
291
+ # 30.times { |i|
292
+ # @logger.debug i
293
+ # sleep 1
294
+ # progressbar.increment
295
+ # }
296
+ # raise ::Parallel::Kill
297
+ # end
298
+ # }
299
+ monitor(30, 'artifact_gavc_search'){
300
+ @arti_search_result = @client.artifact_gavc_search(group: artifactory_org_path(), name: artifact_name, version: "#{artifact_version}", repos: [artifactory_repo()])
301
+ }
302
+ # noinspection RubyScope
303
+ if @arti_search_result.size > 0
304
+ @logger.info "\tresult: #{@arti_search_result}"
217
305
  elsif wide
218
306
  @logger.warn 'GAVC search came up empty!'
219
- result = @client.artifact_search(name: artifact_name, repos: [artifactory_repo()])
220
- @logger.info "Artifactory search match a=#{artifact_name},r=#{artifactory_repo()}: #{result}"
307
+ @arti_search_result = @client.artifact_search(name: artifact_name, repos: [artifactory_repo()])
308
+ @logger.info "Artifactory search match a=#{artifact_name},r=#{artifactory_repo()}: #{@arti_search_result}"
221
309
  end
222
- result
310
+ @arti_search_result
223
311
  rescue Exception => e
224
312
  @logger.error "Artifactory error: #{e.class.name} #{e.message}"
225
313
  raise e
226
314
  end
227
315
  end
228
316
 
317
+ def monitor(limit,title='Progress')
318
+ raise 'Must have a block' unless block_given?
319
+ thread = Thread.new(){
320
+ yield
321
+ }
322
+ progressbar = ::ProgressBar.create({title: title, progress_mark: '=', starting_at: 0, total: limit, remainder_mark: '.', throttle_rate: 0.5})
323
+ limit.times do
324
+ res = thread.join(1)
325
+ progressbar.increment
326
+ progressbar.total = limit
327
+ unless thread.alive? #or thread.stop?
328
+ puts ''
329
+ break
330
+ end
331
+ end
332
+ thread.kill if thread.alive? or thread.stop?
333
+ end
334
+
229
335
  def uploadArtifact(artifact_module, artifact_version, artifact_path, data)
230
336
  data[:size] = File.size(data[:file])
231
337
  artifact = ::Artifactory::Resource::Artifact.new(local_path: data[:file], client: @client)
@@ -236,10 +342,38 @@ module CiCd
236
342
  }
237
343
  artifact.size = data[:size]
238
344
  @logger.info "[#{Time.now.strftime('%Y-%m-%d %H:%M:%S %z')}] Start upload #{artifact_path} = #{data[:size]} bytes"
239
- result = artifact.upload(artifactory_repo(), "#{artifact_path}", data[:properties] || {})
240
- @logger.info "[#{Time.now.strftime('%Y-%m-%d %H:%M:%S %z')}] Uploaded: #{result.attributes.select { |k, _| k != :client }.ai}"
241
- artifact.upload_checksum(artifactory_repo(), "#{artifact_path}", :sha1, data[:sha1])
242
- artifact.upload_checksum(artifactory_repo(), "#{artifact_path}", :md5, data[:md5])
345
+ monitor(30, 'upload') {
346
+ @arti_upload_result = artifact.upload(artifactory_repo(), "#{artifact_path}", data[:properties] || {})
347
+ }
348
+ @logger.info "[#{Time.now.strftime('%Y-%m-%d %H:%M:%S %z')}] Uploaded: #{@arti_upload_result.attributes.select { |k, _| k != :client }.ai}"
349
+ 3.times{
350
+ @arti_upload_checksum = false
351
+ monitor(30, 'upload_checksum') {
352
+ begin
353
+ artifact.upload_checksum(artifactory_repo(), "#{artifact_path}", :sha1, data[:sha1])
354
+ @arti_upload_checksum = true
355
+ rescue Exception => e
356
+ @logger.fatal "Failed to upload #{artifact_path}: #{e.class.name} #{e.message}"
357
+ raise e
358
+ end
359
+ }
360
+ break if @arti_upload_checksum
361
+ }
362
+ raise "Failed to upload SHA1 for #{artifact_path}" unless @arti_upload_checksum
363
+ 3.times{
364
+ @arti_upload_checksum = false
365
+ monitor(30, 'upload_checksum') {
366
+ begin
367
+ artifact.upload_checksum(artifactory_repo(), "#{artifact_path}", :md5, data[:md5])
368
+ @arti_upload_checksum = true
369
+ rescue Exception => e
370
+ @logger.fatal "Failed to upload #{artifact_path}: #{e.class.name} #{e.message}"
371
+ raise e
372
+ end
373
+ }
374
+ break if @arti_upload_checksum
375
+ }
376
+ raise "Failed to upload MD5 for #{artifact_path}" unless @arti_upload_checksum
243
377
  attempt = 0
244
378
  objects = []
245
379
  while attempt < 3
@@ -258,8 +392,17 @@ module CiCd
258
392
  @logger.info "Not copying (identical artifact): #{artifact_path}"
259
393
  else
260
394
  @logger.info "[#{Time.now.strftime('%Y-%m-%d %H:%M:%S %z')}] Start copy #{artifact_path} = #{artifact.attributes[:size]} bytes"
261
- result = artifact.copy("#{artifactory_repo()}/#{artifact_path}")
262
- @logger.info "[#{Time.now.strftime('%Y-%m-%d %H:%M:%S %z')}] Copied: #{result.ai}"
395
+ copied = false
396
+ 3.times{
397
+ copied = false
398
+ monitor(30){
399
+ result = artifact.copy("#{artifactory_repo()}/#{artifact_path}")
400
+ @logger.info "[#{Time.now.strftime('%Y-%m-%d %H:%M:%S %z')}] Copied: #{result.ai}"
401
+ copied = true
402
+ }
403
+ break if copied
404
+ }
405
+ raise "Failed to copy #{artifact_path}" unless copied
263
406
  end
264
407
  objects = maybeArtifactoryObject(artifact_module, artifact_version, false)
265
408
  unless objects.size > 0
@@ -276,7 +419,7 @@ module CiCd
276
419
 
277
420
  # ---------------------------------------------------------------------------------------------------------------
278
421
  def uploadBuildArtifacts()
279
- @logger.step __method__.to_s
422
+ @logger.step CLASS+'::'+__method__.to_s
280
423
  if @vars.has_key?(:build_dir) and @vars.has_key?(:build_pkg)
281
424
  begin
282
425
  artifacts = @vars[:artifacts] rescue []
@@ -314,6 +457,22 @@ module CiCd
314
457
  @vars[:return_code]
315
458
  end
316
459
 
460
+ # ---------------------------------------------------------------------------------------------------------------
461
+ def cleanupTempFiles
462
+ @vars[:artifacts].each do |art|
463
+ if art[:data][:temp].is_a?(FalseClass)
464
+ if File.exists?(art[:data][:file])
465
+ File.unlink(art[:data][:file]) if File.exists?(art[:data][:file])
466
+ art[:data].delete(:file)
467
+ art[:data].delete(:temp)
468
+ else
469
+ @logger.warn "Temporary file disappeared: #{data.ai}"
470
+ @vars[:return_code] = Errors::TEMP_FILE_MISSING
471
+ end
472
+ end
473
+ end
474
+ end
475
+
317
476
  end
318
477
  end
319
478
  end
@@ -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.48'
7
+ version = '0.9.50'
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.48
4
+ version: 0.9.50
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-04-28 00:00:00.000000000 Z
11
+ date: 2015-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -210,6 +210,46 @@ dependencies:
210
210
  - - "<"
211
211
  - !ruby/object:Gem::Version
212
212
  version: '2.3'
213
+ - !ruby/object:Gem::Dependency
214
+ name: parallel
215
+ requirement: !ruby/object:Gem::Requirement
216
+ requirements:
217
+ - - ">="
218
+ - !ruby/object:Gem::Version
219
+ version: 1.4.1
220
+ - - "<"
221
+ - !ruby/object:Gem::Version
222
+ version: '1.5'
223
+ type: :runtime
224
+ prerelease: false
225
+ version_requirements: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - ">="
228
+ - !ruby/object:Gem::Version
229
+ version: 1.4.1
230
+ - - "<"
231
+ - !ruby/object:Gem::Version
232
+ version: '1.5'
233
+ - !ruby/object:Gem::Dependency
234
+ name: ruby-progressbar
235
+ requirement: !ruby/object:Gem::Requirement
236
+ requirements:
237
+ - - ">="
238
+ - !ruby/object:Gem::Version
239
+ version: 1.7.5
240
+ - - "<"
241
+ - !ruby/object:Gem::Version
242
+ version: '2'
243
+ type: :runtime
244
+ prerelease: false
245
+ version_requirements: !ruby/object:Gem::Requirement
246
+ requirements:
247
+ - - ">="
248
+ - !ruby/object:Gem::Version
249
+ version: 1.7.5
250
+ - - "<"
251
+ - !ruby/object:Gem::Version
252
+ version: '2'
213
253
  - !ruby/object:Gem::Dependency
214
254
  name: bundler
215
255
  requirement: !ruby/object:Gem::Requirement