pdk 2.1.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1329 -1292
- data/LICENSE +201 -201
- data/README.md +163 -163
- data/exe/pdk +10 -10
- data/lib/pdk/analytics/client/google_analytics.rb +143 -143
- data/lib/pdk/analytics/client/noop.rb +25 -25
- data/lib/pdk/analytics/util.rb +19 -19
- data/lib/pdk/analytics.rb +30 -30
- data/lib/pdk/answer_file.rb +12 -12
- data/lib/pdk/bolt.rb +19 -19
- data/lib/pdk/cli/build.rb +82 -82
- data/lib/pdk/cli/bundle.rb +48 -48
- data/lib/pdk/cli/config/get.rb +26 -26
- data/lib/pdk/cli/config.rb +22 -22
- data/lib/pdk/cli/console.rb +148 -148
- data/lib/pdk/cli/convert.rb +52 -52
- data/lib/pdk/cli/env.rb +52 -52
- data/lib/pdk/cli/errors.rb +25 -25
- data/lib/pdk/cli/exec/command.rb +293 -283
- data/lib/pdk/cli/exec/interactive_command.rb +114 -114
- data/lib/pdk/cli/exec.rb +84 -84
- data/lib/pdk/cli/exec_group.rb +104 -104
- data/lib/pdk/cli/get/config.rb +24 -24
- data/lib/pdk/cli/get.rb +20 -20
- data/lib/pdk/cli/module/build.rb +12 -12
- data/lib/pdk/cli/module/generate.rb +47 -47
- data/lib/pdk/cli/module.rb +14 -14
- data/lib/pdk/cli/new/class.rb +32 -32
- data/lib/pdk/cli/new/defined_type.rb +32 -32
- data/lib/pdk/cli/new/fact.rb +29 -29
- data/lib/pdk/cli/new/function.rb +29 -29
- data/lib/pdk/cli/new/module.rb +53 -53
- data/lib/pdk/cli/new/provider.rb +29 -29
- data/lib/pdk/cli/new/task.rb +34 -34
- data/lib/pdk/cli/new/test.rb +52 -52
- data/lib/pdk/cli/new/transport.rb +27 -27
- data/lib/pdk/cli/new.rb +21 -21
- data/lib/pdk/cli/release/prep.rb +39 -39
- data/lib/pdk/cli/release/publish.rb +50 -50
- data/lib/pdk/cli/release.rb +194 -192
- data/lib/pdk/cli/remove/config.rb +80 -80
- data/lib/pdk/cli/remove.rb +20 -20
- data/lib/pdk/cli/set/config.rb +119 -119
- data/lib/pdk/cli/set.rb +20 -20
- data/lib/pdk/cli/test/unit.rb +90 -90
- data/lib/pdk/cli/test.rb +11 -11
- data/lib/pdk/cli/update.rb +64 -64
- data/lib/pdk/cli/util/command_redirector.rb +27 -27
- data/lib/pdk/cli/util/interview.rb +72 -72
- data/lib/pdk/cli/util/option_normalizer.rb +55 -55
- data/lib/pdk/cli/util/option_validator.rb +68 -68
- data/lib/pdk/cli/util/spinner.rb +13 -13
- data/lib/pdk/cli/util/update_manager_printer.rb +82 -82
- data/lib/pdk/cli/util.rb +305 -305
- data/lib/pdk/cli/validate.rb +116 -116
- data/lib/pdk/cli.rb +175 -175
- data/lib/pdk/config/analytics_schema.json +26 -26
- data/lib/pdk/config/errors.rb +5 -5
- data/lib/pdk/config/ini_file.rb +183 -183
- data/lib/pdk/config/ini_file_setting.rb +39 -39
- data/lib/pdk/config/json.rb +34 -34
- data/lib/pdk/config/json_schema_namespace.rb +142 -142
- data/lib/pdk/config/json_schema_setting.rb +53 -53
- data/lib/pdk/config/json_with_schema.rb +49 -49
- data/lib/pdk/config/namespace.rb +354 -354
- data/lib/pdk/config/setting.rb +135 -135
- data/lib/pdk/config/validator.rb +31 -31
- data/lib/pdk/config/yaml.rb +46 -42
- data/lib/pdk/config/yaml_with_schema.rb +59 -59
- data/lib/pdk/config.rb +390 -384
- data/lib/pdk/context/control_repo.rb +60 -60
- data/lib/pdk/context/module.rb +28 -28
- data/lib/pdk/context/none.rb +22 -22
- data/lib/pdk/context.rb +99 -99
- data/lib/pdk/control_repo.rb +90 -90
- data/lib/pdk/generate/defined_type.rb +43 -43
- data/lib/pdk/generate/fact.rb +25 -25
- data/lib/pdk/generate/function.rb +48 -48
- data/lib/pdk/generate/module.rb +352 -352
- data/lib/pdk/generate/provider.rb +28 -28
- data/lib/pdk/generate/puppet_class.rb +43 -43
- data/lib/pdk/generate/puppet_object.rb +232 -232
- data/lib/pdk/generate/task.rb +68 -68
- data/lib/pdk/generate/transport.rb +33 -33
- data/lib/pdk/generate.rb +24 -24
- data/lib/pdk/i18n.rb +4 -4
- data/lib/pdk/logger.rb +45 -45
- data/lib/pdk/module/build.rb +322 -322
- data/lib/pdk/module/convert.rb +296 -296
- data/lib/pdk/module/metadata.rb +202 -202
- data/lib/pdk/module/release.rb +260 -254
- data/lib/pdk/module/update.rb +131 -131
- data/lib/pdk/module/update_manager.rb +227 -227
- data/lib/pdk/module.rb +30 -30
- data/lib/pdk/report/event.rb +370 -370
- data/lib/pdk/report.rb +121 -121
- data/lib/pdk/template/fetcher/git.rb +85 -85
- data/lib/pdk/template/fetcher/local.rb +28 -28
- data/lib/pdk/template/fetcher.rb +98 -98
- data/lib/pdk/template/renderer/v1/legacy_template_dir.rb +116 -116
- data/lib/pdk/template/renderer/v1/renderer.rb +132 -132
- data/lib/pdk/template/renderer/v1/template_file.rb +102 -102
- data/lib/pdk/template/renderer/v1.rb +25 -25
- data/lib/pdk/template/renderer.rb +96 -96
- data/lib/pdk/template/template_dir.rb +67 -67
- data/lib/pdk/template.rb +59 -59
- data/lib/pdk/tests/unit.rb +252 -252
- data/lib/pdk/util/bundler.rb +259 -259
- data/lib/pdk/util/changelog_generator.rb +137 -124
- data/lib/pdk/util/env.rb +47 -47
- data/lib/pdk/util/filesystem.rb +138 -138
- data/lib/pdk/util/git.rb +179 -179
- data/lib/pdk/util/json_finder.rb +85 -84
- data/lib/pdk/util/puppet_strings.rb +125 -125
- data/lib/pdk/util/puppet_version.rb +266 -266
- data/lib/pdk/util/ruby_version.rb +179 -179
- data/lib/pdk/util/template_uri.rb +295 -295
- data/lib/pdk/util/vendored_file.rb +93 -93
- data/lib/pdk/util/version.rb +43 -43
- data/lib/pdk/util/windows/api_types.rb +82 -82
- data/lib/pdk/util/windows/file.rb +36 -36
- data/lib/pdk/util/windows/process.rb +79 -79
- data/lib/pdk/util/windows/string.rb +16 -16
- data/lib/pdk/util/windows.rb +15 -15
- data/lib/pdk/util.rb +278 -277
- data/lib/pdk/validate/control_repo/control_repo_validator_group.rb +23 -23
- data/lib/pdk/validate/control_repo/environment_conf_validator.rb +98 -98
- data/lib/pdk/validate/external_command_validator.rb +208 -208
- data/lib/pdk/validate/internal_ruby_validator.rb +100 -100
- data/lib/pdk/validate/invokable_validator.rb +228 -220
- data/lib/pdk/validate/metadata/metadata_json_lint_validator.rb +86 -86
- data/lib/pdk/validate/metadata/metadata_syntax_validator.rb +78 -78
- data/lib/pdk/validate/metadata/metadata_validator_group.rb +20 -20
- data/lib/pdk/validate/puppet/puppet_epp_validator.rb +133 -133
- data/lib/pdk/validate/puppet/puppet_lint_validator.rb +66 -66
- data/lib/pdk/validate/puppet/puppet_syntax_validator.rb +137 -137
- data/lib/pdk/validate/puppet/puppet_validator_group.rb +21 -21
- data/lib/pdk/validate/ruby/ruby_rubocop_validator.rb +80 -80
- data/lib/pdk/validate/ruby/ruby_validator_group.rb +19 -19
- data/lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb +88 -88
- data/lib/pdk/validate/tasks/tasks_name_validator.rb +50 -50
- data/lib/pdk/validate/tasks/tasks_validator_group.rb +20 -20
- data/lib/pdk/validate/validator.rb +118 -118
- data/lib/pdk/validate/validator_group.rb +104 -104
- data/lib/pdk/validate/yaml/yaml_syntax_validator.rb +95 -95
- data/lib/pdk/validate/yaml/yaml_validator_group.rb +19 -19
- data/lib/pdk/validate.rb +94 -94
- data/lib/pdk/version.rb +4 -4
- data/lib/pdk.rb +76 -76
- data/locales/config.yaml +21 -21
- data/locales/pdk.pot +2094 -2094
- metadata +19 -13
data/lib/pdk/util/bundler.rb
CHANGED
@@ -1,259 +1,259 @@
|
|
1
|
-
require 'pdk'
|
2
|
-
|
3
|
-
module PDK
|
4
|
-
module Util
|
5
|
-
module Bundler
|
6
|
-
class BundleHelper; end
|
7
|
-
|
8
|
-
def self.ensure_bundle!(gem_overrides = nil)
|
9
|
-
bundle = BundleHelper.new
|
10
|
-
|
11
|
-
# This will default ensure_bundle! to re-resolving everything to latest
|
12
|
-
gem_overrides ||= { puppet: nil, hiera: nil, facter: nil }
|
13
|
-
|
14
|
-
if already_bundled?(bundle.gemfile, gem_overrides)
|
15
|
-
PDK.logger.debug(_('Bundler managed gems already up to date.'))
|
16
|
-
return
|
17
|
-
end
|
18
|
-
|
19
|
-
unless bundle.gemfile?
|
20
|
-
PDK.logger.debug(_("No Gemfile found in '%{cwd}'. Skipping bundler management.") % { cwd: Dir.pwd })
|
21
|
-
return
|
22
|
-
end
|
23
|
-
|
24
|
-
unless bundle.locked?
|
25
|
-
# Generate initial default Gemfile.lock, either from package cache or
|
26
|
-
# by invoking `bundle lock`
|
27
|
-
bundle.lock!
|
28
|
-
end
|
29
|
-
|
30
|
-
# Check if all dependencies will be available once we update the lockfile.
|
31
|
-
begin
|
32
|
-
original_lockfile = bundle.gemfile_lock
|
33
|
-
temp_lockfile = "#{original_lockfile}.tmp"
|
34
|
-
|
35
|
-
PDK::Util::Filesystem.mv(original_lockfile, temp_lockfile)
|
36
|
-
|
37
|
-
all_deps_available = bundle.installed?(gem_overrides)
|
38
|
-
ensure
|
39
|
-
PDK::Util::Filesystem.mv(temp_lockfile, original_lockfile, force: true)
|
40
|
-
end
|
41
|
-
|
42
|
-
bundle.update_lock!(with: gem_overrides, local: all_deps_available)
|
43
|
-
|
44
|
-
# If there are missing dependencies after updating the lockfile, let `bundle install`
|
45
|
-
# go out and get them. If the specified puppet gem version points to a remote location
|
46
|
-
# or local filepath, then run bundle install as well.
|
47
|
-
if !bundle.installed?(gem_overrides) || (gem_overrides[:puppet] && gem_overrides[:puppet].start_with?('file://', 'git://', 'https://'))
|
48
|
-
bundle.install!(gem_overrides)
|
49
|
-
end
|
50
|
-
|
51
|
-
mark_as_bundled!(bundle.gemfile, gem_overrides)
|
52
|
-
end
|
53
|
-
|
54
|
-
def self.ensure_binstubs!(*gems)
|
55
|
-
bundle = BundleHelper.new
|
56
|
-
|
57
|
-
bundle.binstubs!(gems)
|
58
|
-
end
|
59
|
-
|
60
|
-
def self.already_bundled?(gemfile, gem_overrides)
|
61
|
-
!(@bundled ||= {})[bundle_cache_key(gemfile, gem_overrides)].nil?
|
62
|
-
end
|
63
|
-
|
64
|
-
def self.mark_as_bundled!(gemfile, gem_overrides)
|
65
|
-
(@bundled ||= {})[bundle_cache_key(gemfile, gem_overrides)] = true
|
66
|
-
end
|
67
|
-
|
68
|
-
def self.bundle_cache_key(gemfile, gem_overrides)
|
69
|
-
require 'digest'
|
70
|
-
|
71
|
-
override_sig = (gem_overrides || {}).sort_by { |gem, _| gem.to_s }.to_s
|
72
|
-
Digest::MD5.hexdigest(gemfile.to_s + override_sig)
|
73
|
-
end
|
74
|
-
private_class_method :bundle_cache_key
|
75
|
-
|
76
|
-
class BundleHelper
|
77
|
-
def gemfile
|
78
|
-
require 'pdk/util'
|
79
|
-
@gemfile ||= PDK::Util.find_upwards('Gemfile')
|
80
|
-
end
|
81
|
-
|
82
|
-
def gemfile_lock
|
83
|
-
return if gemfile.nil?
|
84
|
-
@gemfile_lock ||= File.join(File.dirname(gemfile), 'Gemfile.lock')
|
85
|
-
end
|
86
|
-
|
87
|
-
def gemfile?
|
88
|
-
!gemfile.nil?
|
89
|
-
end
|
90
|
-
|
91
|
-
def locked?
|
92
|
-
!gemfile_lock.nil? && PDK::Util::Filesystem.file?(gemfile_lock)
|
93
|
-
end
|
94
|
-
|
95
|
-
def installed?(gem_overrides = {})
|
96
|
-
PDK.logger.debug(_('Checking for missing Gemfile dependencies.'))
|
97
|
-
|
98
|
-
argv = ['check', "--gemfile=#{gemfile}", '--dry-run']
|
99
|
-
|
100
|
-
cmd = bundle_command(*argv).tap do |c|
|
101
|
-
c.update_environment(gemfile_env(gem_overrides)) unless gem_overrides.empty?
|
102
|
-
end
|
103
|
-
|
104
|
-
result = cmd.execute!
|
105
|
-
|
106
|
-
result[:exit_code].zero?
|
107
|
-
end
|
108
|
-
|
109
|
-
def lock!
|
110
|
-
require 'pdk/util'
|
111
|
-
require 'pdk/util/ruby_version'
|
112
|
-
|
113
|
-
if PDK::Util.package_install?
|
114
|
-
# In packaged installs, use vendored Gemfile.lock as a starting point.
|
115
|
-
# Subsequent 'bundle install' will still pick up any new dependencies.
|
116
|
-
vendored_lockfiles = [
|
117
|
-
File.join(PDK::Util.package_cachedir, "Gemfile-#{PDK::Util::RubyVersion.active_ruby_version}.lock"),
|
118
|
-
File.join(PDK::Util.package_cachedir, 'Gemfile.lock'),
|
119
|
-
]
|
120
|
-
|
121
|
-
vendored_gemfile_lock = vendored_lockfiles.find do |lockfile|
|
122
|
-
PDK::Util::Filesystem.exist?(lockfile)
|
123
|
-
end
|
124
|
-
|
125
|
-
unless vendored_gemfile_lock
|
126
|
-
raise PDK::CLI::FatalError, _('Vendored Gemfile.lock (%{source}) not found.') % {
|
127
|
-
source: vendored_gemfile_lock,
|
128
|
-
}
|
129
|
-
end
|
130
|
-
|
131
|
-
PDK.logger.debug(_('Using vendored Gemfile.lock from %{source}.') % { source: vendored_gemfile_lock })
|
132
|
-
PDK::Util::Filesystem.cp(vendored_gemfile_lock, File.join(PDK::Util.module_root, 'Gemfile.lock'))
|
133
|
-
else
|
134
|
-
argv = ['lock']
|
135
|
-
|
136
|
-
cmd = bundle_command(*argv).tap do |c|
|
137
|
-
c.add_spinner(_('Resolving default Gemfile dependencies.'))
|
138
|
-
end
|
139
|
-
|
140
|
-
result = cmd.execute!
|
141
|
-
|
142
|
-
unless result[:exit_code].zero?
|
143
|
-
PDK.logger.fatal(result.values_at(:stdout, :stderr).join("\n")) unless PDK.logger.debug?
|
144
|
-
raise PDK::CLI::FatalError, _('Unable to resolve default Gemfile dependencies.')
|
145
|
-
end
|
146
|
-
|
147
|
-
# After initial lockfile generation, re-resolve json gem to built-in
|
148
|
-
# version to avoid unncessary native compilation attempts. For packaged
|
149
|
-
# installs this is done during the generation of the vendored Gemfile.lock
|
150
|
-
update_lock!(only: { json: nil }, local: true)
|
151
|
-
end
|
152
|
-
|
153
|
-
true
|
154
|
-
end
|
155
|
-
|
156
|
-
def update_lock!(options = {})
|
157
|
-
PDK.logger.debug(_('Updating Gemfile dependencies.'))
|
158
|
-
|
159
|
-
argv = ['lock', "--lockfile=#{gemfile_lock}", '--update']
|
160
|
-
|
161
|
-
overrides = nil
|
162
|
-
|
163
|
-
if options && options[:only]
|
164
|
-
update_gems = options[:only].keys.map(&:to_s)
|
165
|
-
argv << update_gems
|
166
|
-
argv.flatten!
|
167
|
-
|
168
|
-
overrides = options[:only]
|
169
|
-
elsif options && options[:with]
|
170
|
-
overrides = options[:with]
|
171
|
-
end
|
172
|
-
|
173
|
-
argv << '--local' if options && options[:local]
|
174
|
-
argv << '--conservative' if options && options[:conservative]
|
175
|
-
|
176
|
-
cmd = bundle_command(*argv).tap do |c|
|
177
|
-
c.update_environment('BUNDLE_GEMFILE' => gemfile)
|
178
|
-
c.update_environment(gemfile_env(overrides)) if overrides
|
179
|
-
end
|
180
|
-
|
181
|
-
result = cmd.execute!
|
182
|
-
|
183
|
-
unless result[:exit_code].zero?
|
184
|
-
PDK.logger.fatal(result.values_at(:stdout, :stderr).join("\n")) unless PDK.logger.debug?
|
185
|
-
raise PDK::CLI::FatalError, _('Unable to resolve Gemfile dependencies.')
|
186
|
-
end
|
187
|
-
|
188
|
-
true
|
189
|
-
end
|
190
|
-
|
191
|
-
def install!(gem_overrides = {})
|
192
|
-
require 'pdk/util/ruby_version'
|
193
|
-
|
194
|
-
argv = ['install', "--gemfile=#{gemfile}"]
|
195
|
-
argv << '-j4' unless Gem.win_platform? && Gem::Version.new(PDK::Util::RubyVersion.active_ruby_version) < Gem::Version.new('2.3.5')
|
196
|
-
|
197
|
-
cmd = bundle_command(*argv).tap do |c|
|
198
|
-
c.add_spinner(_('Installing missing Gemfile dependencies.'))
|
199
|
-
c.update_environment(gemfile_env(gem_overrides)) unless gem_overrides.empty?
|
200
|
-
end
|
201
|
-
|
202
|
-
result = cmd.execute!
|
203
|
-
|
204
|
-
unless result[:exit_code].zero?
|
205
|
-
PDK.logger.fatal(result.values_at(:stdout, :stderr).join("\n")) unless PDK.logger.debug?
|
206
|
-
raise PDK::CLI::FatalError, _('Unable to install missing Gemfile dependencies.')
|
207
|
-
end
|
208
|
-
|
209
|
-
true
|
210
|
-
end
|
211
|
-
|
212
|
-
def binstubs!(gems)
|
213
|
-
raise PDK::CLI::FatalError, _('Unable to install requested binstubs as the Gemfile is missing') if gemfile.nil?
|
214
|
-
binstub_dir = File.join(File.dirname(gemfile), 'bin')
|
215
|
-
return true if gems.all? { |gem| PDK::Util::Filesystem.file?(File.join(binstub_dir, gem)) }
|
216
|
-
|
217
|
-
cmd = bundle_command('binstubs', *gems, '--force')
|
218
|
-
result = cmd.execute!
|
219
|
-
|
220
|
-
unless result[:exit_code].zero?
|
221
|
-
PDK.logger.fatal(_("Failed to generate binstubs for '%{gems}':\n%{output}") % { gems: gems.join(' '), output: result.values_at(:stdout, :stderr).join("\n") }) unless PDK.logger.debug?
|
222
|
-
raise PDK::CLI::FatalError, _('Unable to install requested binstubs.')
|
223
|
-
end
|
224
|
-
|
225
|
-
true
|
226
|
-
end
|
227
|
-
|
228
|
-
def self.gemfile_env(gem_overrides)
|
229
|
-
gemfile_env = {}
|
230
|
-
|
231
|
-
return gemfile_env unless gem_overrides.respond_to?(:each)
|
232
|
-
|
233
|
-
gem_overrides.each do |gem, version|
|
234
|
-
gemfile_env['PUPPET_GEM_VERSION'] = version if gem.respond_to?(:to_s) && gem.to_s == 'puppet' && !version.nil?
|
235
|
-
gemfile_env['FACTER_GEM_VERSION'] = version if gem.respond_to?(:to_s) && gem.to_s == 'facter' && !version.nil?
|
236
|
-
gemfile_env['HIERA_GEM_VERSION'] = version if gem.respond_to?(:to_s) && gem.to_s == 'hiera' && !version.nil?
|
237
|
-
end
|
238
|
-
|
239
|
-
gemfile_env
|
240
|
-
end
|
241
|
-
|
242
|
-
private
|
243
|
-
|
244
|
-
def gemfile_env(gem_overrides)
|
245
|
-
self.class.gemfile_env(gem_overrides)
|
246
|
-
end
|
247
|
-
|
248
|
-
def bundle_command(*args)
|
249
|
-
require 'pdk/cli/exec'
|
250
|
-
require 'pdk/cli/exec/command'
|
251
|
-
|
252
|
-
PDK::CLI::Exec::Command.new(PDK::CLI::Exec.bundle_bin, *args).tap do |c|
|
253
|
-
c.context = :module
|
254
|
-
end
|
255
|
-
end
|
256
|
-
end
|
257
|
-
end
|
258
|
-
end
|
259
|
-
end
|
1
|
+
require 'pdk'
|
2
|
+
|
3
|
+
module PDK
|
4
|
+
module Util
|
5
|
+
module Bundler
|
6
|
+
class BundleHelper; end
|
7
|
+
|
8
|
+
def self.ensure_bundle!(gem_overrides = nil)
|
9
|
+
bundle = BundleHelper.new
|
10
|
+
|
11
|
+
# This will default ensure_bundle! to re-resolving everything to latest
|
12
|
+
gem_overrides ||= { puppet: nil, hiera: nil, facter: nil }
|
13
|
+
|
14
|
+
if already_bundled?(bundle.gemfile, gem_overrides)
|
15
|
+
PDK.logger.debug(_('Bundler managed gems already up to date.'))
|
16
|
+
return
|
17
|
+
end
|
18
|
+
|
19
|
+
unless bundle.gemfile?
|
20
|
+
PDK.logger.debug(_("No Gemfile found in '%{cwd}'. Skipping bundler management.") % { cwd: Dir.pwd })
|
21
|
+
return
|
22
|
+
end
|
23
|
+
|
24
|
+
unless bundle.locked?
|
25
|
+
# Generate initial default Gemfile.lock, either from package cache or
|
26
|
+
# by invoking `bundle lock`
|
27
|
+
bundle.lock!
|
28
|
+
end
|
29
|
+
|
30
|
+
# Check if all dependencies will be available once we update the lockfile.
|
31
|
+
begin
|
32
|
+
original_lockfile = bundle.gemfile_lock
|
33
|
+
temp_lockfile = "#{original_lockfile}.tmp"
|
34
|
+
|
35
|
+
PDK::Util::Filesystem.mv(original_lockfile, temp_lockfile)
|
36
|
+
|
37
|
+
all_deps_available = bundle.installed?(gem_overrides)
|
38
|
+
ensure
|
39
|
+
PDK::Util::Filesystem.mv(temp_lockfile, original_lockfile, force: true)
|
40
|
+
end
|
41
|
+
|
42
|
+
bundle.update_lock!(with: gem_overrides, local: all_deps_available)
|
43
|
+
|
44
|
+
# If there are missing dependencies after updating the lockfile, let `bundle install`
|
45
|
+
# go out and get them. If the specified puppet gem version points to a remote location
|
46
|
+
# or local filepath, then run bundle install as well.
|
47
|
+
if !bundle.installed?(gem_overrides) || (gem_overrides[:puppet] && gem_overrides[:puppet].start_with?('file://', 'git://', 'https://'))
|
48
|
+
bundle.install!(gem_overrides)
|
49
|
+
end
|
50
|
+
|
51
|
+
mark_as_bundled!(bundle.gemfile, gem_overrides)
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.ensure_binstubs!(*gems)
|
55
|
+
bundle = BundleHelper.new
|
56
|
+
|
57
|
+
bundle.binstubs!(gems)
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.already_bundled?(gemfile, gem_overrides)
|
61
|
+
!(@bundled ||= {})[bundle_cache_key(gemfile, gem_overrides)].nil?
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.mark_as_bundled!(gemfile, gem_overrides)
|
65
|
+
(@bundled ||= {})[bundle_cache_key(gemfile, gem_overrides)] = true
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.bundle_cache_key(gemfile, gem_overrides)
|
69
|
+
require 'digest'
|
70
|
+
|
71
|
+
override_sig = (gem_overrides || {}).sort_by { |gem, _| gem.to_s }.to_s
|
72
|
+
Digest::MD5.hexdigest(gemfile.to_s + override_sig)
|
73
|
+
end
|
74
|
+
private_class_method :bundle_cache_key
|
75
|
+
|
76
|
+
class BundleHelper
|
77
|
+
def gemfile
|
78
|
+
require 'pdk/util'
|
79
|
+
@gemfile ||= PDK::Util.find_upwards('Gemfile')
|
80
|
+
end
|
81
|
+
|
82
|
+
def gemfile_lock
|
83
|
+
return if gemfile.nil?
|
84
|
+
@gemfile_lock ||= File.join(File.dirname(gemfile), 'Gemfile.lock')
|
85
|
+
end
|
86
|
+
|
87
|
+
def gemfile?
|
88
|
+
!gemfile.nil?
|
89
|
+
end
|
90
|
+
|
91
|
+
def locked?
|
92
|
+
!gemfile_lock.nil? && PDK::Util::Filesystem.file?(gemfile_lock)
|
93
|
+
end
|
94
|
+
|
95
|
+
def installed?(gem_overrides = {})
|
96
|
+
PDK.logger.debug(_('Checking for missing Gemfile dependencies.'))
|
97
|
+
|
98
|
+
argv = ['check', "--gemfile=#{gemfile}", '--dry-run']
|
99
|
+
|
100
|
+
cmd = bundle_command(*argv).tap do |c|
|
101
|
+
c.update_environment(gemfile_env(gem_overrides)) unless gem_overrides.empty?
|
102
|
+
end
|
103
|
+
|
104
|
+
result = cmd.execute!
|
105
|
+
|
106
|
+
result[:exit_code].zero?
|
107
|
+
end
|
108
|
+
|
109
|
+
def lock!
|
110
|
+
require 'pdk/util'
|
111
|
+
require 'pdk/util/ruby_version'
|
112
|
+
|
113
|
+
if PDK::Util.package_install?
|
114
|
+
# In packaged installs, use vendored Gemfile.lock as a starting point.
|
115
|
+
# Subsequent 'bundle install' will still pick up any new dependencies.
|
116
|
+
vendored_lockfiles = [
|
117
|
+
File.join(PDK::Util.package_cachedir, "Gemfile-#{PDK::Util::RubyVersion.active_ruby_version}.lock"),
|
118
|
+
File.join(PDK::Util.package_cachedir, 'Gemfile.lock'),
|
119
|
+
]
|
120
|
+
|
121
|
+
vendored_gemfile_lock = vendored_lockfiles.find do |lockfile|
|
122
|
+
PDK::Util::Filesystem.exist?(lockfile)
|
123
|
+
end
|
124
|
+
|
125
|
+
unless vendored_gemfile_lock
|
126
|
+
raise PDK::CLI::FatalError, _('Vendored Gemfile.lock (%{source}) not found.') % {
|
127
|
+
source: vendored_gemfile_lock,
|
128
|
+
}
|
129
|
+
end
|
130
|
+
|
131
|
+
PDK.logger.debug(_('Using vendored Gemfile.lock from %{source}.') % { source: vendored_gemfile_lock })
|
132
|
+
PDK::Util::Filesystem.cp(vendored_gemfile_lock, File.join(PDK::Util.module_root, 'Gemfile.lock'))
|
133
|
+
else
|
134
|
+
argv = ['lock']
|
135
|
+
|
136
|
+
cmd = bundle_command(*argv).tap do |c|
|
137
|
+
c.add_spinner(_('Resolving default Gemfile dependencies.'))
|
138
|
+
end
|
139
|
+
|
140
|
+
result = cmd.execute!
|
141
|
+
|
142
|
+
unless result[:exit_code].zero?
|
143
|
+
PDK.logger.fatal(result.values_at(:stdout, :stderr).join("\n")) unless PDK.logger.debug?
|
144
|
+
raise PDK::CLI::FatalError, _('Unable to resolve default Gemfile dependencies.')
|
145
|
+
end
|
146
|
+
|
147
|
+
# After initial lockfile generation, re-resolve json gem to built-in
|
148
|
+
# version to avoid unncessary native compilation attempts. For packaged
|
149
|
+
# installs this is done during the generation of the vendored Gemfile.lock
|
150
|
+
update_lock!(only: { json: nil }, local: true)
|
151
|
+
end
|
152
|
+
|
153
|
+
true
|
154
|
+
end
|
155
|
+
|
156
|
+
def update_lock!(options = {})
|
157
|
+
PDK.logger.debug(_('Updating Gemfile dependencies.'))
|
158
|
+
|
159
|
+
argv = ['lock', "--lockfile=#{gemfile_lock}", '--update']
|
160
|
+
|
161
|
+
overrides = nil
|
162
|
+
|
163
|
+
if options && options[:only]
|
164
|
+
update_gems = options[:only].keys.map(&:to_s)
|
165
|
+
argv << update_gems
|
166
|
+
argv.flatten!
|
167
|
+
|
168
|
+
overrides = options[:only]
|
169
|
+
elsif options && options[:with]
|
170
|
+
overrides = options[:with]
|
171
|
+
end
|
172
|
+
|
173
|
+
argv << '--local' if options && options[:local]
|
174
|
+
argv << '--conservative' if options && options[:conservative]
|
175
|
+
|
176
|
+
cmd = bundle_command(*argv).tap do |c|
|
177
|
+
c.update_environment('BUNDLE_GEMFILE' => gemfile)
|
178
|
+
c.update_environment(gemfile_env(overrides)) if overrides
|
179
|
+
end
|
180
|
+
|
181
|
+
result = cmd.execute!
|
182
|
+
|
183
|
+
unless result[:exit_code].zero?
|
184
|
+
PDK.logger.fatal(result.values_at(:stdout, :stderr).join("\n")) unless PDK.logger.debug?
|
185
|
+
raise PDK::CLI::FatalError, _('Unable to resolve Gemfile dependencies.')
|
186
|
+
end
|
187
|
+
|
188
|
+
true
|
189
|
+
end
|
190
|
+
|
191
|
+
def install!(gem_overrides = {})
|
192
|
+
require 'pdk/util/ruby_version'
|
193
|
+
|
194
|
+
argv = ['install', "--gemfile=#{gemfile}"]
|
195
|
+
argv << '-j4' unless Gem.win_platform? && Gem::Version.new(PDK::Util::RubyVersion.active_ruby_version) < Gem::Version.new('2.3.5')
|
196
|
+
|
197
|
+
cmd = bundle_command(*argv).tap do |c|
|
198
|
+
c.add_spinner(_('Installing missing Gemfile dependencies.'))
|
199
|
+
c.update_environment(gemfile_env(gem_overrides)) unless gem_overrides.empty?
|
200
|
+
end
|
201
|
+
|
202
|
+
result = cmd.execute!
|
203
|
+
|
204
|
+
unless result[:exit_code].zero?
|
205
|
+
PDK.logger.fatal(result.values_at(:stdout, :stderr).join("\n")) unless PDK.logger.debug?
|
206
|
+
raise PDK::CLI::FatalError, _('Unable to install missing Gemfile dependencies.')
|
207
|
+
end
|
208
|
+
|
209
|
+
true
|
210
|
+
end
|
211
|
+
|
212
|
+
def binstubs!(gems)
|
213
|
+
raise PDK::CLI::FatalError, _('Unable to install requested binstubs as the Gemfile is missing') if gemfile.nil?
|
214
|
+
binstub_dir = File.join(File.dirname(gemfile), 'bin')
|
215
|
+
return true if gems.all? { |gem| PDK::Util::Filesystem.file?(File.join(binstub_dir, gem)) }
|
216
|
+
|
217
|
+
cmd = bundle_command('binstubs', *gems, '--force')
|
218
|
+
result = cmd.execute!
|
219
|
+
|
220
|
+
unless result[:exit_code].zero?
|
221
|
+
PDK.logger.fatal(_("Failed to generate binstubs for '%{gems}':\n%{output}") % { gems: gems.join(' '), output: result.values_at(:stdout, :stderr).join("\n") }) unless PDK.logger.debug?
|
222
|
+
raise PDK::CLI::FatalError, _('Unable to install requested binstubs.')
|
223
|
+
end
|
224
|
+
|
225
|
+
true
|
226
|
+
end
|
227
|
+
|
228
|
+
def self.gemfile_env(gem_overrides)
|
229
|
+
gemfile_env = {}
|
230
|
+
|
231
|
+
return gemfile_env unless gem_overrides.respond_to?(:each)
|
232
|
+
|
233
|
+
gem_overrides.each do |gem, version|
|
234
|
+
gemfile_env['PUPPET_GEM_VERSION'] = version if gem.respond_to?(:to_s) && gem.to_s == 'puppet' && !version.nil?
|
235
|
+
gemfile_env['FACTER_GEM_VERSION'] = version if gem.respond_to?(:to_s) && gem.to_s == 'facter' && !version.nil?
|
236
|
+
gemfile_env['HIERA_GEM_VERSION'] = version if gem.respond_to?(:to_s) && gem.to_s == 'hiera' && !version.nil?
|
237
|
+
end
|
238
|
+
|
239
|
+
gemfile_env
|
240
|
+
end
|
241
|
+
|
242
|
+
private
|
243
|
+
|
244
|
+
def gemfile_env(gem_overrides)
|
245
|
+
self.class.gemfile_env(gem_overrides)
|
246
|
+
end
|
247
|
+
|
248
|
+
def bundle_command(*args)
|
249
|
+
require 'pdk/cli/exec'
|
250
|
+
require 'pdk/cli/exec/command'
|
251
|
+
|
252
|
+
PDK::CLI::Exec::Command.new(PDK::CLI::Exec.bundle_bin, *args).tap do |c|
|
253
|
+
c.context = :module
|
254
|
+
end
|
255
|
+
end
|
256
|
+
end
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|