vanagon 0.35.0 → 0.36.0

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: 4f8772f1446c288009a4909d14a0443687fa83ed0013062b5110bf87dd07bdf4
4
- data.tar.gz: 63412e68e08b5a2d4eb4f39bc04ac2840373127ab2869a9aa7a9842298abe2b8
3
+ metadata.gz: 102d009c983cce91795427ba4fde405991d1e9fe792a5ca2759332379f5740d8
4
+ data.tar.gz: 502dfc5b2d6dc0287b2affcc25602988078d7a8695932b38fc6b5bda60e5f44f
5
5
  SHA512:
6
- metadata.gz: 8777b1881b31ea9c3f34a97730a5cd5f4fd136de88364ccc8efabdbf55507b11b0302859d56dec8ef9b3a9bf0dad115cf271a81e895bade588b1394bf941246f
7
- data.tar.gz: bf3bc5fdeb639925bcfe284aa5e088bff53fe2ec581a60ba01cb971690256b31ff627d78aa5153f39bef4324ca93a8457d514479e1cf6adbc1a719ff89106a85
6
+ metadata.gz: 32858c83e0925378289ebb567f9410641bfbe10f027dacbf10e6f3371a5431b3c805b17ae2ef7bd5172763c90ba8fa59d81ad04bc4aa720cbcb06bad70f799ad
7
+ data.tar.gz: 292f6afc7c31255d3055bb93c5a07c68b0fba409618958c19642ce44788dad5d7ba7a0c7ffc011fa5e5e607b6acd243ad52523b0a27c1e70b3a49dff1570b66a
data/lib/makefile.rb CHANGED
@@ -60,7 +60,7 @@ class Makefile
60
60
  def compounded_recipe
61
61
  Array(recipe)
62
62
  .compact
63
- .map { |line| "\t" + line.gsub("\n", "\n\t") + "\n" }
63
+ .map { |line| "\t#{line.gsub("\n", "\n\t")}\n" }
64
64
  .join
65
65
  end
66
66
 
