kitchen-docker 1.1.0.beta → 1.2.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: 407a5d776917562de10e0e79bd86bffa9e48d9b3
4
- data.tar.gz: 3569d2059afb5caa1db2082772b2c2825f98c063
3
+ metadata.gz: 86592dc15baa47fd6da302f7c30d88f358f02e46
4
+ data.tar.gz: c595e77b2dbc2c200a1e4dcc3316e648463ee790
5
5
  SHA512:
6
- metadata.gz: a24c16a5b18228159b77a09f93c426b2eed684fff51f3c3c65bcb343ed5112f601929d767702ebec783ba113779f0a214bc9500613ad1b9aa529c9e50898d244
7
- data.tar.gz: 5ac2fc97e00d7003d7d0f42303711384c6d72412146a8fdaf0675a3024ba96a804ed1e1e23125f12a7ce973302c2d73fa9607f12166bb4441ddef0e4b055b2e2
6
+ metadata.gz: 26921d25432cab0ca8281e2e0880166fcadb2ddc53693974101ae3c7cab6815600db9edde85c9c84e0f752e13582a4d90b32f02d8c46645be2aee0f484a4965b
7
+ data.tar.gz: 75bcdad585f54c9ffccffc8cdf8f69ada4b240e1741eb1938f23c90a8e789218f677cfff362510da7a931ca38ff64e9a511c5c8d4c198415cc3676fa934f4adb
data/.kitchen.yml CHANGED
@@ -1,14 +1,30 @@
1
1
  ---
2
2
  driver:
3
3
  name: docker
4
+ provision_command: curl -L http://www.opscode.com/chef/install.sh | bash
4
5
 
5
6
  provisioner:
6
7
  name: dummy
7
8
 
8
9
  platforms:
9
10
  - name: ubuntu-12.04
11
+ - name: ubuntu-13.10
10
12
  - name: centos-6.4
13
+ - name: debian
14
+ - name: arch
15
+ driver:
16
+ image: base/arch
11
17
  - name: unknown
18
+ driver:
19
+ image: ubuntu:12.04
20
+ platform: ubuntu
21
+ - name: dockerfile
22
+ driver:
23
+ username: dockerfile
24
+ password: dockerfile
25
+ dockerfile: test/Dockerfile
26
+ run_command: /sbin/init
12
27
 
13
28
  suites:
14
29
  - name: default
30
+ - name: concurrency
data/README.md CHANGED
@@ -32,7 +32,9 @@ platforms:
32
32
  ## Default Configuration
33
33
 
34
34
  This driver can determine an image and platform type for a select number of
35
- platforms. Currently, the following platform names are supported:
35
+ platforms.
36
+
37
+ Examples:
36
38
 
37
39
  ```
38
40
  ---
@@ -58,6 +60,22 @@ platforms:
58
60
 
59
61
  ## Configuration
60
62
 
63
+ ### binary
64
+
65
+ The Docker binary to use.
66
+
67
+ The default value is `docker`.
68
+
69
+ Examples:
70
+
71
+ ```
72
+ binary: docker.io
73
+ ```
74
+
75
+ ```
76
+ binary: /opt/docker
77
+ ```
78
+
61
79
  ### socket
62
80
 
63
81
  The Docker daemon socket to use. By default, Docker will listen on
@@ -81,10 +99,8 @@ Examples:
81
99
  The Docker image to use as the base for the suite containers. You can find
82
100
  images using the [Docker Index][docker_index].
83
101
 
84
- The default will be determined by the Platform name, if a default exists
85
- (see the Default Configuration section for more details). If a default
86
- cannot be computed, then the default value is `base`, an official Ubuntu
87
- [image][docker_default_image].
102
+ The default will be computed, using the platform name (see the Default
103
+ Configuration section for more details).
88
104
 
89
105
  ### platform
90
106
 
@@ -94,9 +110,8 @@ suite container for Test Kitchen. Kitchen Docker currently supports:
94
110
  * `debian` or `ubuntu`
95
111
  * `rhel` or `centos`
96
112
 
97
- The default will be determined by the Platform name, if a default exists
98
- (see the Default Configuration section for more details). If a default
99
- cannot be computed, then the default value is `ubuntu`.
113
+ The default will be computed, using the platform name (see the Default
114
+ Configuration section for more details).
100
115
 
101
116
  ### require\_chef\_omnibus
102
117
 
@@ -252,6 +267,16 @@ Examples:
252
267
  privileged: true
253
268
  ```
