specinfra 2.17.1 → 2.18.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 95957f49bb4305b2517ce5b6850b7f6e099cc3ce
4
- data.tar.gz: 49b26004b03a66d83d4dcf0bdb6c3e471ea63b50
3
+ metadata.gz: 986714dbef8eb87fe3feeec2a68f47b3d54c93e7
4
+ data.tar.gz: 462409f9a83ca31793a5878c39aebab6cd4d1843
5
5
  SHA512:
6
- metadata.gz: 76bfa75a89269273dba700ec9d0bbc824f4e7e2b5846d2109b7e896be97c29f8a184af0d484824e88454a4786b43639703f031f6e78722aea8260fb7af6b8f40
7
- data.tar.gz: f269df1a92d3305f0ec60697f491eef385cb9975e3acbad5d2ec500b3ced054170c001defac00fbef14515630fdd929ac1f536759244e6ec90973c46d056c09d
6
+ metadata.gz: 247447e1066bfbb554f3da2d3b038e35f0f1b760158d3f21b374447095e4240d1656523706bb753a58ba5ea1887220c4ddd3f21fd73cc762ebf6602367425359
7
+ data.tar.gz: 57c398cabc517e9df36f0775655c9555bda4ee0a21a0634102229f8bb2e0a027b6da570be93168e0116f468d698efbe84c1593d78c11746cb6053a2bf7a78cda
@@ -13,8 +13,7 @@ module Specinfra::Backend
13
13
  @images = []
14
14
  @base_image = ::Docker::Image.get(image)
15
15
 
16
- env = Specinfra.configuration.env || {}
17
- create_and_start_container(env)
16
+ create_and_start_container
18
17
  ObjectSpace.define_finalizer(self, proc { cleanup_container })
19
18
  elsif container = Specinfra.configuration.docker_container
20
19
  @container = ::Docker::Container.get(container)
@@ -49,7 +48,7 @@ module Specinfra::Backend
49
48
 
50
49
  private
51
50
 
52
- def create_and_start_container(env)
51
+ def create_and_start_container
53
52
  opts = { 'Image' => current_image.id }
54
53
 
55
54
  if current_image.json["Config"]["Cmd"].nil?
@@ -60,10 +59,13 @@ module Specinfra::Backend
60
59
  (opts['Env'] ||= []) << "PATH=#{path}"
61
60
  end
62
61
 
63
- if env
64
- opts['Env'] = (opts['Env'] || []) + env.map { |k,v| [k,v].join('=') }
62
+ if Specinfra.configuration.env.any?
63
+ env = Specinfra.configuration.env.to_a.map { |v| v.join('=') }
64
+ opts['Env'] = opts['Env'].to_a.concat(env)
65
65
  end
66
66
 
67
+ opts.merge!(Specinfra.configuration.docker_container_create_options || {})
68
+
67
69
  @container = ::Docker::Container.create(opts)
68
70
  @container.start
69
71
  end
@@ -78,13 +80,17 @@ module Specinfra::Backend
78
80
  end
79
81
 
80
82
  def docker_run!(cmd, opts={})
81
- begin
82
- stdout, stderr, status = @container.exec(['/bin/sh', '-c', cmd])
83
- return CommandResult.new :stdout => stdout.join, :stderr => stderr.join,
84
- :exit_status => status
85
- rescue
86
- @container.kill
87
- end
83
+ stdout, stderr, status = @container.exec(['/bin/sh', '-c', cmd])
84
+
85
+ CommandResult.new :stdout => stdout.join, :stderr => stderr.join,
86
+ :exit_status => status
87
+ rescue ::Docker::Error::DockerError => e
88
+ raise
89
+ rescue => e
90
+ @container.kill
91
+ err = stderr.nil? ? ([e.message] + e.backtrace) : stderr
92
+ CommandResult.new :stdout => [stdout].join, :stderr => err.join,
93
+ :exit_status => (status || 1)
88
94
  end
89
95
  end
90
96
  end
