kitchen-docker_cli 0.2.0.beta → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b017b8199ef3de53c08c5272118323eec27674a8
4
- data.tar.gz: c95e1536805f6f66fc46508aa85a20a69e977d11
3
+ metadata.gz: f7f3a5f06608f5e262b3327dae9c4714a942701b
4
+ data.tar.gz: ab67af775455f5966a48f6a613e7075a9ca1dfb2
5
5
  SHA512:
6
- metadata.gz: 099f68c752434b508d8a6023082f6d8043a5e571f605d0fe0eb6db9a0d8a85c9ff45d1af40d31b98ddcfb8c501574de397361587e28a82b40db7a7a980b4a61b
7
- data.tar.gz: bda1883c6a1eb0e7e40424692ebff729b79842511c7ce7fa797904fd1dec36e647d5fdd14b232540932a1ce8b0a665af54b5b07fffb317e64eab1042e353cdfb
6
+ metadata.gz: ca4f63b2b912704f62bdf0cdcc7f4e0ef84f8d42d8989102d7d0c7b244e3d9da490fadda5f8d32f7190377a52ccfd8340b2d9a0888b632cfe6ef042d1ac5dab1
7
+ data.tar.gz: 2dab5ee66aeda1bdeef838ddc63964a8332bcecec261e2f80a89a02150d5925a348b4d586f6a6f1714c1519407ea9a4c54489f3f5b3f095da376b39040fef07c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.3.0
2
+
3
+ * Use docker exec command to transfer the test-kitchen's sandbox [#1][]
4
+
1
5
  ## 0.2.0.beta
2
6
 
3
7
  * Add ```privileged``` option
data/README.md CHANGED
@@ -1,5 +1,4 @@
1
- # <a name="title"></a> Kitchen::DockerCli [![Gem Version](https://badge.fury.io/rb/kitchen-docker_cli.svg)](http://badge.fury.io/rb/kitchen-docker_cli) [![Build Status](https://travis-ci.org/marcy-terui/kitchen-docker_cli.svg?branch=master)](https://travis-ci.org/marcy-terui/kitchen-docker_cli) [![Coverage Status](https://coveralls.io/repos/marcy-terui/kitchen-docker_cli/badge.png)](https://coveralls.io/r/marcy-terui/kitchen-docker_cli) [![Code Climate](https://codeclimate.com/github/marcy-terui/kitchen-docker_cli/badges/gpa.svg)](https://codeclimate.com/github/marcy-terui/kitchen-docker_cli)
2
-
1
+ # <a name="title"></a> Kitchen::DockerCli [![Gem Version](https://badge.fury.io/rb/kitchen-docker_cli.svg)](http://badge.fury.io/rb/kitchen-docker_cli) [![Build Status](https://travis-ci.org/marcy-terui/kitchen-docker_cli.svg?branch=master)](https://travis-ci.org/marcy-terui/kitchen-docker_cli) [![Coverage Status](https://coveralls.io/repos/marcy-terui/kitchen-docker_cli/badge.png)](https://coveralls.io/r/marcy-terui/kitchen-docker_cli)
3
2
  A Test Kitchen Driver for Docker command line interface.
4
3
 
5
4
  This plugin is created with only Docker CLI functions.
@@ -10,6 +9,8 @@ Therefore, we can test with an environment that has no extra software such as ``
10
9
  - Docker (>= 1.3)
11
10
  This driver uses ```docker exec``` command.
12
11
 
12
+ - tar (GNU Tar)
13
+
13
14
  ## <a name="installation"></a> Installation and Setup
14
15
 