254
269
 
270
+ ## dockerfile
271
+
272
+ Use a custom Dockerfile, instead of having Kitchen-Docker build one for you.
273
+
274
+ Examples:
275
+
276
+ ```
277
+ dockerfile: test/Dockerfile
278
+ ```
279
+
255
280
  ## Development
256
281
 
257
282
  * Source hosted at [GitHub][repo]
@@ -16,6 +16,7 @@
16
16
 
17
17
  require 'kitchen'
18
18
  require 'json'
19
+ require File.join(File.dirname(__FILE__), 'docker', 'erb')
19
20
 
20
21
  module Kitchen
21
22
 
@@ -26,6 +27,7 @@ module Kitchen
26
27
  # @author Sean Porter <portertech@gmail.com>
27
28
  class Docker < Kitchen::Driver::SSHBase
28
29
 
30
+ default_config :binary, 'docker'
29
31
  default_config :socket, 'unix:///var/run/docker.sock'
30
32
  default_config :privileged, false
31
33
  default_config :use_cache, true
@@ -49,7 +51,7 @@ module Kitchen
49
51
  default_config :disable_upstart, true
50
52
 
51
53
  def verify_dependencies
52
- run_command('docker > /dev/null', :quiet => true)
54
+ run_command("#{config[:binary]} > /dev/null", :quiet => true)
53
55
  rescue
54
56
  raise UserError,
55
57
  'You must first install the Docker CLI tool http://www.docker.io/gettingstarted/'
@@ -61,7 +63,7 @@ module Kitchen
61
63
  end
62
64
 
63
65
  def default_platform
64
- instance.platform.name.split('-').first || 'ubuntu'
66
+ instance.platform.name.split('-').first
65
67
  end
66
68
 
67
69
  def create(state)
@@ -73,7 +75,7 @@ module Kitchen
73
75
  end
74
76
 
75
77
  def destroy(state)
76
- rm_container(state) if state[:container_id]
78
+ rm_container(state) if container_exists?(state)
77
79
  if config[:remove_images] && state[:image_id]
78
80
  rm_image(state)
79
81
  end
@@ -90,12 +92,12 @@ module Kitchen
90
92
  end
91
93
 
92
94
  def docker_command(cmd, options={})
93
- docker = "docker"
95
+ docker = config[:binary].dup
94
96
  docker << " -H #{config[:socket]}" if config[:socket]
95
- run_command("#{docker} #{cmd}", options)
97
+ run_command("#{docker} #{cmd}", options.merge(:quiet => !logger.debug?))
96
98
  end
97
99
 
98
- def dockerfile
100
+ def build_dockerfile
99
101
  from = "FROM #{config[:image]}"
100
102
  platform = case config[:platform]
101
103
  when 'debian', 'ubuntu'
@@ -113,8 +115,15 @@ module Kitchen
113
115
  <<-eos
114
116
  RUN yum clean all
115
117
  RUN yum install -y sudo openssh-server openssh-clients which curl
116
- RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
117
- RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
118
+ RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''
119
+ RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N ''
120
+ eos
121
+ when 'arch'
122
+ <<-eos
123
+ RUN pacman -Syu --noconfirm
124
+ RUN pacman -S --noconfirm openssh sudo curl
125
+ RUN ssh-keygen -A -t rsa -f /etc/ssh/ssh_host_rsa_key
126
+ RUN ssh-keygen -A -t dsa -f /etc/ssh/ssh_host_dsa_key
118
127
  eos
119
128
  else
120
129
  raise ActionFailed,
@@ -135,6 +144,16 @@ module Kitchen
135
144
  [from, platform, base, custom].join("\n")
136
145
  end
137
146
 
147
+ def dockerfile
148
+ if config[:dockerfile]
149
+ template = IO.read(File.expand_path(config[:dockerfile]))
150
+ context = DockerERBContext.new(config.to_hash)
151
+ ERB.new(template).result(context.get_binding)
152
+ else
153
+ build_dockerfile
154
+ end
155
+ end
156
+
138
157
  def parse_image_id(output)