@@ -0,0 +1,19 @@
1
+ class Specinfra::Command::Alpine::Base::Package < Specinfra::Command::Linux::Base::Package
2
+ class << self
3
+ def check_is_installed(package, version = nil)
4
+ pkg = [escape(package), version].compact.join('=')
5
+ "apk info -qe #{pkg}"
6
+ end
7
+
8
+ alias_method :check_is_installed_by_apk, :check_is_installed
9
+
10
+ def install(package, version = nil, _option = '')
11
+ pkg = [escape(package), version].compact.join('=')
12
+ "apk add -U #{pkg}"
13
+ end
14
+
15
+ def get_version(package, _opts = nil)
16
+ "apk version #{package} | tail -n1 | awk '{ print $1; }' | cut -d- -f2-"
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,20 @@
1
+ class Specinfra::Command::Alpine::Base::Process < Specinfra::Command::Base
2
+ class << self
3
+ def get(process, opts)
4
+ col = opts[:format].chomp('=')
5
+ if col == 'args'
6
+ "ps -o #{col} | grep #{escape(process)} | head -1"
7
+ else
8
+ "ps -o #{col},args | grep -E '\\s+#{process}' | awk '{ print $1 }' | head -1"
9
+ end
10
+ end
11
+
12
+ def check_is_running(process)
13
+ "ps -ocomm | grep -w -- #{escape(process)} | grep -qv grep"
14
+ end
15
+
16
+ def check_count(process, count)
17
+ "test $(ps -ocomm | grep -w -- #{escape(process)} | grep -v grep | wc -l) -eq #{escape(count)}"
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,2 @@
1
+ class Specinfra::Command::Alpine::Base < Specinfra::Command::Linux::Base
2
+ end
@@ -0,0 +1 @@
1
+ class Specinfra::Command::Alpine; end
@@ -98,6 +98,12 @@ require 'specinfra/command/aix/base/port'
98
98
  require 'specinfra/command/aix/base/service'
99
99
  require 'specinfra/command/aix/base/user'
100
100
 
101
+ # Alpine (inherit Linux)
102
+ require 'specinfra/command/alpine'
103
+ require 'specinfra/command/alpine/base'
104
+ require 'specinfra/command/alpine/base/package'
105
+ require 'specinfra/command/alpine/base/process'
106
+
101
107
  # Arch (inherit Linux)
102
108
  require 'specinfra/command/arch'
103
109
  require 'specinfra/command/arch/base'
@@ -13,6 +13,7 @@ module Specinfra
13
13
  :sudo_path,
14
14
  :disable_sudo,
15
15
  :sudo_options,
16
+ :docker_container_create_options,
16
17
  :docker_image,
17
18
  :docker_url,
18
19
  :lxc,
@@ -0,0 +1,8 @@
1
+ class Specinfra::Helper::DetectOs::Alpine < Specinfra::Helper::DetectOs
2
+ def self.detect
3
+ if run_command('ls /etc/alpine-release').success?
4
+ release = run_command('cat /etc/alpine-release').stdout
5
+ { :family => 'alpine', :release => release }
6
+ end
7
+ end
8
+ end
@@ -7,6 +7,7 @@ module Specinfra::Helper
7
7
  end
8
8
 
9
9
  require 'specinfra/helper/detect_os/aix'
10
+ require 'specinfra/helper/detect_os/alpine'
10
11
  require 'specinfra/helper/detect_os/arch'
11
12
  require 'specinfra/helper/detect_os/darwin'
12
13
  require 'specinfra/helper/detect_os/debian'
@@ -1,3 +1,3 @@
1
1
  module Specinfra
2
- VERSION = "2.17.1"
2
+ VERSION = "2.18.0"
3
3
  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.17.1
4
+ version: 2.18.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: 2015-03-02 00:00:00.000000000 Z
11
+ date: 2015-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ssh
@@ -145,6 +145,10 @@ files:
145
145
  - lib/specinfra/command/aix/base/port.rb
146
146
  - lib/specinfra/command/aix/base/service.rb
147
147
  - lib/specinfra/command/aix/base/user.rb
148
+ - lib/specinfra/command/alpine.rb
149
+ - lib/specinfra/command/alpine/base.rb
150
+ - lib/specinfra/command/alpine/base/package.rb
151
+ - lib/specinfra/command/alpine/base/process.rb
148
152
  - lib/specinfra/command/arch.rb
149
153
  - lib/specinfra/command/arch/base.rb
150
154
  - lib/specinfra/command/arch/base/file.rb
@@ -325,6 +329,7 @@ files:
325
329
  - lib/specinfra/helper/configuration.rb
326
330
  - lib/specinfra/helper/detect_os.rb
327
331
  - lib/specinfra/helper/detect_os/aix.rb
332
+ - lib/specinfra/helper/detect_os/alpine.rb
328
333
  - lib/specinfra/helper/detect_os/arch.rb
329
334
  - lib/specinfra/helper/detect_os/darwin.rb
330
335
  - lib/specinfra/helper/detect_os/debian.rb