pdk 1.11.1 → 1.12.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 +4 -4
- data/CHANGELOG.md +34 -0
- data/lib/pdk/analytics/client/google_analytics.rb +2 -2
- data/lib/pdk/cli/bundle.rb +1 -6
- data/lib/pdk/cli/exec.rb +12 -207
- data/lib/pdk/cli/exec/command.rb +233 -0
- data/lib/pdk/cli/exec/interactive_command.rb +110 -0
- data/lib/pdk/cli/exec_group.rb +1 -1
- data/lib/pdk/cli/new.rb +1 -0
- data/lib/pdk/cli/new/transport.rb +25 -0
- data/lib/pdk/cli/util.rb +1 -1
- data/lib/pdk/cli/util/option_validator.rb +4 -0
- data/lib/pdk/config.rb +8 -1
- data/lib/pdk/config/validator.rb +1 -1
- data/lib/pdk/config/value.rb +1 -1
- data/lib/pdk/generate.rb +1 -0
- data/lib/pdk/generate/module.rb +17 -7
- data/lib/pdk/generate/provider.rb +0 -5
- data/lib/pdk/generate/puppet_object.rb +16 -3
- data/lib/pdk/generate/transport.rb +87 -0
- data/lib/pdk/module/build.rb +25 -3
- data/lib/pdk/module/metadata.rb +6 -6
- data/lib/pdk/module/templatedir.rb +4 -2
- data/lib/pdk/util/git.rb +2 -2
- data/lib/pdk/util/puppet_version.rb +1 -1
- data/lib/pdk/validate/puppet/puppet_epp.rb +137 -0
- data/lib/pdk/validate/puppet_validator.rb +2 -1
- data/lib/pdk/validate/tasks/name.rb +1 -1
- data/lib/pdk/validate/yaml/syntax.rb +2 -0
- data/lib/pdk/version.rb +1 -1
- data/locales/pdk.pot +133 -83
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b3de42650b7bdd05b69c6bb9ee6b0150f628c6e6eb9fb22ff938fcf095cd6f2
|
4
|
+
data.tar.gz: 13c89a19fb58166b235d75259d72e391e66cf3a86269cbaf8257bfdd69761b64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 150e3a0047aaca9f19ee203bda23b07e49b177b91f266bfd63a159bac0772c1888a161a671b7b57d3eccbacbad5aec21f794d4eccd175a0ef0717714d322e81c
|
7
|
+
data.tar.gz: a146f216b223a1f93c362dd646d145cdc6149753981ec266fc78f72b181dd34e1279775d317d9eae5e801e6d94d1094f12f07234e2340cadda675774797966a4
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,39 @@ All changes to this repo will be documented in this file.
|
|
4
4
|
See the [release notes](https://puppet.com/docs/pdk/latest/release_notes.html) for a high-level summary.
|
5
5
|
|
6
6
|
|
7
|
+
## [v1.12.0](https://github.com/puppetlabs/pdk/tree/v1.12.0) (2019-07-31)
|
8
|
+
[Full Changelog](https://github.com/puppetlabs/pdk/compare/v1.11.1...v1.12.0)
|
9
|
+
|
10
|
+
**Implemented enhancements:**
|
11
|
+
|
12
|
+
- \(PDK-421\) Validate EPP syntax [\#680](https://github.com/puppetlabs/pdk/pull/680) ([raphink](https://github.com/raphink))
|
13
|
+
- \(FM-8081\) pdk new transport [\#666](https://github.com/puppetlabs/pdk/pull/666) ([DavidS](https://github.com/DavidS))
|
14
|
+
|
15
|
+
**Fixed bugs:**
|
16
|
+
|
17
|
+
- Checking Ruby code style fails [\#697](https://github.com/puppetlabs/pdk/issues/697)
|
18
|
+
- template-url does not properly match ssh URI [\#653](https://github.com/puppetlabs/pdk/issues/653)
|
19
|
+
- pdk build should fix file + directory rights for tar file [\#618](https://github.com/puppetlabs/pdk/issues/618)
|
20
|
+
|
21
|
+
**Merged pull requests:**
|
22
|
+
|
23
|
+
- \(FIXUP\) Bypass shell invocation for PDK::CLI::Exec::InteractiveCommand [\#717](https://github.com/puppetlabs/pdk/pull/717) ([scotje](https://github.com/scotje))
|
24
|
+
- \(maint\) Expect pdk test unit to run more than 1 test [\#714](https://github.com/puppetlabs/pdk/pull/714) ([rodjek](https://github.com/rodjek))
|
25
|
+
- \(PDK-1309\) Ensure file modes in built modules are sane [\#713](https://github.com/puppetlabs/pdk/pull/713) ([rodjek](https://github.com/rodjek))
|
26
|
+
- \(PDK-641\) Make `pdk bundle` fully interactive [\#712](https://github.com/puppetlabs/pdk/pull/712) ([scotje](https://github.com/scotje))
|
27
|
+
- \(PDK-1366\) Update default operatingsystem versions [\#711](https://github.com/puppetlabs/pdk/pull/711) ([rodjek](https://github.com/rodjek))
|
28
|
+
- \(PDK-421\) Update acceptance tests for EPP Validation [\#709](https://github.com/puppetlabs/pdk/pull/709) ([glennsarti](https://github.com/glennsarti))
|
29
|
+
- \(PDK-1434\) Gracefully handle unparsable bolt analytics config [\#705](https://github.com/puppetlabs/pdk/pull/705) ([rodjek](https://github.com/rodjek))
|
30
|
+
- \(MAINT\) Add debug logging of yaml files being validated [\#704](https://github.com/puppetlabs/pdk/pull/704) ([npwalker](https://github.com/npwalker))
|
31
|
+
- \(maint\) Fix typo in gitignore [\#700](https://github.com/puppetlabs/pdk/pull/700) ([glennsarti](https://github.com/glennsarti))
|
32
|
+
- \(PDK-1333\) Fix command\_spec rake task for newer CRI versions [\#699](https://github.com/puppetlabs/pdk/pull/699) ([glennsarti](https://github.com/glennsarti))
|
33
|
+
- \(PDK-1429\) Bump version to 1.11.2.pre [\#698](https://github.com/puppetlabs/pdk/pull/698) ([scotje](https://github.com/scotje))
|
34
|
+
- \(FM-8081\) pdk new transport [\#696](https://github.com/puppetlabs/pdk/pull/696) ([DavidS](https://github.com/DavidS))
|
35
|
+
- \(maint\) Update beaker in package tests [\#695](https://github.com/puppetlabs/pdk/pull/695) ([rodjek](https://github.com/rodjek))
|
36
|
+
- Revert "Merge pull request \#666 from DavidS/fm-8081-pdk-new-transport" [\#693](https://github.com/puppetlabs/pdk/pull/693) ([DavidS](https://github.com/DavidS))
|
37
|
+
- \(maint\) Message and string fixes [\#676](https://github.com/puppetlabs/pdk/pull/676) ([DavidS](https://github.com/DavidS))
|
38
|
+
- \(PDK-1333\) command\_spec rake task [\#644](https://github.com/puppetlabs/pdk/pull/644) ([rodjek](https://github.com/rodjek))
|
39
|
+
|
7
40
|
## [v1.11.1](https://github.com/puppetlabs/pdk/tree/v1.11.1) (2019-07-01)
|
8
41
|
[Full Changelog](https://github.com/puppetlabs/pdk/compare/v1.11.0...v1.11.1)
|
9
42
|
|
@@ -13,6 +46,7 @@ See the [release notes](https://puppet.com/docs/pdk/latest/release_notes.html) f
|
|
13
46
|
|
14
47
|
**Merged pull requests:**
|
15
48
|
|
49
|
+
- \(PDK-1423\) Release 1.11.1 [\#692](https://github.com/puppetlabs/pdk/pull/692) ([rodjek](https://github.com/rodjek))
|
16
50
|
- \(PDK-1415\) Allow analytics opt-out prompt to be disabled via ENV [\#691](https://github.com/puppetlabs/pdk/pull/691) ([scotje](https://github.com/scotje))
|
17
51
|
- \(PDK-1414\) Detect common CI environments and set non-interactive [\#689](https://github.com/puppetlabs/pdk/pull/689) ([glennsarti](https://github.com/glennsarti))
|
18
52
|
- \(PDK-1409\) Bump PDK version to 1.11.1.pre [\#688](https://github.com/puppetlabs/pdk/pull/688) ([rodjek](https://github.com/rodjek))
|
@@ -39,7 +39,7 @@ module PDK
|
|
39
39
|
|
40
40
|
def screen_view(screen, **kwargs)
|
41
41
|
custom_dimensions = walk_keys(kwargs) do |k|
|
42
|
-
CUSTOM_DIMENSIONS[k] || raise("Unknown analytics key '
|
42
|
+
CUSTOM_DIMENSIONS[k] || raise(_("Unknown analytics key '%{key}'") % { key: k })
|
43
43
|
end
|
44
44
|
|
45
45
|
screen_view_params = {
|
@@ -54,7 +54,7 @@ module PDK
|
|
54
54
|
|
55
55
|
def event(category, action, label: nil, value: nil, **kwargs)
|
56
56
|
custom_dimensions = walk_keys(kwargs) do |k|
|
57
|
-
CUSTOM_DIMENSIONS[k] || raise("Unknown analytics key '
|
57
|
+
CUSTOM_DIMENSIONS[k] || raise(_("Unknown analytics key '%{key}'") % { key: k })
|
58
58
|
end
|
59
59
|
|
60
60
|
event_params = {
|
data/lib/pdk/cli/bundle.rb
CHANGED
@@ -6,8 +6,6 @@ module PDK::CLI
|
|
6
6
|
description _(<<-EOF
|
7
7
|
[experimental] For advanced users, pdk bundle runs arbitrary commands in the bundler environment that pdk manages.
|
8
8
|
Careless use of this command can lead to errors that pdk can't help recover from.
|
9
|
-
|
10
|
-
Note that for PowerShell the '--' needs to be escaped using a backtick: '`--' to avoid it being parsed by the shell.
|
11
9
|
EOF
|
12
10
|
)
|
13
11
|
skip_option_parsing
|
@@ -27,16 +25,13 @@ EOF
|
|
27
25
|
|
28
26
|
gemfile_env = PDK::Util::Bundler::BundleHelper.gemfile_env(puppet_env[:gemset])
|
29
27
|
|
30
|
-
command = PDK::CLI::Exec::
|
28
|
+
command = PDK::CLI::Exec::InteractiveCommand.new(PDK::CLI::Exec.bundle_bin, *args).tap do |c|
|
31
29
|
c.context = :pwd
|
32
30
|
c.update_environment(gemfile_env)
|
33
31
|
end
|
34
32
|
|
35
33
|
result = command.execute!
|
36
34
|
|
37
|
-
$stderr.puts result[:stdout]
|
38
|
-
$stderr.puts result[:stderr]
|
39
|
-
|
40
35
|
exit result[:exit_code]
|
41
36
|
end
|
42
37
|
end
|
data/lib/pdk/cli/exec.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'bundler'
|
2
2
|
require 'childprocess'
|
3
|
+
require 'English'
|
3
4
|
require 'tempfile'
|
4
5
|
require 'tty-spinner'
|
5
6
|
require 'tty-which'
|
@@ -11,6 +12,9 @@ require 'pdk/util/ruby_version'
|
|
11
12
|
module PDK
|
12
13
|
module CLI
|
13
14
|
module Exec
|
15
|
+
require 'pdk/cli/exec/command'
|
16
|
+
require 'pdk/cli/exec/interactive_command'
|
17
|
+
|
14
18
|
def self.execute(*cmd)
|
15
19
|
Command.new(*cmd).execute!
|
16
20
|
end
|
@@ -19,6 +23,14 @@ module PDK
|
|
19
23
|
Command.new(*cmd).tap { |c| c.environment = env }.execute!
|
20
24
|
end
|
21
25
|
|
26
|
+
def self.execute_interactive(*cmd)
|
27
|
+
InteractiveCommand.new(*cmd).execute!
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.execute_interactive_with_env(env, *cmd)
|
31
|
+
InteractiveCommand.new(*cmd).tap { |c| c.environment = env }.execute!
|
32
|
+
end
|
33
|
+
|
22
34
|
def self.ensure_bin_present!(bin_path, bin_name)
|
23
35
|
message = _('Unable to find `%{name}`. Check that it is installed and try again.') % {
|
24
36
|
name: bin_name,
|
@@ -61,213 +73,6 @@ module PDK
|
|
61
73
|
PDK.logger.debug(_("Using '%{vendored_bin}' from PDK package.") % { vendored_bin: vendored_bin_full_path })
|
62
74
|
vendored_bin_full_path
|
63
75
|
end
|
64
|
-
|
65
|
-
# TODO: decide how/when to connect stdin to child process for things like pry
|
66
|
-
# TODO: need a way to set callbacks on new stdout/stderr data
|
67
|
-
class Command
|
68
|
-
attr_reader :argv
|
69
|
-
attr_reader :context
|
70
|
-
attr_accessor :timeout
|
71
|
-
attr_accessor :environment
|
72
|
-
attr_writer :exec_group
|
73
|
-
|
74
|
-
def initialize(*argv)
|
75
|
-
@argv = argv
|
76
|
-
|
77
|
-
@process = ChildProcess.build(*@argv)
|
78
|
-
@process.leader = true
|
79
|
-
|
80
|
-
@stdout = Tempfile.new('stdout').tap { |io| io.sync = true }
|
81
|
-
@stderr = Tempfile.new('stderr').tap { |io| io.sync = true }
|
82
|
-
|
83
|
-
@process.io.stdout = @stdout
|
84
|
-
@process.io.stderr = @stderr
|
85
|
-
|
86
|
-
# Default to running things in the system context.
|
87
|
-
@context = :system
|
88
|
-
|
89
|
-
# Extra environment vars to add to base set.
|
90
|
-
@environment = {}
|
91
|
-
|
92
|
-
# Register the ExecGroup when running in parallel
|
93
|
-
@exec_group = nil
|
94
|
-
end
|
95
|
-
|
96
|
-
def context=(new_context)
|
97
|
-
unless [:system, :module, :pwd].include?(new_context)
|
98
|
-
raise ArgumentError, _("Expected execution context to be :system or :module but got '%{context}'.") % { context: new_context }
|
99
|
-
end
|
100
|
-
|
101
|
-
@context = new_context
|
102
|
-
end
|
103
|
-
|
104
|
-
def register_spinner(spinner, opts = {})
|
105
|
-
return unless PDK::CLI::Util.interactive?
|
106
|
-
@success_message = opts.delete(:success)
|
107
|
-
@failure_message = opts.delete(:failure)
|
108
|
-
|
109
|
-
@spinner = spinner
|
110
|
-
end
|
111
|
-
|
112
|
-
def add_spinner(message, opts = {})
|
113
|
-
return unless PDK::CLI::Util.interactive?
|
114
|
-
@success_message = opts.delete(:success)
|
115
|
-
@failure_message = opts.delete(:failure)
|
116
|
-
|
117
|
-
@spinner = TTY::Spinner.new("[:spinner] #{message}", opts.merge(PDK::CLI::Util.spinner_opts_for_platform))
|
118
|
-
end
|
119
|
-
|
120
|
-
def update_environment(additional_env)
|
121
|
-
@environment.merge!(additional_env)
|
122
|
-
end
|
123
|
-
|
124
|
-
def check_for_legacy_env_vars
|
125
|
-
if ENV['PUPPET_GEM_VERSION']
|
126
|
-
PDK.logger.warn_once _(
|
127
|
-
'PUPPET_GEM_VERSION is not supported by PDK. ' \
|
128
|
-
'Please use the --puppet-version option on your PDK command ' \
|
129
|
-
'or set the PDK_PUPPET_VERSION environment variable instead',
|
130
|
-
)
|
131
|
-
@process.environment['PUPPET_GEM_VERSION'] = nil
|
132
|
-
end
|
133
|
-
|
134
|
-
%w[FACTER HIERA].each do |gem|
|
135
|
-
if ENV["#{gem}_GEM_VERSION"]
|
136
|
-
PDK.logger.warn_once _("#{gem}_GEM_VERSION is not supported by PDK.")
|
137
|
-
@process.environment["#{gem}_GEM_VERSION"] = nil
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
def execute!
|
143
|
-
# Start spinning if configured.
|
144
|
-
@spinner.auto_spin if @spinner
|
145
|
-
|
146
|
-
# Add custom env vars.
|
147
|
-
@environment.each do |k, v|
|
148
|
-
@process.environment[k] = v
|
149
|
-
end
|
150
|
-
|
151
|
-
check_for_legacy_env_vars
|
152
|
-
|
153
|
-
@process.environment['BUNDLE_IGNORE_CONFIG'] = '1'
|
154
|
-
|
155
|
-
if [:module, :pwd].include?(context)
|
156
|
-
@process.environment['GEM_HOME'] = PDK::Util::RubyVersion.gem_home
|
157
|
-
@process.environment['GEM_PATH'] = PDK::Util::RubyVersion.gem_path
|
158
|
-
|
159
|
-
# Make sure invocation of Ruby prefers our private installation.
|
160
|
-
package_binpath = PDK::Util.package_install? ? File.join(PDK::Util.pdk_package_basedir, 'bin') : nil
|
161
|
-
@process.environment['PATH'] = [
|
162
|
-
PDK::Util::RubyVersion.bin_path,
|
163
|
-
File.join(@process.environment['GEM_HOME'], 'bin'),
|
164
|
-
PDK::Util::RubyVersion.gem_paths_raw.map { |gem_path| File.join(gem_path, 'bin') },
|
165
|
-
package_binpath,
|
166
|
-
PDK::Util.package_install? ? PDK::Util::Git.git_paths : nil,
|
167
|
-
ENV['PATH'],
|
168
|
-
].compact.flatten.join(File::PATH_SEPARATOR)
|
169
|
-
|
170
|
-
mod_root = PDK::Util.module_root
|
171
|
-
|
172
|
-
unless mod_root
|
173
|
-
@spinner.error if @spinner
|
174
|
-
|
175
|
-
raise PDK::CLI::FatalError, _('Current working directory is not part of a module. (No metadata.json was found.)')
|
176
|
-
end
|
177
|
-
|
178
|
-
if Dir.pwd == mod_root || context == :pwd
|
179
|
-
run_process_in_clean_env!
|
180
|
-
else
|
181
|
-
Dir.chdir(mod_root) do
|
182
|
-
run_process_in_clean_env!
|
183
|
-
end
|
184
|
-
end
|
185
|
-
else
|
186
|
-
run_process!
|
187
|
-
end
|
188
|
-
|
189
|
-
# Stop spinning when done (if configured).
|
190
|
-
stop_spinner
|
191
|
-
|
192
|
-
@stdout.rewind
|
193
|
-
@stderr.rewind
|
194
|
-
|
195
|
-
process_data = {
|
196
|
-
stdout: @stdout.read,
|
197
|
-
stderr: @stderr.read,
|
198
|
-
exit_code: @process.exit_code,
|
199
|
-
duration: @duration,
|
200
|
-
}
|
201
|
-
|
202
|
-
PDK.logger.debug _('STDOUT: %{output}') % {
|
203
|
-
output: process_data[:stdout].empty? ? 'N/A' : "\n#{process_data[:stdout]}",
|
204
|
-
}
|
205
|
-
PDK.logger.debug _('STDERR: %{output}') % {
|
206
|
-
output: process_data[:stderr].empty? ? 'N/A' : "\n#{process_data[:stderr]}",
|
207
|
-
}
|
208
|
-
|
209
|
-
process_data
|
210
|
-
ensure
|
211
|
-
@stdout.close
|
212
|
-
@stderr.close
|
213
|
-
end
|
214
|
-
|
215
|
-
protected
|
216
|
-
|
217
|
-
def stop_spinner
|
218
|
-
return unless @spinner
|
219
|
-
|
220
|
-
# If it is a single spinner, we need to send it a success/error message
|
221
|
-
if @process.exit_code.zero?
|
222
|
-
@spinner.success(@success_message || '')
|
223
|
-
else
|
224
|
-
@spinner.error(@failure_message || '')
|
225
|
-
end
|
226
|
-
end
|
227
|
-
|
228
|
-
def run_process_in_clean_env!
|
229
|
-
::Bundler.with_clean_env do
|
230
|
-
run_process!
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
def run_process!
|
235
|
-
command_string = argv.join(' ')
|
236
|
-
|
237
|
-
PDK.logger.debug(_("Executing '%{command}'") % { command: command_string })
|
238
|
-
|
239
|
-
if context == :module
|
240
|
-
PDK.logger.debug(_('Command environment:'))
|
241
|
-
@process.environment.each do |var, val|
|
242
|
-
PDK.logger.debug(" #{var}: #{val}")
|
243
|
-
end
|
244
|
-
end
|
245
|
-
|
246
|
-
start_time = Time.now
|
247
|
-
|
248
|
-
begin
|
249
|
-
@process.start
|
250
|
-
rescue ChildProcess::LaunchError => e
|
251
|
-
raise PDK::CLI::FatalError, _("Failed to execute '%{command}': %{message}") % { command: command_string, message: e.message }
|
252
|
-
end
|
253
|
-
|
254
|
-
if timeout
|
255
|
-
begin
|
256
|
-
@process.poll_for_exit(timeout)
|
257
|
-
rescue ChildProcess::TimeoutError
|
258
|
-
@process.stop # tries increasingly harsher methods to kill the process.
|
259
|
-
end
|
260
|
-
else
|
261
|
-
# Wait indfinitely if no timeout set.
|
262
|
-
@process.wait
|
263
|
-
end
|
264
|
-
|
265
|
-
@duration = Time.now - start_time
|
266
|
-
|
267
|
-
PDK.logger.debug(_("Execution of '%{command}' complete (duration: %{duration_in_seconds}s; exit code: %{exit_code})") %
|
268
|
-
{ command: command_string, duration_in_seconds: @duration, exit_code: @process.exit_code })
|
269
|
-
end
|
270
|
-
end
|
271
76
|
end
|
272
77
|
end
|
273
78
|
end
|
@@ -0,0 +1,233 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
require 'childprocess'
|
3
|
+
require 'English'
|
4
|
+
require 'tempfile'
|
5
|
+
require 'tty-spinner'
|
6
|
+
require 'tty-which'
|
7
|
+
|
8
|
+
require 'pdk/util'
|
9
|
+
require 'pdk/util/git'
|
10
|
+
require 'pdk/util/ruby_version'
|
11
|
+
|
12
|
+
module PDK
|
13
|
+
module CLI
|
14
|
+
module Exec
|
15
|
+
class Command
|
16
|
+
attr_reader :argv
|
17
|
+
attr_reader :context
|
18
|
+
attr_accessor :timeout
|
19
|
+
attr_accessor :environment
|
20
|
+
attr_writer :exec_group
|
21
|
+
|
22
|
+
def initialize(*argv)
|
23
|
+
@argv = argv
|
24
|
+
|
25
|
+
@process = ChildProcess.build(*@argv)
|
26
|
+
@process.leader = true
|
27
|
+
|
28
|
+
@stdout = Tempfile.new('stdout').tap { |io| io.sync = true }
|
29
|
+
@stderr = Tempfile.new('stderr').tap { |io| io.sync = true }
|
30
|
+
|
31
|
+
@process.io.stdout = @stdout
|
32
|
+
@process.io.stderr = @stderr
|
33
|
+
|
34
|
+
# Default to running things in the system context.
|
35
|
+
@context = :system
|
36
|
+
|
37
|
+
# Extra environment vars to add to base set.
|
38
|
+
@environment = {}
|
39
|
+
|
40
|
+
# Register the ExecGroup when running in parallel
|
41
|
+
@exec_group = nil
|
42
|
+
end
|
43
|
+
|
44
|
+
def context=(new_context)
|
45
|
+
unless [:system, :module, :pwd].include?(new_context)
|
46
|
+
raise ArgumentError, _("Expected execution context to be :system or :module but got '%{context}'.") % { context: new_context }
|
47
|
+
end
|
48
|
+
|
49
|
+
@context = new_context
|
50
|
+
end
|
51
|
+
|
52
|
+
def register_spinner(spinner, opts = {})
|
53
|
+
return unless PDK::CLI::Util.interactive?
|
54
|
+
@success_message = opts.delete(:success)
|
55
|
+
@failure_message = opts.delete(:failure)
|
56
|
+
|
57
|
+
@spinner = spinner
|
58
|
+
end
|
59
|
+
|
60
|
+
def add_spinner(message, opts = {})
|
61
|
+
return unless PDK::CLI::Util.interactive?
|
62
|
+
@success_message = opts.delete(:success)
|
63
|
+
@failure_message = opts.delete(:failure)
|
64
|
+
|
65
|
+
@spinner = TTY::Spinner.new("[:spinner] #{message}", opts.merge(PDK::CLI::Util.spinner_opts_for_platform))
|
66
|
+
end
|
67
|
+
|
68
|
+
def update_environment(additional_env)
|
69
|
+
@environment.merge!(additional_env)
|
70
|
+
end
|
71
|
+
|
72
|
+
def execute!
|
73
|
+
# Start spinning if configured.
|
74
|
+
@spinner.auto_spin if @spinner
|
75
|
+
|
76
|
+
# Set env for child process
|
77
|
+
resolved_env_for_command.each { |k, v| @process.environment[k] = v }
|
78
|
+
|
79
|
+
if [:module, :pwd].include?(context)
|
80
|
+
mod_root = PDK::Util.module_root
|
81
|
+
|
82
|
+
unless mod_root
|
83
|
+
@spinner.error if @spinner
|
84
|
+
|
85
|
+
raise PDK::CLI::FatalError, _('Current working directory is not part of a module. (No metadata.json was found.)')
|
86
|
+
end
|
87
|
+
|
88
|
+
if Dir.pwd == mod_root || context == :pwd
|
89
|
+
run_process_in_clean_env!
|
90
|
+
else
|
91
|
+
Dir.chdir(mod_root) do
|
92
|
+
run_process_in_clean_env!
|
93
|
+
end
|
94
|
+
end
|
95
|
+
else
|
96
|
+
run_process!
|
97
|
+
end
|
98
|
+
|
99
|
+
# Stop spinning when done (if configured).
|
100
|
+
stop_spinner
|
101
|
+
|
102
|
+
@stdout.rewind
|
103
|
+
@stderr.rewind
|
104
|
+
|
105
|
+
process_data = {
|
106
|
+
stdout: @stdout.read,
|
107
|
+
stderr: @stderr.read,
|
108
|
+
exit_code: @process.exit_code,
|
109
|
+
duration: @duration,
|
110
|
+
}
|
111
|
+
|
112
|
+
PDK.logger.debug _('STDOUT: %{output}') % {
|
113
|
+
output: process_data[:stdout].empty? ? 'N/A' : "\n#{process_data[:stdout]}",
|
114
|
+
}
|
115
|
+
PDK.logger.debug _('STDERR: %{output}') % {
|
116
|
+
output: process_data[:stderr].empty? ? 'N/A' : "\n#{process_data[:stderr]}",
|
117
|
+
}
|
118
|
+
|
119
|
+
process_data
|
120
|
+
ensure
|
121
|
+
@stdout.close
|
122
|
+
@stderr.close
|
123
|
+
end
|
124
|
+
|
125
|
+
protected
|
126
|
+
|
127
|
+
def warn_on_legacy_env_vars!
|
128
|
+
if ENV['PUPPET_GEM_VERSION']
|
129
|
+
PDK.logger.warn_once _(
|
130
|
+
'PUPPET_GEM_VERSION is not supported by PDK. ' \
|
131
|
+
'Use the --puppet-version option on your PDK command ' \
|
132
|
+
'or set the PDK_PUPPET_VERSION environment variable instead',
|
133
|
+
)
|
134
|
+
end
|
135
|
+
|
136
|
+
%w[FACTER HIERA].each do |gem|
|
137
|
+
if ENV["#{gem}_GEM_VERSION"]
|
138
|
+
PDK.logger.warn_once _('%{varname} is not supported by PDK.') % { varname: "#{gem}_GEM_VERSION" }
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def resolved_env_for_command
|
144
|
+
warn_on_legacy_env_vars!
|
145
|
+
|
146
|
+
resolved_env = {}
|
147
|
+
|
148
|
+
resolved_env['TERM'] = ENV['TERM']
|
149
|
+
resolved_env['PUPPET_GEM_VERSION'] = nil
|
150
|
+
resolved_env['FACTER_GEM_VERSION'] = nil
|
151
|
+
resolved_env['HIERA_GEM_VERSION'] = nil
|
152
|
+
|
153
|
+
resolved_env.merge!(@environment.dup)
|
154
|
+
|
155
|
+
resolved_env['BUNDLE_IGNORE_CONFIG'] = '1'
|
156
|
+
|
157
|
+
if [:module, :pwd].include?(context)
|
158
|
+
resolved_env['GEM_HOME'] = PDK::Util::RubyVersion.gem_home
|
159
|
+
resolved_env['GEM_PATH'] = PDK::Util::RubyVersion.gem_path
|
160
|
+
|
161
|
+
# Make sure invocation of Ruby prefers our private installation.
|
162
|
+
package_binpath = PDK::Util.package_install? ? File.join(PDK::Util.pdk_package_basedir, 'bin') : nil
|
163
|
+
|
164
|
+
resolved_env['PATH'] = [
|
165
|
+
PDK::Util::RubyVersion.bin_path,
|
166
|
+
File.join(resolved_env['GEM_HOME'], 'bin'),
|
167
|
+
PDK::Util::RubyVersion.gem_paths_raw.map { |gem_path| File.join(gem_path, 'bin') },
|
168
|
+
package_binpath,
|
169
|
+
PDK::Util.package_install? ? PDK::Util::Git.git_paths : nil,
|
170
|
+
ENV['PATH'],
|
171
|
+
].compact.flatten.join(File::PATH_SEPARATOR)
|
172
|
+
end
|
173
|
+
|
174
|
+
resolved_env
|
175
|
+
end
|
176
|
+
|
177
|
+
def stop_spinner
|
178
|
+
return unless @spinner
|
179
|
+
|
180
|
+
# If it is a single spinner, we need to send it a success/error message
|
181
|
+
if @process.exit_code.zero?
|
182
|
+
@spinner.success(@success_message || '')
|
183
|
+
else
|
184
|
+
@spinner.error(@failure_message || '')
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
def run_process_in_clean_env!
|
189
|
+
::Bundler.with_clean_env do
|
190
|
+
run_process!
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
def run_process!
|
195
|
+
command_string = argv.join(' ')
|
196
|
+
|
197
|
+
PDK.logger.debug(_("Executing '%{command}'") % { command: command_string })
|
198
|
+
|
199
|
+
if context == :module
|
200
|
+
PDK.logger.debug(_('Command environment:'))
|
201
|
+
@process.environment.each do |var, val|
|
202
|
+
PDK.logger.debug(" #{var}: #{val}")
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
start_time = Time.now
|
207
|
+
|
208
|
+
begin
|
209
|
+
@process.start
|
210
|
+
rescue ChildProcess::LaunchError => e
|
211
|
+
raise PDK::CLI::FatalError, _("Failed to execute '%{command}': %{message}") % { command: command_string, message: e.message }
|
212
|
+
end
|
213
|
+
|
214
|
+
if timeout
|
215
|
+
begin
|
216
|
+
@process.poll_for_exit(timeout)
|
217
|
+
rescue ChildProcess::TimeoutError
|
218
|
+
@process.stop # tries increasingly harsher methods to kill the process.
|
219
|
+
end
|
220
|
+
else
|
221
|
+
# Wait indfinitely if no timeout set.
|
222
|
+
@process.wait
|
223
|
+
end
|
224
|
+
|
225
|
+
@duration = Time.now - start_time
|
226
|
+
|
227
|
+
PDK.logger.debug(_("Execution of '%{command}' complete (duration: %{duration_in_seconds}s; exit code: %{exit_code})") %
|
228
|
+
{ command: command_string, duration_in_seconds: @duration, exit_code: @process.exit_code })
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|