vanagon 0.15.38 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -284,6 +284,17 @@ class Vanagon
284
284
  @platform.docker_run_args = Array(args)
285
285
  end
286
286
 
287
+ # Specify whether to use Docker exec instead of SSH to run commands
288
+ #
289
+ # This also causes Vanagon to use `docker cp` instead of `rsync` when
290
+ # copying files.
291
+ #
292
+ # @param bool [Boolean] a boolean value indicating whether to use
293
+ # `docker exec` and `docker cp` over `ssh` and `rsync`.
294
+ def use_docker_exec(bool)
295
+ @platform.use_docker_exec = bool
296
+ end
297
+
287
298
  # Set the ami for the platform to use
288
299
  #
289
300
  # @param ami [String] the ami id used.
@@ -0,0 +1,80 @@
1
+ require 'vanagon/cli'
2
+
3
+ ##
4
+ ## Ignore the CLI calling 'exit'
5
+ ##
6
+ RSpec.configure do |rspec|
7
+ rspec.around(:example) do |ex|
8
+ begin
9
+ ex.run
10
+ rescue SystemExit => e
11
+ puts "Got SystemExit: #{e.inspect}. Ignoring"
12
+ end
13
+ end
14
+ end
15
+
16
+ describe Vanagon::CLI do
17
+ describe "options that don't take a value" do
18
+ [:skipcheck, :verbose].each do |flag|
19
+ it "can create an option parser that accepts the #{flag} flag" do
20
+ subject = described_class.new
21
+ expect(subject.parse(%W[build --#{flag} project platform])).to have_key(flag)
22
+ end
23
+ end
24
+
25
+ describe "short options" do
26
+ [["v", :verbose]].each do |short, long|
27
+ it "maps the short option #{short} to #{long}" do
28
+ subject = described_class.new
29
+ expect(subject.parse(%W[build -#{short} project platform])).to include(long => true)
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ describe "options that only allow limited values" do
36
+ [[:preserve, ["always", "never", "on-failure"]]].each do |option, values|
37
+ values.each do |value|
38
+ it "can create a parser that accepts \"--#{option} #{value}\"" do
39
+ subject = described_class.new
40
+ expect(subject.parse(%W[build --#{option} #{value} project platform]))
41
+ .to include(option => value.to_sym)
42
+ end
43
+ end
44
+ end
45
+ [[:preserve, ["bad-argument"]]].each do |option, values|
46
+ values.each do |value|
47
+ it "rejects the bad argument \"--#{option} #{value}\"" do
48
+ subject = described_class.new
49
+ expect{subject.parse(%W[build --#{option} #{value} project platform])}
50
+ .to raise_error(Vanagon::InvalidArgument)
51
+ end
52
+ end
53
+ end
54
+ it "preserve defaults to :on-failure" do
55
+ subject = described_class.new
56
+ expect(subject.parse([])).to include(:preserve => :'on-failure')
57
+ end
58
+ end
59
+
60
+
61
+ describe "options that take a value" do
62
+ [:workdir, :configdir, :engine].each do |option|
63
+ it "can create an option parser that accepts the #{option} option" do
64
+ subject = described_class.new
65
+ expect(subject.parse(%W[build --#{option} hello project platform]))
66
+ .to include(option => "hello")
67
+ end
68
+ end
69
+
70
+ describe "short options" do
71
+ [["w", :workdir], ["c", :configdir], ["e", :engine]].each do |short, long|
72
+ it "maps the short option #{short} to #{long}" do
73
+ subject = described_class.new
74
+ expect(subject.parse(%W[build -#{short} hello project platform]))
75
+ .to include(long => "hello")
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -1,21 +1,36 @@
1
1
  require 'vanagon/engine/docker'
2
2
  require 'vanagon/platform'
3
3
 
4
- describe 'Vanagon::Engine::Docker' do
5
- let (:platform_with_docker_image) {
6
- plat = Vanagon::Platform::DSL.new('debian-6-i386')
7
- plat.instance_eval("platform 'debian-6-i386' do |plat|
8
- plat.docker_image 'debian-6-i386'
9
- end")
4
+ describe Vanagon::Engine::Docker do
5
+ let (:platform_with_docker_image) do
6
+ plat = Vanagon::Platform::DSL.new('debian-10-amd64')
7
+ plat.instance_eval(<<~EOF)
8
+ platform 'debian-10-amd64' do |plat|
9
+ plat.docker_image 'debian:10-slim'
10
+ end
11
+ EOF
10
12
  plat._platform
11
- }
13
+ end
12
14
 
13
- let (:platform_without_docker_image) {
14
- plat = Vanagon::Platform::DSL.new('debian-6-i386')
15
- plat.instance_eval("platform 'debian-6-i386' do |plat|
16
- end")
15
+ let (:platform_without_docker_image) do
16
+ plat = Vanagon::Platform::DSL.new('debian-10-amd64')
17
+ plat.instance_eval(<<~EOF)
18
+ platform 'debian-10-amd64' do |plat|
19
+ end
20
+ EOF
21
+ plat._platform
22
+ end
23
+
24
+ let(:platform_with_docker_exec) do
25
+ plat = Vanagon::Platform::DSL.new('debian-10-amd64')
26
+ plat.instance_eval(<<~EOF)
27
+ platform 'debian-10-amd64' do |plat|
28
+ plat.docker_image 'debian:10-slim'
29
+ plat.use_docker_exec true
30
+ end
31
+ EOF
17
32
  plat._platform
18
- }
33
+ end
19
34
 
20
35
  describe '#initialize' do
21
36
  it 'fails without docker installed' do
@@ -23,24 +38,67 @@ describe 'Vanagon::Engine::Docker' do
23
38
  expect(FileTest).to receive(:executable?).with(File.join(path_elem, 'docker')).and_return(false)
24
39
  end
25
40
 
26
- expect { Vanagon::Engine::Docker.new(platform_with_docker_image) }.to raise_error(RuntimeError)
41
+ expect { described_class.new(platform_with_docker_image) }.to raise_error(RuntimeError)
27
42
  end
28
43
  end
29
44
 
30
45
  describe "#validate_platform" do
31
46
  it 'raises an error if the platform is missing a required attribute' do
32
47
  expect(Vanagon::Utilities).to receive(:find_program_on_path).with('docker').and_return('/usr/bin/docker')
33
- expect { Vanagon::Engine::Docker.new(platform_without_docker_image).validate_platform }.to raise_error(Vanagon::Error)
48
+ expect { described_class.new(platform_without_docker_image).validate_platform }.to raise_error(Vanagon::Error)
34
49
  end
35
50
 
36
51
  it 'returns true if the platform has the required attributes' do
37
52
  expect(Vanagon::Utilities).to receive(:find_program_on_path).with('docker').and_return('/usr/bin/docker')
38
- expect(Vanagon::Engine::Docker.new(platform_with_docker_image).validate_platform).to be(true)
53
+ expect(described_class.new(platform_with_docker_image).validate_platform).to be(true)
39
54
  end
40
55
  end
41
56
 
42
57
  it 'returns "docker" name' do
43
58
  expect(Vanagon::Utilities).to receive(:find_program_on_path).with('docker').and_return('/usr/bin/docker')
44
- expect(Vanagon::Engine::Docker.new(platform_with_docker_image).name).to eq('docker')
59
+ expect(described_class.new(platform_with_docker_image).name).to eq('docker')
60
+ end
61
+
62
+ describe '#dispatch' do
63
+ context 'when platform has use_docker_exec set' do
64
+ subject { described_class.new(platform_with_docker_exec) }
65
+
66
+ it 'uses docker exec' do
67
+ expect(Vanagon::Utilities).to receive(:remote_ssh_command).never
68
+ expect(subject).to receive(:docker_exec)
69
+
70
+ subject.dispatch('true', true)
71
+ end
72
+ end
73
+ end
74
+
75
+ describe '#ship_workdir' do
76
+ context 'when platform has use_docker_exec set' do
77
+ subject { described_class.new(platform_with_docker_exec) }
78
+
79
+ it 'uses docker cp' do
80
+ expect(Vanagon::Utilities).to receive(:rsync_to).never
81
+ expect(subject).to receive(:docker_cp_globs_to)
82
+
83
+ subject.ship_workdir('foo/')
84
+ end
85
+ end
86
+ end
87
+
88
+ describe '#retrieve_built_artifact' do
89
+ context 'when platform has use_docker_exec set' do
90
+ subject { described_class.new(platform_with_docker_exec) }
91
+
92
+ before(:each) do
93
+ allow(FileUtils).to receive(:mkdir_p)
94
+ end
95
+
96
+ it 'uses docker cp' do
97
+ expect(Vanagon::Utilities).to receive(:rsync_from).never
98
+ expect(subject).to receive(:docker_cp_globs_from)
99
+
100
+ subject.retrieve_built_artifact('output/*', false)
101
+ end
102
+ end
45
103
  end
46
104
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vanagon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.38
4
+ version: 0.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet Labs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-16 00:00:00.000000000 Z
11
+ date: 2020-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: docopt
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: git
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -70,6 +84,7 @@ description: Vanagon is a tool to build a single package out of a project, which
70
84
  itself contain one or more components.
71
85
  email: info@puppet.com
72
86
  executables:
87
+ - vanagon
73
88
  - build
74
89
  - inspect
75
90
  - ship
@@ -91,10 +106,19 @@ files:
91
106
  - bin/repo
92
107
  - bin/ship
93
108
  - bin/sign
109
+ - bin/vanagon
94
110
  - lib/git/basic_submodules.rb
95
111
  - lib/git/rev_list.rb
96
112
  - lib/makefile.rb
97
113
  - lib/vanagon.rb
114
+ - lib/vanagon/cli.rb
115
+ - lib/vanagon/cli/build.rb
116
+ - lib/vanagon/cli/build_host_info.rb
117
+ - lib/vanagon/cli/build_requirements.rb
118
+ - lib/vanagon/cli/inspect.rb
119
+ - lib/vanagon/cli/render.rb
120
+ - lib/vanagon/cli/ship.rb
121
+ - lib/vanagon/cli/sign.rb
98
122
  - lib/vanagon/common.rb
99
123
  - lib/vanagon/common/pathname.rb
100
124
  - lib/vanagon/common/user.rb
@@ -120,7 +144,6 @@ files:
120
144
  - lib/vanagon/extensions/ostruct/json.rb
121
145
  - lib/vanagon/extensions/set/json.rb
122
146
  - lib/vanagon/extensions/string.rb
123
- - lib/vanagon/optparse.rb
124
147
  - lib/vanagon/patch.rb
125
148
  - lib/vanagon/platform.rb
126
149
  - lib/vanagon/platform/deb.rb
@@ -204,6 +227,7 @@ files:
204
227
  - spec/fixtures/wix/resources/windows/wix/ui/ui-sample-1.wxs
205
228
  - spec/lib/git/rev_list_spec.rb
206
229
  - spec/lib/makefile_spec.rb
230
+ - spec/lib/vanagon/cli_spec.rb
207
231
  - spec/lib/vanagon/common/pathname_spec.rb
208
232
  - spec/lib/vanagon/common/user_spec.rb
209
233
  - spec/lib/vanagon/component/dsl_spec.rb
@@ -226,7 +250,6 @@ files:
226
250
  - spec/lib/vanagon/extensions/ostruct/json_spec.rb
227
251
  - spec/lib/vanagon/extensions/set/json_spec.rb
228
252
  - spec/lib/vanagon/extensions/string_spec.rb
229
- - spec/lib/vanagon/optparse_spec.rb
230
253
  - spec/lib/vanagon/platform/deb_spec.rb
231
254
  - spec/lib/vanagon/platform/dsl_spec.rb
232
255
  - spec/lib/vanagon/platform/osx_spec.rb
@@ -265,41 +288,41 @@ signing_key:
265
288
  specification_version: 3
266
289
  summary: All of your packages will fit into this van with this one simple trick.
267
290
  test_files:
268
- - spec/lib/git/rev_list_spec.rb
269
- - spec/lib/vanagon/driver_spec.rb
270
- - spec/lib/vanagon/project_spec.rb
271
- - spec/lib/vanagon/utilities/shell_utilities_spec.rb
272
- - spec/lib/vanagon/utilities_spec.rb
273
- - spec/lib/vanagon/platform/solaris_10_spec.rb
291
+ - spec/lib/vanagon/platform/rpm/aix_spec.rb
292
+ - spec/lib/vanagon/platform/osx_spec.rb
293
+ - spec/lib/vanagon/platform/windows_spec.rb
274
294
  - spec/lib/vanagon/platform/rpm_spec.rb
295
+ - spec/lib/vanagon/platform/deb_spec.rb
275
296
  - spec/lib/vanagon/platform/solaris_11_spec.rb
297
+ - spec/lib/vanagon/platform/solaris_10_spec.rb
276
298
  - spec/lib/vanagon/platform/dsl_spec.rb
277
- - spec/lib/vanagon/platform/deb_spec.rb
278
- - spec/lib/vanagon/platform/windows_spec.rb
279
- - spec/lib/vanagon/platform/osx_spec.rb
280
- - spec/lib/vanagon/platform/rpm/aix_spec.rb
281
- - spec/lib/vanagon/component/source_spec.rb
282
- - spec/lib/vanagon/component/dsl_spec.rb
299
+ - spec/lib/vanagon/driver_spec.rb
300
+ - spec/lib/vanagon/project/dsl_spec.rb
301
+ - spec/lib/vanagon/utilities_spec.rb
302
+ - spec/lib/vanagon/cli_spec.rb
303
+ - spec/lib/vanagon/environment_spec.rb
283
304
  - spec/lib/vanagon/component/rules_spec.rb
284
- - spec/lib/vanagon/component/source/http_spec.rb
305
+ - spec/lib/vanagon/component/source_spec.rb
285
306
  - spec/lib/vanagon/component/source/local_spec.rb
286
- - spec/lib/vanagon/component/source/rewrite_spec.rb
287
307
  - spec/lib/vanagon/component/source/git_spec.rb
288
- - spec/lib/vanagon/engine/docker_spec.rb
289
- - spec/lib/vanagon/engine/hardware_spec.rb
290
- - spec/lib/vanagon/engine/ec2_spec.rb
291
- - spec/lib/vanagon/engine/base_spec.rb
308
+ - spec/lib/vanagon/component/source/http_spec.rb
309
+ - spec/lib/vanagon/component/source/rewrite_spec.rb
310
+ - spec/lib/vanagon/component/dsl_spec.rb
311
+ - spec/lib/vanagon/utilities/shell_utilities_spec.rb
312
+ - spec/lib/vanagon/extensions/set/json_spec.rb
313
+ - spec/lib/vanagon/extensions/string_spec.rb
314
+ - spec/lib/vanagon/extensions/ostruct/json_spec.rb
315
+ - spec/lib/vanagon/component_spec.rb
316
+ - spec/lib/vanagon/platform_spec.rb
292
317
  - spec/lib/vanagon/engine/local_spec.rb
293
- - spec/lib/vanagon/engine/pooler_spec.rb
318
+ - spec/lib/vanagon/engine/hardware_spec.rb
294
319
  - spec/lib/vanagon/engine/always_be_scheduling_spec.rb
295
- - spec/lib/vanagon/platform_spec.rb
296
- - spec/lib/vanagon/project/dsl_spec.rb
297
- - spec/lib/vanagon/optparse_spec.rb
298
- - spec/lib/vanagon/component_spec.rb
299
- - spec/lib/vanagon/extensions/ostruct/json_spec.rb
300
- - spec/lib/vanagon/extensions/string_spec.rb
301
- - spec/lib/vanagon/extensions/set/json_spec.rb
320
+ - spec/lib/vanagon/engine/pooler_spec.rb
321
+ - spec/lib/vanagon/engine/base_spec.rb
322
+ - spec/lib/vanagon/engine/ec2_spec.rb
323
+ - spec/lib/vanagon/engine/docker_spec.rb
302
324
  - spec/lib/vanagon/common/user_spec.rb
303
325
  - spec/lib/vanagon/common/pathname_spec.rb
304
- - spec/lib/vanagon/environment_spec.rb
326
+ - spec/lib/vanagon/project_spec.rb
305
327
  - spec/lib/makefile_spec.rb
328
+ - spec/lib/git/rev_list_spec.rb
@@ -1,86 +0,0 @@
1
- require 'optparse'
2
-
3
- class Vanagon
4
- class OptParse
5
- def initialize(banner, symbols = []) # rubocop:disable Metrics/AbcSize
6
- ## symbols array kept for backward compatibility but ignored
7
-
8
- @options = Hash.new
9
- @options[:preserve] = :'on-failure'
10
-
11
- @option_parser = OptionParser.new do |opts| # rubocop:disable Metrics/BlockLength
12
- opts.banner = banner
13
- opts.separator ""
14
- opts.separator "Options:"
15
-
16
- opts.on("-h",
17
- "--help",
18
- "Display help") do
19
- $stdout.puts opts
20
- exit 1
21
- end
22
-
23
- opts.on("-v",
24
- "--verbose",
25
- "Verbose output (does nothing)") do |verbose|
26
- @options[:verbose] = verbose
27
- end
28
-
29
- opts.on("-w DIRECTORY",
30
- "--workdir DIRECTORY",
31
- "Working directory on the local host (defaults to calling mktemp)") do |workdir|
32
- @options[:workdir] = workdir
33
- end
34
-
35
- opts.on("-r DIRECTORY",
36
- "--remote-workdir DIRECTORY",
37
- "Working directory on the remote host (defaults to calling mktemp)") do |remote|
38
- @options[:"remote-workdir"] = remote
39
- end
40
-
41
- opts.on("-c DIRECTORY",
42
- "--configdir DIRECTORY",
43
- "Configuration directory (defaults to $CWD/configs)") do |configuration_directory|
44
- @options[:configdir] = configuration_directory
45
- end
46
-
47
- opts.on("-e ENGINE",
48
- "--engine ENGINE",
49
- "Custom engine to use [base, local, docker, pooler] (defaults to \"pooler\")") do |engine|
50
- @options[:engine] = engine
51
- end
52
-
53
- opts.on("--skipcheck",
54
- "Skip the \"check\" stage when building components") do |skipcheck|
55
- @options[:skipcheck] = skipcheck
56
- end
57
-
58
- opts.on("-p [RULE]",
59
- "--preserve [RULE]",
60
- ["never", "on-failure", "always"],
61
- "Rule for VM preservation. [never, on-failure, always]") do |rule|
62
- if rule.nil?
63
- @options[:preserve] = :always
64
- else
65
- @options[:preserve] = rule.to_sym
66
- end
67
- end
68
-
69
- opts.on("--only-build COMPONENT,COMPONENT,...",
70
- Array,
71
- "Only build listed COMPONENTs") do |components|
72
- @options[:only_build] = components
73
- end
74
- end
75
- end
76
-
77
- def parse!(args)
78
- @option_parser.parse!(args)
79
- @options
80
- end
81
-
82
- def to_s
83
- @optparse.to_s
84
- end
85
- end
86
- end