kitchen-docker_cli 0.1.0.alpha2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 025e35972b93ea612102fec7acc7746e572d19ff
4
+ data.tar.gz: a2475b29f49869fd79c37522135bbe8387fded38
5
+ SHA512:
6
+ metadata.gz: 91f1632a6db589541e6fef1d14d1bcac2604ef795eae7f9cbe56ee57c7e6fd387f6d7cfddf91ff67a9ed63c8c7354f4e600c37d963cb0a3d718a99fe006f0c30
7
+ data.tar.gz: b2606f7aea5427eb599fdf625b8687d5ade1ee5d100fa51af51f7cf22db20c5ba04edd70b5bbc43951486675f9b89319fd58dae1c6783d38f8aae0847e3d7b0e
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ /vendor
19
+ .kitchen/
20
+ .kitchen.local.yml
data/.kitchen.yml ADDED
@@ -0,0 +1,12 @@
1
+ ---
2
+ driver:
3
+ name: docker_cli
4
+
5
+ platforms:
6
+ - name: ubuntu-12.04
7
+ - name: centos-6.4
8
+
9
+ suites:
10
+ - name: default
11
+ run_list:
12
+ attributes:
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.1
5
+ - 2.0.0
6
+ - 1.9.3
7
+ - ruby-head
8
+
9
+ matrix:
10
+ allow_failures:
11
+ - rvm: ruby-head
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## 0.1.0.alpha
2
+
3
+ * Initial release
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'test-kitchen', github: 'test-kitchen/test-kitchen', ref: '237efd17dbcafd0c1334134e3f26b050f2ef49d5'
data/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ Author:: Masashi Terui (<marcy9114@gmail.com>)
2
+
3
+ Copyright (C) 2014, Masashi Terui
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.
data/README.md ADDED
@@ -0,0 +1,189 @@
1
+ # <a name="title"></a> Kitchen::DockerCli [![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
+
3
+ A Test Kitchen Driver for Docker command line interface.
4
+
5
+ ## <a name="requirements"></a> Requirements
6
+
7
+ - Docker (>= 1.3)
8
+ This driver uses ```docker exec``` command.
9
+
10
+ ## <a name="installation"></a> Installation and Setup
11
+
12
+ ```sh
13
+ gem install kitchen-docker_cli
14
+ ```
15
+
16
+ or put ```Gemfile``` in your project directory.
17
+
18
+ ```ruby
19
+ source 'https://rubygems.org'
20
+
21
+ gem 'kitchen-docker_cli'
22
+ ```
23
+
24
+ and
25
+
26
+ ```sh
27
+ bundle install
28
+ ```
29
+
30
+ If you want to use the ```kithcen exec``` command, should you put Gemfile like this. (as of 25 Dec, 2014)
31
+
32
+ ```ruby
33
+ source 'https://rubygems.org'
34
+
35
+ gem 'test-kitchen', github: 'test-kitchen/test-kitchen', ref: '237efd17dbcafd0c1334134e3f26b050f2ef49d5'
36
+ gem 'kitchen-docker_cli'
37
+ ```
38
+
39
+ ## <a name="config"></a> Configuration
40
+
41
+ ### image
42
+
43
+ The Docker image's path.
44
+
45
+ The default value get from ```platform.name```.
46
+
47
+ Examples:
48
+
49
+ ```yml
50
+ image: marcy/amzn
51
+ ```
52
+
53
+ ### platform
54
+
55
+ The Docker image's platform.
56
+
57
+ The default value get from ```platform.name```.
58
+
59
+ Examples:
60
+
61
+ ```yml
62
+ platform: centos
63
+ ```
64
+
65
+ ### command
66
+
67
+ The command to be executed at ```docker run```.
68
+
69
+ The default value is ```sh -c 'while true; do sleep 1d; done;'```.
70
+
71
+ Examples:
72
+
73
+ ```yml
74
+ command: /bin/bash
75
+ ```
76
+
77
+ ### run_command
78
+
79
+ Adds ```RUN``` command(s) to ```Dockerfile```.
80
+
81
+ The default value is ```nil```.
82
+
83
+ Examples:
84
+
85
+ ```yml
86
+ run_command:
87
+ - yum -y install httpd
88
+ - service httpd start
89
+ ```
90
+
91
+ ### no_cache
92
+
93
+ Not use the cached image on ```docker build```.
94
+
95
+ The default value is ```true```.
96
+
97
+ Examples:
98
+
99
+ ```yml
100
+ no_cache: true
101
+ ```
102
+
103
+ ### container_name
104
+
105
+ Set the name of container to link other container(s).
106
+
107
+ Examples:
108
+
109
+ ```yml
110
+ container_name: web
111
+ ```
112
+
113
+ ### link
114
+
115
+ Set ```container_name```(and alias) of other container(s) that connect from the suite container.
116
+
117
+ Examples:
118
+
119
+ ```yml
120
+ link: mysql:db
121
+ ```
122
+
123
+ Examples:
124
+
125
+ ```yml
126
+ links:
127
+ - mysql:db
128
+ - redis:kvs
129
+ ```
130
+
131
+ ### publish_all
132
+
133
+ Publish all exposed ports to the host interfaces.
134
+ This option used to communicate between some containers.
135
+
136
+ The default value is `false`.
137
+
138
+ Examples:
139
+
140
+ ```yml
141
+ publish_all: true
142
+ ```
143
+
144
+ ### volume
145
+
146
+ Adds data volume(s) to the container.
147
+
148
+ Examples:
149
+
150
+ ```yml
151
+ volume: /data
152
+ ```
153
+
154
+ ```yml
155
+ volume:
156
+ - /tmp:/tmp
157
+ - <%= Dir::pwd %>:/var:rw
158
+ ```
159
+
160
+ ## <a name="development"></a> Development
161
+
162
+ * Source hosted at [GitHub][repo]
163
+ * Report issues/questions/feature requests on [GitHub Issues][issues]
164
+
165
+ Pull requests are very welcome! Make sure your patches are well tested.
166
+ Ideally create a topic branch for every separate change you make. For
167
+ example:
168
+
169
+ 1. Fork the repo
170
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
171
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
172
+ 4. Push to the branch (`git push origin my-new-feature`)
173
+ 5. Create new Pull Request
174
+
175
+ ## <a name="authors"></a> Authors
176
+
177
+ Created and maintained by [Masashi Terui][author] (<marcy9114@gmail.com>)
178
+
179
+ ## <a name="license"></a> License
180
+
181
+ Apache 2.0 (see [LICENSE][license])
182
+
183
+
184
+ [author]: https://github.com/marcy-terui
185
+ [issues]: https://github.com/marcy-terui/kitchen-docker_cli/issues
186
+ [license]: https://github.com/marcy-terui/kitchen-docker_cli/blob/master/LICENSE
187
+ [repo]: https://github.com/marcy-terui/kitchen-docker_cli
188
+ [driver_usage]: http://docs.kitchen-ci.org/drivers/usage
189
+ [chef_omnibus_dl]: http://www.getchef.com/chef/install/
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec) do |spec|
6
+ spec.pattern = 'spec/**/*_spec.rb'
7
+ end
8
+
9
+ task :default => [:spec]
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kitchen/driver/docker_cli_version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'kitchen-docker_cli'
8
+ spec.version = Kitchen::Driver::DOCKER_CLI_VERSION
9
+ spec.authors = ['Masashi Terui']
10
+ spec.email = ['marcy9114@gmail.com']
11
+ spec.description = %q{A Test Kitchen Driver for Docker native CLI}
12
+ spec.summary = spec.description
13
+ spec.homepage = 'https://github.com/marcy-terui/kitchen-docker_cli'
14
+ spec.license = 'Apache 2.0'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = []
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'test-kitchen'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.3'
24
+ spec.add_development_dependency 'rake'
25
+
26
+ spec.add_development_dependency "coveralls"
27
+ spec.add_development_dependency "rspec"
28
+ spec.add_development_dependency "rspec-its"
29
+ end
@@ -0,0 +1,185 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ # Author:: Masashi Terui (<marcy9114@gmail.com>)
4
+ #
5
+ # Copyright (C) 2014, Masashi Terui
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ require 'kitchen'
20
+
21
+ module Kitchen
22
+
23
+ module Driver
24
+
25
+ # Docker CLI driver for Kitchen.
26
+ #
27
+ # @author Masashi Terui <marcy9114@gmail.com>
28
+ class DockerCli < Kitchen::Driver::Base
29
+
30
+ default_config :no_cache, true
31
+ default_config :command, 'sh -c \'while true; do sleep 1d; done;\''
32
+
33
+ default_config :image do |driver|
34
+ driver.default_image
35
+ end
36
+
37
+ default_config :platform do |driver|
38
+ driver.default_platform
39
+ end
40
+
41
+ def default_image
42
+ platform, version = instance.platform.name.split('-')
43
+ if platform == 'centos' && version
44
+ version = "centos#{version.split('.').first}"
45
+ end
46
+ version ? [platform, version].join(':') : platform
47
+ end
48
+
49
+ def default_platform
50
+ instance.platform.name.split('-').first
51
+ end
52
+
53
+ def create(state)
54
+ state[:image] = build unless state[:image]
55
+ state[:container_id] = run(state[:image]) unless state[:container_id]
56
+ end
57
+
58
+ def converge(state)
59
+ provisioner = instance.provisioner
60
+ provisioner.create_sandbox
61
+
62
+ execute(docker_exec_command(state[:container_id], provisioner.install_command, :tty => true)) if provisioner.install_command
63
+ execute(docker_exec_command(state[:container_id], provisioner.init_command, :tty => true)) if provisioner.init_command
64
+ execute(docker_transfer_command(provisioner, state[:container_id]))
65
+ execute(docker_exec_command(state[:container_id], provisioner.prepare_command, :tty => true)) if provisioner.prepare_command
66
+ execute(docker_exec_command(state[:container_id], provisioner.run_command, :tty => true)) if provisioner.run_command
67
+
68
+ ensure
69
+ provisioner && provisioner.cleanup_sandbox
70
+ end
71
+
72
+ def setup(state)
73
+ if busser.setup_cmd
74
+ execute(docker_exec_command(state[:container_id], busser.setup_cmd, :tty => true))
75
+ end
76
+ end
77
+
78
+ def verify(state)
79
+ if busser.sync_cmd
80
+ execute(docker_exec_command(state[:container_id], busser.sync_cmd, :tty => true))
81
+ end
82
+ if busser.run_cmd
83
+ execute(docker_exec_command(state[:container_id], busser.run_cmd, :tty => true))
84
+ end
85
+ end
86
+
87
+ def destroy(state)
88
+ execute("rm -f #{state[:container_id]}") rescue false
89
+ end
90
+
91
+ def remote_command(state, cmd)
92
+ execute(docker_exec_command(state[:container_id], cmd))
93
+ end
94
+
95
+ def login_command(state)
96
+ args = []
97
+ args << 'exec'
98
+ args << '-t'
99
+ args << '-i'
100
+ args << state[:container_id]
101
+ args << '/bin/bash'
102
+ LoginCommand.new(['docker', *args])
103
+ end
104
+
105
+ def build
106
+ output = execute(docker_build_command, :input => docker_file)
107
+ parse_image_id(output)
108
+ end
109
+
110
+ def run(image)
111
+ output = execute(docker_run_command(image))
112
+ parse_container_id(output)
113
+ end
114
+
115
+ def docker_build_command
116
+ cmd = 'build'
117
+ cmd << ' --no-cache' if config[:no_cache]
118
+ cmd << ' -'
119
+ end
120
+
121
+ def docker_run_command(image)
122
+ cmd = "run -d -v #{Dir::tmpdir}:/tmp:rw"
123
+ cmd << " --name #{config[:container_name]}" if config[:container_name]
124
+ cmd << ' -P' if config[:publish_all]
125
+ Array(config[:publish]).each { |pub| cmd << " -p #{pub}" }
126
+ Array(config[:volume]).each { |vol| cmd << " -v #{vol}" }
127
+ Array(config[:link]).each { |link| cmd << " --link #{link}" }
128
+ cmd << " #{image} #{config[:command]}"
129
+ end
130
+
131
+ def docker_exec_command(container_id, cmd, opt = {})
132
+ exec_cmd = "exec"
133
+ exec_cmd << " -t" if opt[:tty]
134
+ exec_cmd << " -i" if opt[:interactive]
135
+ # exec_cmd << " <<-EOH\n#{cmd}\nEOH"
136
+ exec_cmd << " #{container_id} #{cmd}"
137
+ end
138
+
139
+ def docker_transfer_command(provisioner, container_id)
140
+ cmd = "rm -rf #{provisioner[:root_path]}"
141
+ cmd << " && mkdir #{provisioner[:root_path]}"
142
+ cmd << " && cp -rp #{provisioner.sandbox_path}/*"
143
+ cmd << " #{provisioner[:root_path]}/"
144
+ docker_exec_command(container_id, cmd)
145
+ end
146
+
147
+ def parse_image_id(output)
148
+ unless output.chomp.match(/Successfully built ([0-9a-z]{12})$/)
149
+ raise ActionFailed, 'Could not parse IMAGE ID.'
150
+ end
151
+ $1
152
+ end
153
+
154
+ def parse_container_id(output)
155
+ unless output.chomp.match(/([0-9a-z]{64})$/)
156
+ raise ActionFailed, 'Could not parse CONTAINER ID.'
157
+ end
158
+ $1
159
+ end
160
+
161
+ def docker_file
162
+ file = ["FROM #{config[:image]}"]
163
+ case config[:platform]
164
+ when 'debian', 'ubuntu'
165
+ file << 'RUN apt-get update'
166
+ file << 'RUN apt-get -y install sudo curl'
167
+ when 'rhel', 'centos'
168
+ file << 'RUN yum clean all'
169
+ file << 'RUN yum -y install sudo curl'
170
+ else
171
+ # TODO: Support other distribution
172
+ end
173
+ Array(config[:run_command]).each { |cmd| file << "RUN #{cmd}" }
174
+ file.join("\n")
175
+ end
176
+
177
+ def execute(cmd, opts = {})
178
+ cmd = "docker #{cmd}"
179
+ run_command(cmd, opts)
180
+ end
181
+
182
+
183
+ end
184
+ end
185
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ # Author:: Masashi Terui (<marcy9114@gmail.com>)
4
+ #
5
+ # Copyright (C) 2014, Masashi Terui
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ module Kitchen
20
+
21
+ module Driver
22
+
23
+ # Version string for DockerCli Kitchen driver
24
+ DOCKER_CLI_VERSION = '0.1.0.alpha2'
25
+ end
26
+ end
@@ -0,0 +1,363 @@
1
+ require 'spec_helper'
2
+ require 'kitchen/driver/docker_cli'
3
+
4
+ describe Kitchen::Driver::DockerCli, "default_image" do
5
+
6
+ before do
7
+ @docker_cli = Kitchen::Driver::DockerCli.new
8
+ end
9
+
10
+ example do
11
+ platform = double('platform')
12
+ instance = double('instance')
13
+ platform.stub(:name).and_return("centos-6.4")
14
+ instance.stub(:platform).and_return(platform)
15
+ @docker_cli.stub(:instance).and_return(instance)
16
+ expect(@docker_cli.default_image).to eq 'centos:centos6'
17
+ end
18
+
19
+ example do
20
+ platform = double('platform')
21
+ instance = double('instance')
22
+ platform.stub(:name).and_return("ubuntu-12.04")
23
+ instance.stub(:platform).and_return(platform)
24
+ @docker_cli.stub(:instance).and_return(instance)
25
+ expect(@docker_cli.default_image).to eq 'ubuntu:12.04'
26
+ end
27
+ end
28
+
29
+ describe Kitchen::Driver::DockerCli, "default_platform" do
30
+
31
+ before do
32
+ @docker_cli = Kitchen::Driver::DockerCli.new
33
+ end
34
+
35
+ example do
36
+ platform = double('platform')
37
+ instance = double('instance')
38
+ platform.stub(:name).and_return("centos-6.4")
39
+ instance.stub(:platform).and_return(platform)
40
+ @docker_cli.stub(:instance).and_return(instance)
41
+ expect(@docker_cli.default_platform).to eq 'centos'
42
+ end
43
+ end
44
+
45
+ describe Kitchen::Driver::DockerCli, "create" do
46
+
47
+ before do
48
+ @docker_cli = Kitchen::Driver::DockerCli.new(config)
49
+ @docker_cli.stub(:build).and_return("qwerty")
50
+ @docker_cli.stub(:run).and_return("asdfgf")
51
+ @docker_cli.create(state)
52
+ end
53
+
54
+ context 'first kitchen create' do
55
+ let(:config) { Hash.new }
56
+ let(:state) { Hash.new }
57
+
58
+ example { expect(state[:image]).to eq "qwerty" }
59
+ example { expect(state[:container_id]).to eq "asdfgf" }
60
+ end
61
+
62
+ context 'second kitchen create' do
63
+ let(:config) { Hash.new }
64
+ let(:state) { {:image => "abc", :container_id => "xyz"} }
65
+
66
+ example { expect(state[:image]).to eq "abc" }
67
+ example { expect(state[:container_id]).to eq "xyz" }
68
+ end
69
+ end
70
+
71
+ describe Kitchen::Driver::DockerCli, "converge" do
72
+
73
+ before do
74
+ @docker_cli = Kitchen::Driver::DockerCli.new
75
+ provisioner = double('provisioner')
76
+ instance = double('instance')
77
+ provisioner.stub(:create_sandbox)
78
+ provisioner.stub(:install_command)
79
+ provisioner.stub(:init_command)
80
+ provisioner.stub(:prepare_command)
81
+ provisioner.stub(:run_command)
82
+ provisioner.stub(:cleanup_sandbox)
83
+ instance.stub(:provisioner).and_return(provisioner)
84
+ @docker_cli.stub(:instance).and_return(instance)
85
+ @docker_cli.stub(:docker_transfer_command)
86
+ @docker_cli.stub(:execute)
87
+ end
88
+
89
+ example do
90
+ expect { @docker_cli.converge(:container_id => 'abc') }.not_to raise_error
91
+ end
92
+ end
93
+
94
+ describe Kitchen::Driver::DockerCli, "setup" do
95
+
96
+ before do
97
+ @docker_cli = Kitchen::Driver::DockerCli.new
98
+ busser = double('busser')
99
+ busser.stub(:setup_cmd).and_return('setup')
100
+ @docker_cli.stub(:busser).and_return(busser)
101
+ @docker_cli.stub(:execute)
102
+ end
103
+
104
+ example do
105
+ expect{ @docker_cli.setup(:container_id => 'abc') }.not_to raise_error
106
+ end
107
+ end
108
+
109
+ describe Kitchen::Driver::DockerCli, "verify" do
110
+
111
+ before do
112
+ @docker_cli = Kitchen::Driver::DockerCli.new
113
+ busser = double('busser')
114
+ busser.stub(:sync_cmd).and_return('setup')
115
+ busser.stub(:run_cmd).and_return('setup')
116
+ @docker_cli.stub(:busser).and_return(busser)
117
+ @docker_cli.stub(:execute)
118
+ end
119
+
120
+ example do
121
+ expect{ @docker_cli.verify(:container_id => 'abc') }.not_to raise_error
122
+ end
123
+ end
124
+
125
+ describe Kitchen::Driver::DockerCli, "destroy" do
126
+
127
+ before do
128
+ @docker_cli = Kitchen::Driver::DockerCli.new
129
+ end
130
+
131
+ example do
132
+ expect{ @docker_cli.destroy(:container_id => 'abc') }.not_to raise_error
133
+ end
134
+ end
135
+
136
+ describe Kitchen::Driver::DockerCli, "remote_command" do
137
+
138
+ before do
139
+ @docker_cli = Kitchen::Driver::DockerCli.new
140
+ @docker_cli.stub(:execute)
141
+ end
142
+
143
+ example do
144
+ opt = {:container_id => 'abc'}
145
+ expect{ @docker_cli.remote_command(opt, "test") }.not_to raise_error
146
+ end
147
+ end
148
+
149
+ describe Kitchen::Driver::DockerCli, "login_command" do
150
+
151
+ before do
152
+ @docker_cli = Kitchen::Driver::DockerCli.new()
153
+ end
154
+
155
+ example do
156
+ login_command = @docker_cli.login_command(:container_id => 'abc')
157
+ cmd, *args = login_command.cmd_array
158
+ cmd = "#{cmd} #{args.join(" ")}"
159
+ expect(cmd).to eq "docker exec -t -i abc /bin/bash"
160
+ end
161
+ end
162
+
163
+ describe Kitchen::Driver::DockerCli, "build" do
164
+
165
+ before do
166
+ @docker_cli = Kitchen::Driver::DockerCli.new
167
+ @docker_cli.stub(:docker_build_command)
168
+ @docker_cli.stub(:docker_file)
169
+ @docker_cli.stub(:parse_image_id)
170
+ @docker_cli.stub(:execute)
171
+ end
172
+
173
+ example do
174
+ expect{ @docker_cli.build }.not_to raise_error
175
+ end
176
+ end
177
+
178
+ describe Kitchen::Driver::DockerCli, "run" do
179
+
180
+ before do
181
+ @docker_cli = Kitchen::Driver::DockerCli.new
182
+ @docker_cli.stub(:docker_run_command)
183
+ @docker_cli.stub(:parse_container_id)
184
+ @docker_cli.stub(:execute)
185
+ end
186
+
187
+ example do
188
+ expect{ @docker_cli.run('test') }.not_to raise_error
189
+ end
190
+ end
191
+
192
+ describe Kitchen::Driver::DockerCli, "docker_build_command" do
193
+
194
+ before do
195
+ @docker_cli = Kitchen::Driver::DockerCli.new(config)
196
+ end
197
+
198
+ context 'default' do
199
+ let(:config) { Hash.new }
200
+
201
+ example do
202
+ expect(@docker_cli.docker_build_command).to eq 'build --no-cache -'
203
+ end
204
+ end
205
+
206
+ context 'nocache' do
207
+ let(:config) { {:no_cache => false} }
208
+
209
+ example do
210
+ expect(@docker_cli.docker_build_command).to eq 'build -'
211
+ end
212
+ end
213
+ end
214
+
215
+ describe Kitchen::Driver::DockerCli, "docker_run_command" do
216
+
217
+ before do
218
+ @docker_cli = Kitchen::Driver::DockerCli.new(config)
219
+ end
220
+
221
+ context 'default' do
222
+ let(:config) { {:command => '/bin/bash'} }
223
+
224
+ example do
225
+ cmd = "run -d -v #{Dir::tmpdir}:/tmp:rw test /bin/bash"
226
+ expect(@docker_cli.docker_run_command('test')).to eq cmd
227
+ end
228
+ end
229
+
230
+ context 'set configs' do
231
+ let(:config) do
232
+ {
233
+ :command => '/bin/bash',
234
+ :container_name => 'web',
235
+ :publish_all => true,
236
+ :publish => ['80:8080', '22:2222'],
237
+ :volume => '/dev:/dev',
238
+ :link => 'mysql:db'
239
+ }
240
+ end
241
+
242
+ example do
243
+ cmd = "run -d -v #{Dir::tmpdir}:/tmp:rw --name web -P -p 80:8080 -p 22:2222 -v /dev:/dev --link mysql:db test /bin/bash"
244
+ expect(@docker_cli.docker_run_command('test')).to eq cmd
245
+ end
246
+ end
247
+ end
248
+
249
+ describe Kitchen::Driver::DockerCli, "parse_image_id" do
250
+
251
+ before do
252
+ @docker_cli = Kitchen::Driver::DockerCli.new()
253
+ end
254
+
255
+ example do
256
+ expect { @docker_cli.parse_image_id("Successfully built abc123def456\n").to eq "abc123def456" }
257
+ end
258
+ example do
259
+ expect { @docker_cli.parse_image_id("Successfully built abc123\n") }.to raise_error('Could not parse IMAGE ID.')
260
+ end
261
+ example do
262
+ expect { @docker_cli.parse_image_id("Error abc123def456\n") }.to raise_error('Could not parse IMAGE ID.')
263
+ end
264
+
265
+ end
266
+
267
+ describe Kitchen::Driver::DockerCli, "parse_container_id" do
268
+
269
+ before do
270
+ @docker_cli = Kitchen::Driver::DockerCli.new()
271
+ end
272
+
273
+ example do
274
+ expect do
275
+ output = "abcd1234efgh5678"
276
+ output << "abcd1234efgh5678"
277
+ output << "abcd1234efgh5678"
278
+ output << "abcd1234efgh5678\n"
279
+ @docker_cli.parse_container_id(output).to eq output.chomp
280
+ end
281
+ end
282
+
283
+ example do
284
+ expect do
285
+ output = "abcd1234efgh5678"
286
+ output << "abcd1234efgh5678"
287
+ output << "abcd1234efgh5678\n"
288
+ @docker_cli.parse_container_id(output)
289
+ end.to raise_error('Could not parse CONTAINER ID.')
290
+ end
291
+
292
+ end
293
+
294
+ describe Kitchen::Driver::DockerCli, "docker_file" do
295
+
296
+ before do
297
+ @docker_cli = Kitchen::Driver::DockerCli.new(config)
298
+ end
299
+
300
+ context 'not set run_command' do
301
+ let(:config) do
302
+ {
303
+ image: "centos/centos6",
304
+ platform: "centos"
305
+ }
306
+ end
307
+ example do
308
+ ret = "FROM centos/centos6\n"
309
+ ret << "RUN yum clean all\n"
310
+ ret << "RUN yum -y install sudo curl"
311
+ expect(@docker_cli.send(:docker_file)).to eq ret
312
+ end
313
+ end
314
+
315
+ context 'set run_command' do
316
+ let(:config) {
317
+ {
318
+ image: "ubuntu/12.04",
319
+ platform: "ubuntu",
320
+ run_command: ["test", "test2"]
321
+ }
322
+ }
323
+ example do
324
+ ret = "FROM ubuntu/12.04\n"
325
+ ret = "FROM ubuntu/12.04\n"
326
+ ret << "RUN apt-get update\n"
327
+ ret << "RUN apt-get -y install sudo curl\n"
328
+ ret << "RUN test\nRUN test2"
329
+ expect(@docker_cli.send(:docker_file)).to eq ret
330
+ end
331
+ end
332
+ end
333
+
334
+ describe Kitchen::Driver::DockerCli, "docker_exec_command" do
335
+
336
+ before do
337
+ @docker_cli = Kitchen::Driver::DockerCli.new()
338
+ end
339
+
340
+ example do
341
+ cmd = 'exec abc /bin/bash'
342
+ expect(@docker_cli.docker_exec_command('abc','/bin/bash')).to eq cmd
343
+ end
344
+ example do
345
+ cmd = 'exec -t -i abc /bin/bash'
346
+ opt = {:interactive => true, :tty => true}
347
+ expect(@docker_cli.docker_exec_command('abc', '/bin/bash', opt)).to eq cmd
348
+ end
349
+ end
350
+
351
+ describe Kitchen::Driver::DockerCli, "docker_transfer_command" do
352
+
353
+ before do
354
+ @docker_cli = Kitchen::Driver::DockerCli.new()
355
+ end
356
+
357
+ example do
358
+ provisoner = {:root_path => '/tmp/kitchen'}
359
+ provisoner.stub(:sandbox_path).and_return('/tmp/sandbox')
360
+ cmd = "exec abc rm -rf /tmp/kitchen && mkdir /tmp/kitchen && cp -rp /tmp/sandbox/* /tmp/kitchen/"
361
+ expect(@docker_cli.docker_transfer_command(provisoner, 'abc')).to eq cmd
362
+ end
363
+ end
@@ -0,0 +1,2 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
@@ -0,0 +1,8 @@
1
+ require 'serverspec'
2
+ set :backend, :exec
3
+
4
+ set :path, '/sbin:/usr/local/sbin:$PATH'
5
+
6
+ describe file('/tmp') do
7
+ it { should be_directory }
8
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kitchen-docker_cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.alpha2
5
+ platform: ruby
6
+ authors:
7
+ - Masashi Terui
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: test-kitchen
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'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: coveralls
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec-its
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: A Test Kitchen Driver for Docker native CLI
98
+ email:
99
+ - marcy9114@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".coveralls.yml"
105
+ - ".gitignore"
106
+ - ".kitchen.yml"
107
+ - ".travis.yml"
108
+ - CHANGELOG.md
109
+ - Gemfile
110
+ - LICENSE
111
+ - README.md
112
+ - Rakefile
113
+ - kitchen-docker_cli.gemspec
114
+ - lib/kitchen/driver/docker_cli.rb
115
+ - lib/kitchen/driver/docker_cli_version.rb
116
+ - spec/kitchen/driver/docker_cli_spec.rb
117
+ - spec/spec_helper.rb
118
+ - test/integration/default/serverspec/default_spec.rb
119
+ homepage: https://github.com/marcy-terui/kitchen-docker_cli
120
+ licenses:
121
+ - Apache 2.0
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">"
135
+ - !ruby/object:Gem::Version
136
+ version: 1.3.1
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.2.2
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: A Test Kitchen Driver for Docker native CLI
143
+ test_files:
144
+ - spec/kitchen/driver/docker_cli_spec.rb
145
+ - spec/spec_helper.rb
146
+ - test/integration/default/serverspec/default_spec.rb