15
16
  ```sh
@@ -62,7 +62,8 @@ module Kitchen
62
62
 
63
63
  execute(docker_exec_command(state[:container_id], provisioner.install_command, :tty => true)) if provisioner.install_command
64
64
  execute(docker_exec_command(state[:container_id], provisioner.init_command, :tty => true)) if provisioner.init_command
65
- execute(docker_transfer_command(provisioner, state[:container_id]))
65
+ execute(docker_pre_transfer_command(provisioner, state[:container_id]))
66
+ run_command(docker_transfer_command(provisioner, state[:container_id]))
66
67
  execute(docker_exec_command(state[:container_id], provisioner.prepare_command, :tty => true)) if provisioner.prepare_command
67
68
  execute(docker_exec_command(state[:container_id], provisioner.run_command, :tty => true)) if provisioner.run_command
68
69
 
@@ -113,6 +114,10 @@ module Kitchen
113
114
  parse_container_id(output)
114
115
  end
115
116
 
117
+ def docker_command(cmd)
118
+ "docker #{cmd}"
119
+ end
120
+
116
121
  def docker_build_command
117
122
  cmd = 'build'
118
123
  cmd << ' --no-cache' if config[:no_cache]
@@ -120,7 +125,7 @@ module Kitchen
120
125
  end
121
126
 
122
127
  def docker_run_command(image)
123
- cmd = "run -d -v #{Dir::tmpdir}:/tmp:rw"
128
+ cmd = "run -d"
124
129
  cmd << " --name #{config[:container_name]}" if config[:container_name]
125
130
  cmd << ' -P' if config[:publish_all]
126
131
  cmd << ' --privileged' if config[:privileged]
@@ -138,14 +143,18 @@ module Kitchen
138
143
  exec_cmd << " #{container_id} #{cmd}"
139
144
  end
140
145
 
141
- def docker_transfer_command(provisioner, container_id)
142
- cmd = "rm -rf #{provisioner[:root_path]}"
143
- cmd << " && mkdir #{provisioner[:root_path]}"
144
- cmd << " && cp -rp #{provisioner.sandbox_path}/*"
145
- cmd << " #{provisioner[:root_path]}/"
146
+ def docker_pre_transfer_command(provisioner, container_id)
147
+ cmd = "mkdir -p #{provisioner[:root_path]}"
148
+ cmd << " && rm -rf #{provisioner[:root_path]}/*"
146
149
  docker_exec_command(container_id, cmd)
147
150
  end
148
151
 
152
+ def docker_transfer_command(provisioner, container_id)
153
+ remote_cmd = "tar x -C #{provisioner[:root_path]}"
154
+ local_cmd = "cd #{provisioner.sandbox_path} && tar cf - ./"
155
+ "#{local_cmd} | #{docker_command(docker_exec_command(container_id, remote_cmd, :interactive => true))}"
156
+ end
157
+
149
158
  def parse_image_id(output)
150
159
  unless output.chomp.match(/Successfully built ([0-9a-z]{12})$/)
151
160
  raise ActionFailed, 'Could not parse IMAGE ID.'
@@ -165,10 +174,10 @@ module Kitchen
165
174
  case config[:platform]
166
175
  when 'debian', 'ubuntu'
167
176
  file << 'RUN apt-get update'
168
- file << 'RUN apt-get -y install sudo curl'
177
+ file << 'RUN apt-get -y install sudo curl tar'
169
178
  when 'rhel', 'centos'
170
179
  file << 'RUN yum clean all'
171
- file << 'RUN yum -y install sudo curl'
180
+ file << 'RUN yum -y install sudo curl tar'
172
181
  else
173
182
  # TODO: Support other distribution
174
183
  end
@@ -177,8 +186,7 @@ module Kitchen
177
186
  end
178
187
 
179
188
  def execute(cmd, opts = {})
180
- cmd = "docker #{cmd}"
181
- run_command(cmd, opts)
189
+ run_command(docker_command(cmd), opts)
182
190
  end
183
191
 
184
192
 
@@ -21,6 +21,6 @@ module Kitchen
21
21
  module Driver
22
22
 
23
23
  # Version string for DockerCli Kitchen driver
24
- DOCKER_CLI_VERSION = '0.2.0.beta'
24
+ DOCKER_CLI_VERSION = '0.3.0'
25
25
  end
26
26
  end
@@ -83,7 +83,9 @@ describe Kitchen::Driver::DockerCli, "converge" do
83
83
  instance.stub(:provisioner).and_return(provisioner)
84
84
  @docker_cli.stub(:instance).and_return(instance)
85
85
  @docker_cli.stub(:docker_transfer_command)
86
+ @docker_cli.stub(:docker_pre_transfer_command)
86
87
  @docker_cli.stub(:execute)
88
+ @docker_cli.stub(:run_command)
87
89
  end
88
90
 
89
91
  example do
@@ -222,7 +224,7 @@ describe Kitchen::Driver::DockerCli, "docker_run_command" do
222
224
  let(:config) { {:command => '/bin/bash'} }
223
225
 
224
226
  example do
225
- cmd = "run -d -v #{Dir::tmpdir}:/tmp:rw test /bin/bash"
227
+ cmd = "run -d test /bin/bash"
226
228
  expect(@docker_cli.docker_run_command('test')).to eq cmd
227
229
  end
228
230
  end
@@ -241,7 +243,7 @@ describe Kitchen::Driver::DockerCli, "docker_run_command" do
241
243
  end
242
244
 
243
245
  example do
244
- cmd = "run -d -v #{Dir::tmpdir}:/tmp:rw --name web -P --privileged -p 80:8080 -p 22:2222 -v /dev:/dev --link mysql:db test /bin/bash"
246
+ cmd = "run -d --name web -P --privileged -p 80:8080 -p 22:2222 -v /dev:/dev --link mysql:db test /bin/bash"
245
247
  expect(@docker_cli.docker_run_command('test')).to eq cmd
246
248
  end
247
249
  end
@@ -308,7 +310,7 @@ describe Kitchen::Driver::DockerCli, "docker_file" do
308
310
  example do
309
311
  ret = "FROM centos/centos6\n"
310
312
  ret << "RUN yum clean all\n"
311
- ret << "RUN yum -y install sudo curl"
313
+ ret << "RUN yum -y install sudo curl tar"
312
314
  expect(@docker_cli.send(:docker_file)).to eq ret
313
315
  end
314
316
  end
@@ -325,13 +327,24 @@ describe Kitchen::Driver::DockerCli, "docker_file" do
325
327
  ret = "FROM ubuntu/12.04\n"
326
328
  ret = "FROM ubuntu/12.04\n"
327
329
  ret << "RUN apt-get update\n"
328
- ret << "RUN apt-get -y install sudo curl\n"
330
+ ret << "RUN apt-get -y install sudo curl tar\n"
329
331
  ret << "RUN test\nRUN test2"
330
332
  expect(@docker_cli.send(:docker_file)).to eq ret
331
333
  end
332
334
  end
333
335
  end
334
336
 
337
+ describe Kitchen::Driver::DockerCli, "docker_command" do
338
+
339
+ before do
340
+ @docker_cli = Kitchen::Driver::DockerCli.new()
341
+ end
342
+
343
+ example do
344
+ expect(@docker_cli.docker_command('exec')).to eq "docker exec"
345
+ end
346
+ end
347
+
335
348
  describe Kitchen::Driver::DockerCli, "docker_exec_command" do
336
349
 
337
350
  before do
@@ -349,6 +362,19 @@ describe Kitchen::Driver::DockerCli, "docker_exec_command" do
349
362
  end
350
363
  end
351
364
 
365
+ describe Kitchen::Driver::DockerCli, "docker_pre_transfer_command" do
366
+
367
+ before do
368
+ @docker_cli = Kitchen::Driver::DockerCli.new()
369
+ end
370
+
371
+ example do
372
+ provisoner = {:root_path => '/tmp/kitchen'}
373
+ cmd = "exec abc mkdir -p /tmp/kitchen && rm -rf /tmp/kitchen/*"
374
+ expect(@docker_cli.docker_pre_transfer_command(provisoner, 'abc')).to eq cmd
375
+ end
376
+ end
377
+
352
378
  describe Kitchen::Driver::DockerCli, "docker_transfer_command" do
353
379
 
354
380
  before do
@@ -358,7 +384,7 @@ describe Kitchen::Driver::DockerCli, "docker_transfer_command" do
358
384
  example do
359
385
  provisoner = {:root_path => '/tmp/kitchen'}
360
386
  provisoner.stub(:sandbox_path).and_return('/tmp/sandbox')
361
- cmd = "exec abc rm -rf /tmp/kitchen && mkdir /tmp/kitchen && cp -rp /tmp/sandbox/* /tmp/kitchen/"
387
+ cmd = "cd /tmp/sandbox && tar cf - ./ | docker exec -i abc tar x -C /tmp/kitchen"
362
388
  expect(@docker_cli.docker_transfer_command(provisoner, 'abc')).to eq cmd
363
389
  end
364
390
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen-docker_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0.beta
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masashi Terui
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-29 00:00:00.000000000 Z
11
+ date: 2015-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-kitchen
@@ -131,9 +131,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
131
131
  version: '0'
132
132
  required_rubygems_version: !ruby/object:Gem::Requirement
133
133
  requirements:
134
- - - ">"
134
+ - - ">="
135
135
  - !ruby/object:Gem::Version
136
- version: 1.3.1
136
+ version: '0'
137
137
  requirements: []
138
138
  rubyforge_project:
139
139
  rubygems_version: 2.2.2