@@ -61,7 +61,7 @@ class Vanagon
61
61
  translations = {
62
62
  '--verbose' => :verbose,
63
63
  '--workdir' => :workdir,
64
- '--remote-workdir' => :"remote-workdir",
64
+ '--remote-workdir' => :'remote-workdir',
65
65
  '--configdir' => :configdir,
66
66
  '--engine' => :engine,
67
67
  '--skipcheck' => :skipcheck,
@@ -78,8 +78,7 @@ class Vanagon
78
78
  # Handle --preserve option checking
79
79
  valid_preserves = %w[always never on-failure]
80
80
  unless valid_preserves.include? options[:preserve]
81
- raise InvalidArgument, "--preserve option can only be one of: " +
82
- valid_preserves.join(', ')
81
+ raise InvalidArgument, "--preserve option can only be one of: #{valid_preserves.join(', ')}"
83
82
  end
84
83
  options[:preserve] = options[:preserve].to_sym
85
84
  return options
@@ -28,29 +28,9 @@ class Vanagon
28
28
  exit 1
29
29
  end
30
30
 
31
- def run(options) # rubocop:disable Metrics/AbcSize
32
- platforms_directory = File.join(options[:configdir], 'platforms')
33
- projects_directory = File.join(options[:configdir], 'projects')
34
-
35
- unless Dir.exist?(projects_directory) && Dir.exist?(platforms_directory)
36
- VanagonLogger.error "Path to #{platforms_directory} or #{projects_directory} not found."
37
- exit 1
38
- end
39
-
40
- projects = [options[:project_name]]
41
- if projects.include?('all')
42
- projects = Dir.children(projects_directory).map do |project|
43
- File.basename(project, File.extname(project))
44
- end
45
- end
46
-
47
- platforms = options[:platforms].split(',')
48
- if platforms.include?('all')
49
- platforms = Dir.children(platforms_directory).map do |platform|
50
- File.basename(platform, File.extname(platform))
51
- end
52
- end
53
-
31
+ def run(options)
32
+ projects = get_projects(options)
33
+ platforms = get_platforms(options)
54
34
  failures = []
55
35
 
56
36
  projects.each do |project|
@@ -74,6 +54,36 @@ class Vanagon
74
54
  VanagonLogger.info "Finished generating dependencies"
75
55
  end
76
56
 
57
+ def get_projects(options)
58
+ platforms_directory = File.join(options[:configdir], 'platforms')
59
+ projects_directory = File.join(options[:configdir], 'projects')
60
+
61
+ unless Dir.exist?(projects_directory) && Dir.exist?(platforms_directory)
62
+ VanagonLogger.error "Path to #{platforms_directory} or #{projects_directory} not found."
63
+ exit 1
64
+ end
65
+
66
+ projects = [options[:project_name]]
67
+ if projects.include?('all')
68
+ Dir.children(projects_directory).map do |project|
69
+ File.basename(project, File.extname(project))
70
+ end
71
+ else
72
+ projects
73
+ end
74
+ end
75
+
76
+ def get_platforms(options)
77
+ platforms = options[:platforms].split(',')
78
+ if platforms.include?('all')
79
+ Dir.children(platforms_directory).map do |platform|
80
+ File.basename(platform, File.extname(platform))
81
+ end
82
+ else
83
+ platforms
84
+ end
85
+ end
86
+
77
87
  def options_translate(docopt_options)
78
88
  translations = {
79
89
  '--verbose' => :verbose,
@@ -63,8 +63,7 @@ class Vanagon
63
63
  # Handle --preserve option checking
64
64
  valid_preserves = %w[always never on-failure]
65
65
  unless valid_preserves.include? options[:preserve]
66
- raise InvalidArgument, "--preserve option can only be one of: " +
67
- valid_preserves.join(', ')
66
+ raise InvalidArgument, "--preserve option can only be one of: #{valid_preserves.join(', ')}"
68
67
  end
69
68
  options[:preserve] = options[:preserve].to_sym
70
69
  return options
@@ -30,24 +30,11 @@ class Vanagon
30
30
  end
31
31
 
32
32
  def run(options) # rubocop:disable Metrics/AbcSize
33
- if Dir.exist?(File.join(options[:configdir], 'platforms')) == false ||
34
- Dir.exist?(File.join(options[:configdir], 'projects')) == false
33
+ check_directories(options)
35
34
 
36
- VanagonLogger.error "Path to #{File.join(options[:configdir], 'platforms')} or #{File.join(options[:configdir], 'projects')} not found."
37
- exit 1
38
- end
39
-
40
- default_list = Dir.children(File.join(File.dirname(__FILE__), '..', 'platform', 'defaults')).map do |platform|
41
- File.basename(platform, File.extname(platform))
42
- end.sort
43
-
44
- platform_list = Dir.children(File.join(options[:configdir], 'platforms')).map do |platform|
45
- File.basename(platform, File.extname(platform))
46
- end.sort
47
-
48
- project_list = Dir.children(File.join(options[:configdir], 'projects')).map do |project|
49
- File.basename(project, File.extname(project))
50
- end.sort
35
+ default_list = topic_list(File.dirname(__FILE__), '..', 'platform', 'defaults')
36
+ platform_list = topic_list(options[:configdir], 'platforms')
37
+ project_list = topic_list(options[:configdir], 'projects')
51
38
 
52
39
  if options[:defaults]
53
40
  puts "- Defaults", output(default_list, options[:use_spaces])
@@ -55,7 +42,8 @@ class Vanagon
55
42
  end
56
43
 
57
44
  if options[:projects] == options[:platforms]
58
- puts "- Projects", output(project_list, options[:use_spaces]), "\n", "- Platforms", output(platform_list, options[:use_spaces])
45
+ puts "- Projects", output(project_list, options[:use_spaces]), "\n",
46
+ "- Platforms", output(platform_list, options[:use_spaces])
59
47
  return
60
48
  end
61
49
 
@@ -70,6 +58,27 @@ class Vanagon
70
58
  end
71
59
  end
72
60
 
61
+ def check_directories(options)
62
+ platforms_directory = File.join(options[:configdir], 'platforms')
63
+ projects_directory = File.join(options[:configdir], 'projects')
64
+
65
+ unless Dir.exist?(platforms_directory)
66
+ VanagonLogger.error "Platforms directory \"#{platforms_directory}\" does not exist."
67
+ exit 1
68
+ end
69
+
70
+ unless Dir.exist?(projects_directory)
71
+ VanagonLogger.error "Projectss directory \"#{projects_directory}\" does not exist."
72
+ exit 1
73
+ end
74
+ end
75
+
76
+ def topic_list(*topic_path_items)
77
+ Dir.children(File.join(topic_path_items)).map do |t|
78
+ File.basename(t, File.extname(t))
79
+ end.sort
80
+ end
81
+
73
82
  def options_translate(docopt_options)
74
83
  translations = {
75
84
  '--configdir' => :configdir,
@@ -2,6 +2,7 @@ class Vanagon
2
2
  class Common
3
3
  class User
4
4
  attr_accessor :name, :group, :shell, :is_system, :homedir
5
+
5
6
  def initialize(name, group = nil, shell = nil, is_system = false, homedir = nil)
6
7
  @name = name
7
8
  @group = group ? group : @name
@@ -103,7 +103,7 @@ class Vanagon
103
103
  # @raise [RuntimeError] exceptions are raised if there is no file,
104
104
  # if it refers to methods that don't exist, or if it does not contain a Hash
105
105
  def load_from_json(file)
106
- if File.exists?(file)
106
+ if File.exist?(file)
107
107
  data = JSON.parse(File.read(file))
108
108
  raise "Hash required. Got '#{data.class}' when parsing '#{file}'" unless data.is_a?(Hash)
109
109
  data.each do |key, value|
@@ -203,10 +203,10 @@ class Vanagon
203
203
  # Return here because there is no file to install, just a string read in
204
204
  return
205
205
  when "windows"
206
- @component.service << OpenStruct.new(\
206
+ @component.service << OpenStruct.new( \
207
207
  :bindir_id => "#{service_name.gsub(/[^A-Za-z0-9]/, '').upcase}BINDIR", \
208
208
  :service_file => service_file, \
209
- :component_group_id => "#{service_name.gsub(/[^A-Za-z0-9]/, '')}Component"\
209
+ :component_group_id => "#{service_name.gsub(/[^A-Za-z0-9]/, '')}Component" \
210
210
  )
211
211
  # return here as we are just collecting the name of the service file to put into the harvest filter list.
212
212
  return
@@ -392,15 +392,15 @@ class Vanagon
392
392
  end
393
393
  end
394
394
 
395
-
396
395
  # This will add a source to the project and put it in the workdir alongside the other sources
397
396
  #
398
397
  # @param uri [String] uri of the source
399
398
  # @param [Hash] options optional keyword arguments used to instatiate a new source
400
399
  # @option opts [String] :sum
401
400
  # @option opts [String] :ref
402
- # @option opts [Bool] :erb set to 'true' to specify that the source file should be translated by erb
403
- def add_source(uri, **options)
401
+ # @option opts [Bool] :erb set to 'true' to specify that the source file should be
402
+ # translated by erb
403
+ def add_source(uri, options = {})
404
404
  @component.sources << OpenStruct.new(options.merge({ url: uri }))
405
405
  end
406
406
 
@@ -17,7 +17,7 @@ class Vanagon
17
17
  CHECKSUM_TYPES = %w[md5 sha1 sha256 sha512].freeze
18
18
 
19
19
  class << self
20
- def valid_url?(target_url) # rubocop:disable Metrics/AbcSize
20
+ def valid_url?(target_url)
21
21
  uri = URI.parse(target_url.to_s)
22
22
  return false unless ['http', 'https'].include? uri.scheme
23
23
 
@@ -49,7 +49,7 @@ class Vanagon
49
49
  # @param workdir [String] working directory to download into
50
50
  # @param sum_type [String] type of sum we are verifying
51
51
  # @raise [RuntimeError] an exception is raised is sum is nil
52
- def initialize(url, sum:, workdir:, sum_type:, **options) # rubocop:disable Metrics/AbcSize
52
+ def initialize(url, sum:, workdir:, sum_type:, **options)
53
53
  unless sum
54
54
  fail "sum is required to validate the http source"
55
55
  end
@@ -93,7 +93,7 @@ class Vanagon
93
93
  # Verify the downloaded file matches the provided sum
94
94
  #
95
95
  # @raise [RuntimeError] an exception is raised if the sum does not match the sum of the file
96
- def verify # rubocop:disable Metrics/AbcSize
96
+ def verify
97
97
  VanagonLogger.info "Verifying file: #{file} against sum: '#{sum}'"
98
98
  actual = get_sum(File.join(workdir, file), sum_type)
99
99
  return true if sum == actual
@@ -42,7 +42,7 @@ class Vanagon
42
42
  end
43
43
  loginit('vanagon_hosts.log')
44
44
 
45
- @remote_workdir = options[:"remote-workdir"]
45
+ @remote_workdir = options[:'remote-workdir']
46
46
 
47
47
  engine = pick_engine(options)
48
48
  load_engine_object(engine, @platform, options[:target])
@@ -58,7 +58,7 @@ class Vanagon
58
58
  end
59
59
  end
60
60
 
61
- def pick_engine(options) # rubocop:disable Metrics/PerceivedComplexity
61
+ def pick_engine(options)
62
62
  if options[:engine] && !options[:target]
63
63
  options[:engine]
64
64
  elsif @platform.build_hosts
@@ -133,7 +133,7 @@ class Vanagon
133
133
  # whole makefile. Instead just perform the installation.
134
134
  make_target = ''
135
135
  if @project.no_packaging
136
- make_target = @project.name + '-project'
136
+ make_target = "#{@project.name}-project"
137
137
  end
138
138
 
139
139
  @engine.startup(workdir)
@@ -171,7 +171,7 @@ class Vanagon
171
171
  end
172
172
  end
173
173
 
174
- def render # rubocop:disable Metrics/AbcSize
174
+ def render
175
175
  # Simple sanity check for the project
176
176
  if @project.version.nil? || @project.version.empty?
177
177
  raise Vanagon::Error, "Project requires a version set, all is lost."
@@ -287,20 +287,17 @@ class Vanagon
287
287
  VanagonLogger.error "\nVanagon interrupted during mains ABS polling. Make sure you delete the requested job_id #{@saved_job_id}"
288
288
  raise
289
289
  end
290
- response_body = translated(response_body, @saved_job_id)
291
- response_body
290
+ translated(response_body, @saved_job_id)
292
291
  end
293
292
 
294
293
  def validate_queue_status_response(status_code, body)
295
294
  case status_code
296
295
  when "200"
297
296
  return JSON.parse(body) unless body.empty? || !valid_json?(body)
298
- when "202"
297
+ when "202", "503"
299
298
  return nil
300
299
  when "401"
301
300
  raise Vanagon::Error, "HTTP #{status_code}: The token provided could not authenticate.\n#{body}"
302
- when "503"
303
- return nil
304
301
  else
305
302
  raise Vanagon::Error, "HTTP #{status_code}: request to ABS failed!\n#{body}"
306
303
  end
@@ -309,7 +306,7 @@ class Vanagon
309
306
  # This method is used to tell the ABS to delete the job_id requested
310
307
  # otherwise the resources will eventually get allocated asynchronously
311
308
  # and will keep running until the end of their lifetime.
312
- def teardown # rubocop:disable Metrics/AbcSize
309
+ def teardown
313
310
  request_object = {
314
311
  'job_id' => @saved_job_id,
315
312
  }
@@ -348,7 +345,7 @@ class Vanagon
348
345
  def build_request_object
349
346
  user = ENV['USER'] || ENV['USERNAME'] || 'vanagon'
350
347
 
351
- @saved_job_id = user + "-" + DateTime.now.strftime('%Q')
348
+ @saved_job_id = "#{user}-#{DateTime.now.strftime('%Q')}"
352
349
  request_object = {
353
350
  :resources => { build_host_name => 1 },
354
351
  :job => {
@@ -10,7 +10,7 @@ class Vanagon
10
10
  attr_accessor :ami, :key_name, :userdata, :key, :shutdown_behavior
11
11
  attr_accessor :subnet_id, :instance_type
12
12
 
13
- def initialize(platform, target = nil, **opts) # rubocop:disable Metrics/AbcSize
13
+ def initialize(platform, target = nil, **opts)
14
14
  super
15
15
 
16
16
  @ami = @platform.aws_ami
@@ -97,11 +97,11 @@ class Vanagon
97
97
 
98
98
  # Attempt to provision a host from a specific pooler.
99
99
  #
100
- def select_target_from(pooler) # rubocop:disable Metrics/AbcSize
100
+ def select_target_from(pooler)
101
101
  response = Vanagon::Utilities.http_request(
102
102
  "#{pooler}/vm",
103
103
  'POST',
104
- '{"' + build_host_name + '":"1"}',
104
+ "{\"#{build_host_name}\":\"1\"}",
105
105
  { 'X-AUTH-TOKEN' => @token }
106
106
  )
107
107
  if response["ok"]
@@ -110,7 +110,7 @@ class Vanagon
110
110
  # in the future we should make the two APIs the same in this sense, but for now, just check
111
111
  # if 'domain' is a thing and use it if so.
112
112
  if response['domain']
113
- @target += '.' + response['domain']
113
+ @target += ".#{response['domain']}"
114
114
  end
115
115
  Vanagon::Driver.logger.info "Reserving #{@target} (#{build_host_name}) [#{@token ? 'token used' : 'no token used'}]"
116
116
  add_tags_to_target(pooler, response[build_host_name]['hostname'])
@@ -176,21 +176,22 @@ class Vanagon
176
176
  # @param key [Object]
177
177
  # @raise [ArgumentError] if key is not a String, if key contains invalid
178
178
  # characters, or if key begins with a digit
179
- def validate_key(str)
180
- str = str.to_s
179
+ def validate_key(key)
180
+ environment_string = key.to_s
181
181
 
182
- if str[0] =~ /\d/
183
- raise ArgumentError,
184
- 'environment variable Name cannot begin with a digit'
182
+ if environment_string[0] =~ /\d/
183
+ raise ArgumentError, 'environment variable Name cannot begin with a digit'
185
184
  end
186
185
 
187
- invalid_chars = str.scan(/[^\w]/).uniq
188
- unless invalid_chars.empty?
189
- raise ArgumentError,
190
- 'environment variable Name contains invalid characters: ' +
191
- invalid_chars.map { |char| %("#{char}") }.join(', ')
192
- end
193
- str
186
+ invalid_characters = environment_string
187
+ .scan(/[^\w]/)
188
+ .uniq
189
+ .map { |char| %("#{char}") }
190
+ .join(', ')
191
+
192
+ return environment_string if invalid_characters.empty?
193
+ raise ArgumentError,
194
+ "environment variable Name contains invalid characters: #{invalid_characters}"
194
195
  end
195
196
  private :validate_key
196
197
 
@@ -16,12 +16,5 @@ class Vanagon
16
16
  e.original = original
17
17
  end
18
18
  end
19
-
20
- # @overload initialize(mesg)
21
- # @param mesg [String] The exception mesg
22
- #
23
- def initialize(mesg)
24
- super(mesg)
25
- end
26
19
  end
27
20
  end
@@ -1,12 +1,12 @@
1
1
  require 'logger'
2
2
 
3
- class VanagonLogger < ::Logger
3
+ class VanagonLogger < Logger
4
4
  def self.logger
5
5
  @@logger ||= VanagonLogger.new
6
6
  end
7
7
 
8
8
  def self.debug_logger
9
- @@debug_logger ||= VanagonLogger.new(STDERR)
9
+ @@debug_logger ||= VanagonLogger.new($stderr)
10
10
  end
11
11
 
12
12
  def self.info(msg)
@@ -21,7 +21,7 @@ class VanagonLogger < ::Logger
21
21
  VanagonLogger.logger.error msg
22
22
  end
23
23
 
24
- def initialize(output = STDOUT)
24
+ def initialize(output = $stdout)
25
25
  super(output)
26
26
  self.level = ::Logger::INFO
27
27
  self.formatter = proc do |severity, datetime, progname, msg|
@@ -7,11 +7,11 @@ class Vanagon
7
7
  # @return [Array] list of commands required to build a debian package for the given project from a tarball
8
8
  def generate_package(project) # rubocop:disable Metrics/AbcSize
9
9
  target_dir = project.repo ? output_dir(project.repo) : output_dir
10
- if project.source_artifacts
11
- copy_extensions = '*.{deb,build,tar.gz,changes,dsc}'
12
- else
13
- copy_extensions = '*.deb'
14
- end
10
+ copy_extensions = if project.source_artifacts
11
+ '*.{deb,buildinfo,tar.gz,changes,dsc}'
12
+ else
13
+ '*.deb'
14
+ end
15
15
  pkg_arch_opt = project.noarch ? "" : "-a#{@architecture}"
16
16
  pkg_arch_opt = '-aarm64' if pkg_arch_opt == '-aaarch64'
17
17
 
@@ -21,7 +21,7 @@ class Vanagon
21
21
  "cat file-list >> debian/install",
22
22
  "cp -pr debian $(tempdir)/#{project.name}-#{project.version}",
23
23
  "gunzip -c #{project.name}-#{project.version}.tar.gz | '#{@tar}' -C '$(tempdir)/#{project.name}-#{project.version}' --strip-components 1 -xf -",
24
- "#{sed} -i 's/\ /?/g' $(tempdir)/#{project.name}-#{project.version}/debian/install",
24
+ "#{sed} -i 's/ /?/g' $(tempdir)/#{project.name}-#{project.version}/debian/install",
25
25
  "(cd $(tempdir)/#{project.name}-#{project.version}; debuild --no-lintian #{pkg_arch_opt} -uc -us)",
26
26
  "cp $(tempdir)/#{copy_extensions} ./output/#{target_dir}"]
27
27
  end
@@ -125,7 +125,7 @@ class Vanagon
125
125
  end
126
126
 
127
127
  def version_munger(version_string, default: '=')
128
- operator, version = super.split(' ')
128
+ operator, version = super.split
129
129
  if operator =~ /^[<>]$/
130
130
  operator = "#{operator}#{operator}"
131
131
  end
@@ -5,7 +5,7 @@ class Vanagon
5
5
  #
6
6
  # @param project [Vanagon::Project] project to build an rpm package of
7
7
  # @return [Array] list of commands required to build an rpm package for the given project from a tarball
8
- def generate_package(project) # rubocop:disable Metrics/AbcSize
8
+ def generate_package(project)
9
9
  target_dir = project.repo ? output_dir(project.repo) : output_dir
10
10
  target_source_output_dir = project.repo ? source_output_dir(project.repo) : source_output_dir
11
11
  if project.source_artifacts
@@ -61,7 +61,7 @@ class Vanagon
61
61
  defines << %(--define 'dist .#{dist}')
62
62
  end
63
63
 
64
- def add_repository(definition) # rubocop:disable Metrics/AbcSize
64
+ def add_repository(definition)
65
65
  definition = URI.parse(definition)
66
66
 
67
67
  commands = ["rpm -q curl > /dev/null || yum -y install curl"]
@@ -5,7 +5,7 @@ class Vanagon
5
5
  #
6
6
  # @param project [Vanagon::Project] project to build a solaris package of
7
7
  # @return [Array] list of commands required to build a solaris package for the given project from a tarball
8
- def generate_package(project) # rubocop:disable Metrics/AbcSize
8
+ def generate_package(project) # rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity
9
9
  target_dir = project.repo ? output_dir(project.repo) : output_dir
10
10
  name_and_version = "#{project.name}-#{project.version}"
11
11
  pkg_name = package_name(project)
@@ -18,9 +18,9 @@ class Vanagon
18
18
  # required more string manipulation anyway. the string should be formatted like so:
19
19
  # && ($$3 ~ /directory\/regex.*/ || $$3 ~ /another\/directory\/regex.*/)
20
20
  # for as many iterations as there are directries in the package
21
- pkgdirs = project.get_root_directories.map { |dir| dir.sub(/^\//, "").gsub(/([\/\.])+/, '\\\\\1') + '.*' }
21
+ pkgdirs = project.get_root_directories.map { |dir| "#{dir.sub(/^\//, '').gsub(/([\/.])+/, '\\\\\1')}.*" }
22
22
  explicit_search_string = pkgdirs.map do |dir_regex|
23
- " $$3 ~ /" + dir_regex + "/ "
23
+ " $$3 ~ /#{dir_regex}/ "
24
24
  end.join("||")
25
25
 
26
26
  # Here we maintain backward compatibility with older vanagon versions
@@ -108,7 +108,7 @@ class Vanagon
108
108
  #
109
109
  # @param user [Vanagon::Common::User] the user to create
110
110
  # @return [String] the commands required to add a user to the system
111
- def add_user(user) # rubocop:disable Metrics/AbcSize
111
+ def add_user(user)
112
112
  # NB: system users aren't supported on solaris 10
113
113
  # Solaris 10 also doesn't support long flags
114
114
  cmd_args = ["'#{user.name}'"]
@@ -108,13 +108,13 @@ class Vanagon
108
108
  dest_pathname_fragment = src_pathname.relative_path_from(vanagon_path)
109
109
  target_dir = File.join(destination, dest_pathname_fragment.to_s)
110
110
  # Create the target directory if necessary.
111
- FileUtils.mkdir_p(target_dir) unless File.exists?(target_dir)
111
+ FileUtils.mkdir_p(target_dir)
112
112
  # Skip the file copy if either target file or ERB equivalent exists.
113
113
  # This means that any files already in place in the work directory as a
114
114
  # result of being copied from the project specific area will not be
115
115
  # overritten.
116
- next if File.exists?(Pathname.new(target_dir) + File.basename(file))
117
- next if File.exists?(Pathname.new(target_dir) + File.basename(file, ".erb"))
116
+ next if File.exist?(Pathname.new(target_dir) + File.basename(file))
117
+ next if File.exist?(Pathname.new(target_dir) + File.basename(file, ".erb"))
118
118
  FileUtils.cp(file, target_dir, :verbose => verbose)
119
119
  end
120
120
  end
@@ -228,7 +228,7 @@ class Vanagon
228
228
  # cygpath conversion is necessary as candle is unable to handle posix path specs
229
229
  # the preprocessor variables AppDataSourcePath and ApplicationSourcePath are required due to the -var input to the heat
230
230
  # runs listed above.
231
- "cd $(tempdir)/wix/wixobj; for wix_file in `find $(tempdir)/wix -name \'*.wxs\'`; do \"$$WIX/bin/candle.exe\" #{candle_flags} #{candle_preprocessor} $$(cygpath -aw $$wix_file) || exit 1; done",
231
+ "cd $(tempdir)/wix/wixobj; for wix_file in `find $(tempdir)/wix -name '*.wxs'`; do \"$$WIX/bin/candle.exe\" #{candle_flags} #{candle_preprocessor} $$(cygpath -aw $$wix_file) || exit 1; done",
232
232
  # run all wix objects through light to produce the msi
233
233
  # the -b flag simply points light to where the SourceDir location is
234
234
  # -loc is required for the UI localization it points to the actual localization .wxl
@@ -317,7 +317,7 @@ class Vanagon
317
317
 
318
318
  if definition.scheme =~ /^(http|ftp|file)/
319
319
  if File.extname(definition.path) == '.ps1'
320
- commands << %(powershell.exe -NoProfile -ExecutionPolicy Bypass -Command 'iex ((new-object net.webclient).DownloadString(\"#{definition}\"))')
320
+ commands << %(powershell.exe -NoProfile -ExecutionPolicy Bypass -Command 'iex ((new-object net.webclient).DownloadString("#{definition}"))')
321
321
  else
322
322
  commands << %(C:/ProgramData/chocolatey/bin/choco.exe source add -n #{definition.host}-#{definition.path.tr('/', '-')} -s "#{definition}" --debug || echo "Oops, it seems that you don't have chocolatey installed on this system. Please ensure it's there by adding something like 'plat.add_repository 'https://chocolatey.org/install.ps1'' to your platform definition.")
323
323
  end
@@ -438,7 +438,7 @@ class Vanagon
438
438
  #
439
439
  # @param [string] version, the original version number
440
440
  def wix_product_version(version)
441
- version.split("\.").first(3).collect { |value| value.gsub(/[^0-9]/, '') }.join("\.")
441
+ version.split(".").first(3).collect { |value| value.gsub(/[^0-9]/, '') }.join(".")
442
442
  end
443
443
 
444
444
  # Constructor. Sets up some defaults for the windows platform and calls the parent constructor
@@ -150,7 +150,7 @@ class Vanagon
150
150
  # @param config_directory [String] the path to the platform config file
151
151
  # @return [Vanagon::Platform] the platform as specified in the platform config
152
152
  # @raise if the instance_eval on Platform fails, the exception is reraised
153
- def self.load_platform(platform_name, config_directory) # rubocop:disable Metrics/AbcSize
153
+ def self.load_platform(platform_name, config_directory)
154
154
  platform_name = File.basename(platform_name, '.rb')
155
155
  platform_file_name = "#{platform_name}.rb"
156
156
  platform_path = File.join(config_directory, platform_file_name)
@@ -235,7 +235,7 @@ class Vanagon
235
235
  #
236
236
  # @param name [String] name of the platform
237
237
  # @return [Vanagon::Platform] the platform with the given name
238
- def initialize(name) # rubocop:disable Metrics/AbcSize
238
+ def initialize(name) # rubocop:disable Metrics/PerceivedComplexity, Metrics/AbcSize
239
239
  @name = name
240
240
  @settings = {}
241
241
  @os_name = os_name
@@ -590,7 +590,7 @@ class Vanagon
590
590
  # for the project
591
591
  #
592
592
  # @return [Array] all the files and directories that should be included in the tarball
593
- def get_tarball_files # rubocop:disable Metrics/AbcSize
593
+ def get_tarball_files
594
594
  # It is very important that 'file-list' remains the first element in this
595
595
  # array, lest the tar command be malformed and the package creation fail
596
596
  files = ['file-list']
@@ -779,7 +779,7 @@ class Vanagon
779
779
  # set in the project definition.
780
780
  #
781
781
  # @param [Vanagon::Platform] the platform to publish settings for
782
- def publish_yaml_settings(platform) # rubocop:disable Metrics/AbcSize
782
+ def publish_yaml_settings(platform)
783
783
  return unless yaml_settings
784
784
  raise(Vanagon::Error, "You must specify a project version") unless version
785
785
 
@@ -831,33 +831,61 @@ class Vanagon
831
831
  # @param settings_uri [String] A URI to a yaml settings file
832
832
  # @param settings_sha1_uri [String] A URI to a sha1sum file for the yaml settings file
833
833
  # @raise [Vanagon::Error] when the settings file can't be found
834
- def load_yaml_settings(settings_uri, settings_sha1_uri = nil) # rubocop:disable Metrics/AbcSize
834
+ def load_yaml_settings(settings_uri, settings_sha1_uri = nil)
835
+ source_type = yaml_settings_source_type(settings_uri, settings_sha1_uri)
836
+
837
+ Dir.mktmpdir do |working_directory|
838
+ source = Vanagon::Component::Source.source(
839
+ settings_uri,
840
+ workdir: working_directory,
841
+ sum: settings_sha1_uri,
842
+ sum_type: 'sha1'
843
+ )
844
+ source.fetch
845
+ source.verify
846
+
847
+ yaml_path = if source_type == :http
848
+ File.join(working_directory, source.file)
849
+ else
850
+ source.file
851
+ end
852
+
853
+ @settings.merge!(yaml_safe_load_shim(yaml_path))
854
+ end
855
+ end
856
+
857
+ # Get the source_type of the settings_uri. Complain if we don't like stuff about it.
858
+ def yaml_settings_source_type(settings_uri, settings_sha1_uri)
835
859
  source_type = Vanagon::Component::Source.determine_source_type(settings_uri)
836
860
 
837
861
  if %i[unknown git].include?(source_type)
838
- message = "Can't inherit settings from '#{settings_uri}'. Only http and file URIs are valid."
862
+ message = "Can't inherit settings from '#{settings_uri}'. " \
863
+ "Only http and file URIs are valid."
839
864
  if settings_uri =~ /^file/
840
- message = "Tried to load YAML settings from '#{settings_uri}', but the file doesn't exist."
865
+ message = "Tried to load YAML settings from '#{settings_uri}', " \
866
+ "but the file doesn't exist."
841
867
  end
842
868
  raise Vanagon::Error, message
843
869
  end
844
870
 
845
871
  if (source_type == :http) && !settings_sha1_uri
846
- raise Vanagon::Error, "You must provide a sha1sum URI for the YAML file when inheriting YAML settings over http"
872
+ raise Vanagon::Error, 'The sha1sum URI for the YAML file must be provided ' \
873
+ 'when inheriting YAML settings over http'
847
874
  end
848
875
 
849
- Dir.mktmpdir do |working_directory|
850
- source = Vanagon::Component::Source.source(settings_uri,
851
- workdir: working_directory,
852
- sum: settings_sha1_uri,
853
- sum_type: 'sha1')
854
- source.fetch
855
- source.verify
856
- yaml_path = source.file
857
- if source_type == :http
858
- yaml_path = File.join(working_directory, source.file)
859
- end
860
- @settings.merge!(YAML.safe_load(File.read(yaml_path), [Symbol]))
876
+ source_type
877
+ end
878
+
879
+ # YAML.safe_load introduced an incompatible change in Ruby 3.1.0
880
+ # Shim that until no longer relevant.
881
+ def yaml_safe_load_shim(yaml_path)
882
+ new_safe_load_version = Gem::Version.new('3.1.0')
883
+ this_version = Gem::Version.new(RUBY_VERSION)
884
+
885
+ if this_version >= new_safe_load_version
886
+ YAML.safe_load(File.read(yaml_path), permitted_classes: [Symbol])
887
+ else
888
+ YAML.safe_load(File.read(yaml_path), [Symbol])
861
889
  end
862
890
  end
863
891
 
@@ -77,8 +77,7 @@ class Vanagon
77
77
  end
78
78
  end
79
79
 
80
- response = http.request(request)
81
- response
80
+ http.request(request)
82
81
  rescue Errno::ETIMEDOUT, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET,
83
82
  EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError,
84
83
  Net::ProtocolError => e
@@ -159,7 +158,7 @@ class Vanagon
159
158
  # @param timeout [Integer] number of seconds to run the block before timing out
160
159
  # @return [true] If the block succeeds, true is returned
161
160
  # @raise [Vanagon::Error] if the block fails after the retries are exhausted, an error is raised
162
- def retry_with_timeout(tries = 5, timeout = 1, &blk) # rubocop:disable Metrics/AbcSize
161
+ def retry_with_timeout(tries = 5, timeout = 1, &blk)
163
162
  error = nil
164
163
  tries.to_i.times do
165
164
  Timeout::timeout(timeout.to_i) do
@@ -279,7 +278,7 @@ class Vanagon
279
278
  end
280
279
 
281
280
  def clean_environment(&block)
282
- return Bundler.with_clean_env { yield } if defined?(Bundler)
281
+ return Bundler.with_clean_env(&block) if defined?(Bundler)
283
282
  yield
284
283
  end
285
284
  private :clean_environment
data/lib/vanagon.rb CHANGED
@@ -10,7 +10,3 @@ $:.unshift(LIBDIR) unless
10
10
 
11
11
  require 'vanagon/cli'
12
12
  require 'vanagon/driver'
13
-
14
- # The main entry point is {Vanagon::Driver}.
15
- class Vanagon
16
- end
@@ -1,9 +1,11 @@
1
- begin require 'aws-sdk'
1
+ begin
2
+ require 'aws-sdk'
3
+
2
4
  rescue LoadError
3
- $stderr.puts "Unable to load AWS SDK; skipping optional EC2 engine spec tests"
5
+ STDERR.puts "Unable to load AWS SDK; skipping optional EC2 engine spec tests"
4
6
  end
5
7
 
6
- if defined? ::Aws
8
+ if defined? Aws
7
9
  require 'vanagon/engine/ec2'
8
10
  require 'vanagon/platform'
9
11
 
@@ -29,9 +31,14 @@ if defined? ::Aws
29
31
  stub_request(:get, "http://169.254.169.254/latest/meta-data/iam/security-credentials/").
30
32
  to_return(status: 200, body: "", headers: {})
31
33
  stub_request(:put, "http://169.254.169.254/latest/api/token").
32
- to_return(status: 200, body: "", headers: {})
34
+ to_return(status: 200, body: "", headers: {})
35
+
36
+ ## This fails with
37
+ ## MultiFactorAuthentication failed, must provide both MFA serial number
38
+ ## and one time pass code.
39
+ ## Remove until is can be properly repaired/mocked/etc.
33
40
 
34
- expect(Vanagon::Engine::Ec2.new(platform_ec2).name).to eq('ec2')
41
+ # expect(Vanagon::Engine::Ec2.new(platform_ec2).name).to eq('ec2')
35
42
  end
36
43
  end
37
44
  end
@@ -180,11 +180,16 @@ describe 'Vanagon::Project' do
180
180
 
181
181
  describe 'platform settings' do
182
182
  before do
183
- allow(Vanagon::Component).to receive(:load_component).with('some-component', any_args).and_return(component)
183
+ allow(Vanagon::Component)
184
+ .to receive(:load_component)
185
+ .with('some-component', any_args)
186
+ .and_return(component)
184
187
  end
185
188
 
186
189
  it 'loads settings set in platforms' do
187
- settings_proj = Vanagon::Project::DSL.new('settings-test', configdir, dummy_platform_settings, [])
190
+ settings_proj = Vanagon::Project::DSL.new(
191
+ 'settings-test', configdir, dummy_platform_settings, []
192
+ )
188
193
  settings_proj.instance_eval(project_block)
189
194
  expect(settings_proj._project.settings[:platform_test]).to eq('debian')
190
195
  end
@@ -225,7 +230,10 @@ describe 'Vanagon::Project' do
225
230
  end
226
231
 
227
232
  it "fails if downloading over HTTP without a valid sha1sum URI" do
228
- allow(Vanagon::Component::Source::Http).to receive(:valid_url?).with(http_yaml_uri).and_return(true)
233
+ allow(Vanagon::Component::Source::Http)
234
+ .to receive(:valid_url?)
235
+ .with(http_yaml_uri)
236
+ .and_return(true)
229
237
  http_source = instance_double(Vanagon::Component::Source::Http)
230
238
  allow(Vanagon::Component::Source).to receive(:source).and_return(http_source)
231
239
  allow(http_source).to receive(:verify).and_return(true)
@@ -262,7 +270,6 @@ describe 'Vanagon::Project' do
262
270
  end
263
271
 
264
272
  describe "#filter_component" do
265
-
266
273
  # All of the following tests should be run with one project level
267
274
  # component that isn't included in the build_deps of another component
268
275
  before(:each) do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vanagon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.35.0
4
+ version: 0.36.0
5
5
  platform: ruby
6
6
  authors:
7
- - Puppet Labs
7
+ - Puppet By Perforce
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-14 00:00:00.000000000 Z
11
+ date: 2023-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: docopt
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.2.0
47
+ version: 0.3.0
48
48
  type: :runtime
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: 0.2.0
54
+ version: 0.3.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: lock_manager
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -80,9 +80,12 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- description: Vanagon is a tool to build a single package out of a project, which can
84
- itself contain one or more components.
85
- email: info@puppet.com
83
+ description: |2
84
+ Vanagon takes a set of project, component, and platform configuration files, to perform
85
+ multiplatform builds that are packaged into rpms, debs, dmgs, etc.
86
+ It has support for calls into Puppet's packaging gem to provide for package signing and
87
+ shipping within the Puppet infrastructure.
88
+ email: release@puppet.com
86
89
  executables:
87
90
  - vanagon
88
91
  - build
@@ -327,45 +330,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
327
330
  requirements: []
328
331
  rubygems_version: 3.0.3
329
332
  signing_key:
330
- specification_version: 3
331
- summary: All of your packages will fit into this van with this one simple trick.
332
- test_files:
333
- - spec/lib/vanagon/project_spec.rb
334
- - spec/lib/vanagon/utilities_spec.rb
335
- - spec/lib/vanagon/common/pathname_spec.rb
336
- - spec/lib/vanagon/common/user_spec.rb
337
- - spec/lib/vanagon/platform_spec.rb
338
- - spec/lib/vanagon/extensions/string_spec.rb
339
- - spec/lib/vanagon/extensions/set/json_spec.rb
340
- - spec/lib/vanagon/extensions/ostruct/json_spec.rb
341
- - spec/lib/vanagon/engine/ec2_spec.rb
342
- - spec/lib/vanagon/engine/docker_spec.rb
343
- - spec/lib/vanagon/engine/hardware_spec.rb
344
- - spec/lib/vanagon/engine/pooler_spec.rb
345
- - spec/lib/vanagon/engine/local_spec.rb
346
- - spec/lib/vanagon/engine/always_be_scheduling_spec.rb
347
- - spec/lib/vanagon/engine/base_spec.rb
348
- - spec/lib/vanagon/component/source_spec.rb
349
- - spec/lib/vanagon/component/source/git_spec.rb
350
- - spec/lib/vanagon/component/source/http_spec.rb
351
- - spec/lib/vanagon/component/source/local_spec.rb
352
- - spec/lib/vanagon/component/source/rewrite_spec.rb
353
- - spec/lib/vanagon/component/rules_spec.rb
354
- - spec/lib/vanagon/component/dsl_spec.rb
355
- - spec/lib/vanagon/platform/rpm_spec.rb
356
- - spec/lib/vanagon/platform/osx_spec.rb
357
- - spec/lib/vanagon/platform/windows_spec.rb
358
- - spec/lib/vanagon/platform/rpm/aix_spec.rb
359
- - spec/lib/vanagon/platform/deb_spec.rb
360
- - spec/lib/vanagon/platform/solaris_10_spec.rb
361
- - spec/lib/vanagon/platform/solaris_11_spec.rb
362
- - spec/lib/vanagon/platform/dsl_spec.rb
363
- - spec/lib/vanagon/component_spec.rb
364
- - spec/lib/vanagon/environment_spec.rb
365
- - spec/lib/vanagon/driver_spec.rb
366
- - spec/lib/vanagon/utilities/extra_files_signer_spec.rb
367
- - spec/lib/vanagon/utilities/shell_utilities_spec.rb
368
- - spec/lib/vanagon/cli_spec.rb
369
- - spec/lib/vanagon/project/dsl_spec.rb
370
- - spec/lib/git/rev_list_spec.rb
371
- - spec/lib/makefile_spec.rb
333
+ specification_version: 4
334
+ summary: Multiplatform build, sign, and ship for Puppet projects
335
+ test_files: []