139
158
  output.each_line do |line|
140
159
  if line =~ /image id|build successful|successfully built/i
@@ -180,6 +199,15 @@ module Kitchen
180
199
  parse_container_id(output)
181
200
  end
182
201
 
202
+ def inspect_container(state)
203
+ container_id = state[:container_id]
204
+ docker_command("inspect #{container_id}")
205
+ end
206
+
207
+ def container_exists?(state)
208
+ !!inspect_container(state) rescue false
209
+ end
210
+
183
211
  def parse_container_ssh_port(output)
184
212
  begin
185
213
  info = Array(::JSON.parse(output)).first
@@ -193,8 +221,7 @@ module Kitchen
193
221
  end
194
222
 
195
223
  def container_ssh_port(state)
196
- container_id = state[:container_id]
197
- output = docker_command("inspect #{container_id}")
224
+ output = inspect_container(state)
198
225
  parse_container_ssh_port(output)
199
226
  end
200
227
 
@@ -0,0 +1,35 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2013, Sean Porter
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require 'erb'
18
+
19
+ module Kitchen
20
+
21
+ module Driver
22
+
23
+ class DockerERBContext
24
+ def initialize(config={})
25
+ config.each do |key, value|
26
+ instance_variable_set('@' + key.to_s, value)
27
+ end
28
+ end
29
+
30
+ def get_binding
31
+ binding
32
+ end
33
+ end
34
+ end
35
+ end
@@ -19,6 +19,6 @@ module Kitchen
19
19
  module Driver
20
20
 
21
21
  # Version string for Docker Kitchen driver
22
- DOCKER_VERSION = "1.1.0.beta"
22
+ DOCKER_VERSION = "1.2.0"
23
23
  end
24
24
  end
data/test/Dockerfile ADDED
@@ -0,0 +1,10 @@
1
+ FROM centos:6.4
2
+ RUN yum clean all
3
+ RUN yum install -y sudo openssh-server openssh-clients which curl htop
4
+ RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
5
+ RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
6
+ RUN mkdir -p /var/run/sshd
7
+ RUN useradd -d /home/<%= @username %> -m -s /bin/bash <%= @username %>
8
+ RUN echo <%= "#{@username}:#{@password}" %> | chpasswd
9
+ RUN echo '<%= @username %> ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
10
+ RUN curl -L http://www.opscode.com/chef/install.sh | bash
@@ -0,0 +1,8 @@
1
+ require 'serverspec'
2
+
3
+ include Serverspec::Helper::Exec
4
+ include Serverspec::Helper::DetectOS
5
+
6
+ describe file('/etc/passwd') do
7
+ it { should be_file }
8
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen-docker
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0.beta
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Porter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-28 00:00:00.000000000 Z
11
+ date: 2014-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-kitchen
@@ -113,7 +113,10 @@ files:
113
113
  - Rakefile
114
114
  - kitchen-docker.gemspec
115
115
  - lib/kitchen/driver/docker.rb
116
+ - lib/kitchen/driver/docker/erb.rb
116
117
  - lib/kitchen/driver/docker_version.rb
118
+ - test/Dockerfile
119
+ - test/integration/default/serverspec/default_spec.rb
117
120
  homepage: https://github.com/portertech/kitchen-docker
118
121
  licenses:
119
122
  - Apache 2.0
@@ -129,13 +132,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
129
132
  version: '0'
130
133
  required_rubygems_version: !ruby/object:Gem::Requirement
131
134
  requirements:
132
- - - ">"
135
+ - - ">="
133
136
  - !ruby/object:Gem::Version
134
- version: 1.3.1
137
+ version: '0'
135
138
  requirements: []
136
139
  rubyforge_project:
137
- rubygems_version: 2.1.11
140
+ rubygems_version: 2.2.0
138
141
  signing_key:
139
142
  specification_version: 4
140
143
  summary: A Test Kitchen Driver for Docker
141
- test_files: []
144
+ test_files:
145
+ - test/Dockerfile
146
+ - test/integration/default/serverspec/default_spec.rb