specinfra 2.88.2 → 2.89.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/lib/specinfra/backend/dockercli.rb +34 -0
- data/lib/specinfra/backend.rb +1 -0
- data/lib/specinfra/version.rb +1 -1
- data/lib/specinfra.rb +1 -0
- data/spec/backend/dockercli/build_command_spec.rb +118 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e50bdeee324833215a1b15370cfc44ef242b6c52dfd9dac888bd2391fb9e7de
|
4
|
+
data.tar.gz: a99274248ab6323eea1f84a5692bb73aab86288169e70ee71d743a981b0a5e13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9fa6eacae5f42b7dca7743d83b052e0bdd9e3077649baa0638c3ba9bc7e7f6f3d2f8faa743c5bf3a36fdda7e7d068868f57830cdcf19b33a21f3519aa08a3849
|
7
|
+
data.tar.gz: 97227f5e2114863c8afee052c8dd207fa4a2f20bc07b5e4c8b43a030cd44811764f7fb1ab0c16267dfc4bcf2c8968d6b87cd7c0944b567db0f8d0a025edac503
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Specinfra
|
4
|
+
module Backend
|
5
|
+
# Docker command line transport
|
6
|
+
class Dockercli < Exec
|
7
|
+
def build_command(cmd)
|
8
|
+
docker_cmd = %w[docker exec]
|
9
|
+
docker_cmd << '--interactive' if get_config(:interactive_shell)
|
10
|
+
docker_cmd << '--tty' if get_config(:request_pty)
|
11
|
+
docker_cmd << instance
|
12
|
+
(docker_cmd << super(cmd)).join(' ')
|
13
|
+
end
|
14
|
+
|
15
|
+
def send_file(from, to)
|
16
|
+
to = Pathname.new(to).dirname.to_s if File.directory?(from)
|
17
|
+
cmd = %W[docker cp #{from} #{instance}:#{to}]
|
18
|
+
spawn_command(cmd.join(' '))
|
19
|
+
end
|
20
|
+
|
21
|
+
def send_directory(from, to)
|
22
|
+
send_file(from, to)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def instance
|
28
|
+
raise 'Please specify docker_container' unless (container = get_config(:docker_container))
|
29
|
+
|
30
|
+
container
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/specinfra/backend.rb
CHANGED
@@ -5,6 +5,7 @@ require 'specinfra/backend/powershell/script_helper'
|
|
5
5
|
require 'specinfra/backend/powershell/command'
|
6
6
|
require 'specinfra/backend/cmd'
|
7
7
|
require 'specinfra/backend/docker'
|
8
|
+
require 'specinfra/backend/dockercli'
|
8
9
|
require 'specinfra/backend/lxc'
|
9
10
|
require 'specinfra/backend/lxd'
|
10
11
|
require 'specinfra/backend/winrm'
|
data/lib/specinfra/version.rb
CHANGED
data/lib/specinfra.rb
CHANGED
@@ -35,6 +35,7 @@ if defined?(RSpec)
|
|
35
35
|
c.add_setting :scp, :default => nil
|
36
36
|
c.add_setting :sudo_password, :default => nil
|
37
37
|
c.add_setting :winrm, :default => nil
|
38
|
+
c.add_setting :docker_container, :default => nil
|
38
39
|
c.add_setting :architecture, :default => :x86_64
|
39
40
|
Specinfra.configuration.defaults.each { |k, v| c.add_setting k, :default => v }
|
40
41
|
c.before :each do
|
@@ -0,0 +1,118 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'shellwords'
|
5
|
+
|
6
|
+
describe Specinfra::Backend::Dockercli do
|
7
|
+
let(:interactive_shell) { false }
|
8
|
+
let(:login_shell) { false }
|
9
|
+
let(:request_pty) { false }
|
10
|
+
let(:shell) { '/bin/sh' }
|
11
|
+
let(:docker_container) { 'instance' }
|
12
|
+
let(:path) { nil }
|
13
|
+
let(:docker_exec) do
|
14
|
+
cmd = %w[docker exec]
|
15
|
+
cmd << '--interactive' if interactive_shell
|
16
|
+
cmd << '--tty' if request_pty
|
17
|
+
cmd << docker_container
|
18
|
+
cmd << "env PATH=\"#{path}\"" if path
|
19
|
+
cmd << shell.shellescape
|
20
|
+
cmd << '-i' if interactive_shell
|
21
|
+
cmd << '-l' if login_shell
|
22
|
+
cmd << '-c'
|
23
|
+
cmd.join(' ')
|
24
|
+
end
|
25
|
+
|
26
|
+
before(:each) do
|
27
|
+
set :backend, :dockercli
|
28
|
+
RSpec.configure do |c|
|
29
|
+
c.request_pty = request_pty
|
30
|
+
c.interactive_shell = interactive_shell
|
31
|
+
c.docker_container = docker_container
|
32
|
+
c.path = path
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
after(:each) do
|
37
|
+
Specinfra::Backend::Dockercli.clear
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#build_command' do
|
41
|
+
context 'without required docker_container set' do
|
42
|
+
let(:docker_container) { nil }
|
43
|
+
it {
|
44
|
+
expect { subject.build_command('true') }.to raise_error(RuntimeError, /docker_container/)
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'with simple command' do
|
49
|
+
it 'should escape spaces' do
|
50
|
+
expect(subject.build_command('test -f /etc/passwd')).to eq "#{docker_exec} test\\ -f\\ /etc/passwd"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'with complex command' do
|
55
|
+
it 'should escape special chars' do
|
56
|
+
expect(subject.build_command('test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)'))
|
57
|
+
.to eq "#{docker_exec} test\\ \\!\\ -f\\ /etc/selinux/config\\ \\|\\|\\ \\(getenforce\\ \\|\\ grep\\ -i\\ --\\ disabled\\ \\&\\&\\ grep\\ -i\\ --\\ \\^SELINUX\\=disabled\\$\\ /etc/selinux/config\\)"
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should escape quotes' do
|
61
|
+
if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.7')
|
62
|
+
expect(subject.build_command(%Q(find /etc/apt/ -name \*.list | xargs grep -o -E "^deb +[\\"']?http://ppa.launchpad.net/gluster/glusterfs-3.7"))).to eq("#{docker_exec} find\\ /etc/apt/\\ -name\\ \\*.list\\ \\|\\ xargs\\ grep\\ -o\\ -E\\ \\\"\\^deb\\ \\+\\[\\\\\\\"\\'\\]\\?http://ppa.launchpad.net/gluster/glusterfs-3.7\\\"")
|
63
|
+
else
|
64
|
+
# Since Ruby 2.7, `+` is not escaped.
|
65
|
+
expect(subject.build_command(%Q(find /etc/apt/ -name \*.list | xargs grep -o -E "^deb +[\\"']?http://ppa.launchpad.net/gluster/glusterfs-3.7"))).to eq("#{docker_exec} find\\ /etc/apt/\\ -name\\ \\*.list\\ \\|\\ xargs\\ grep\\ -o\\ -E\\ \\\"\\^deb\\ +\\[\\\\\\\"\\'\\]\\?http://ppa.launchpad.net/gluster/glusterfs-3.7\\\"")
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'with custom shell' do
|
71
|
+
let(:shell) { '/usr/local/bin/tcsh' }
|
72
|
+
|
73
|
+
it 'should use custom shell' do
|
74
|
+
expect(subject.build_command('test -f /etc/passwd')).to eq "#{docker_exec} test\\ -f\\ /etc/passwd"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'with custom shell that needs escaping' do
|
79
|
+
let(:shell) { '/usr/test & spec/bin/sh' }
|
80
|
+
|
81
|
+
it 'should use custom shell' do
|
82
|
+
expect(subject.build_command('test -f /etc/passwd')).to eq "#{docker_exec} test\\ -f\\ /etc/passwd"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
context 'with an interactive shell' do
|
87
|
+
let(:interactive_shell) { true }
|
88
|
+
|
89
|
+
it 'should emulate an interactive shell' do
|
90
|
+
expect(subject.build_command('test -f /etc/passwd')).to eq "#{docker_exec} test\\ -f\\ /etc/passwd"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context 'with an login shell' do
|
95
|
+
let(:login_shell) { true }
|
96
|
+
|
97
|
+
it 'should emulate an login shell' do
|
98
|
+
expect(subject.build_command('test -f /etc/passwd')).to eq "#{docker_exec} test\\ -f\\ /etc/passwd"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context 'with custom path' do
|
103
|
+
let(:path) { '/opt/bin:/opt/foo/bin:$PATH' }
|
104
|
+
|
105
|
+
it 'should use custom path' do
|
106
|
+
expect(subject.build_command('test -f /etc/passwd')).to eq "#{docker_exec} test\\ -f\\ /etc/passwd"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context 'with custom path that needs escaping' do
|
111
|
+
let(:path) { '/opt/bin:/opt/test & spec/bin:$PATH' }
|
112
|
+
|
113
|
+
it 'should use custom path' do
|
114
|
+
expect(subject.build_command('test -f /etc/passwd')).to eq "#{docker_exec} test\\ -f\\ /etc/passwd"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: specinfra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.89.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gosuke Miyashita
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-03-
|
11
|
+
date: 2024-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-scp
|
@@ -124,6 +124,7 @@ files:
|
|
124
124
|
- lib/specinfra/backend/base.rb
|
125
125
|
- lib/specinfra/backend/cmd.rb
|
126
126
|
- lib/specinfra/backend/docker.rb
|
127
|
+
- lib/specinfra/backend/dockercli.rb
|
127
128
|
- lib/specinfra/backend/dockerfile.rb
|
128
129
|
- lib/specinfra/backend/exec.rb
|
129
130
|
- lib/specinfra/backend/jexec.rb
|
@@ -515,6 +516,7 @@ files:
|
|
515
516
|
- lib/specinfra/properties.rb
|
516
517
|
- lib/specinfra/runner.rb
|
517
518
|
- lib/specinfra/version.rb
|
519
|
+
- spec/backend/dockercli/build_command_spec.rb
|
518
520
|
- spec/backend/exec/build_command_spec.rb
|
519
521
|
- spec/backend/exec/child_process_spec.rb
|
520
522
|
- spec/backend/exec/consume_exited_process_spec.rb
|
@@ -665,6 +667,7 @@ test_files:
|
|
665
667
|
- Gemfile
|
666
668
|
- specinfra.gemspec
|
667
669
|
- Rakefile
|
670
|
+
- spec/backend/dockercli/build_command_spec.rb
|
668
671
|
- spec/backend/exec/build_command_spec.rb
|
669
672
|
- spec/backend/exec/child_process_spec.rb
|
670
673
|
- spec/backend/exec/consume_exited_process_spec.rb
|