kitchen-docker 0.1.0.dev

Sign up to get free protection for your applications and to get access to all the features.
data/.cane ADDED
File without changes
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/.tailor ADDED
@@ -0,0 +1,4 @@
1
+ Tailor.config do |config|
2
+ config.formatters "text"
3
+ config.file_set 'lib/**/*.rb'
4
+ end
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.0.0
5
+ - 1.9.3
6
+ - 1.9.2
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 / Unreleased
2
+
3
+ * Initial release
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ Author:: Sean Porter (<portertech@gmail.com>)
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.
data/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # <a name="title"></a> Kitchen::Docker
2
+
3
+ A Test Kitchen Driver for Docker.
4
+
5
+ ## <a name="requirements"></a> Requirements
6
+
7
+ **TODO:** document any software or library prerequisites that are required to
8
+ use this driver. Implement the `#verify_dependencies` method in your Driver
9
+ class to enforce these requirements in code, if possible.
10
+
11
+ ## <a name="installation"></a> Installation and Setup
12
+
13
+ Please read the [Driver usage][driver_usage] page for more details.
14
+
15
+ ## <a name="config"></a> Configuration
16
+
17
+ **TODO:** Write descriptions of all configuration options
18
+
19
+ ### <a name="config-require-chef-omnibus"></a> require\_chef\_omnibus
20
+
21
+ Determines whether or not a Chef [Omnibus package][chef_omnibus_dl] will be
22
+ installed. There are several different behaviors available:
23
+
24
+ * `true` - the latest release will be installed. Subsequent converges
25
+ will skip re-installing if chef is present.
26
+ * `latest` - the latest release will be installed. Subsequent converges
27
+ will always re-install even if chef is present.
28
+ * `<VERSION_STRING>` (ex: `10.24.0`) - the desired version string will
29
+ be passed the the install.sh script. Subsequent converges will skip if
30
+ the installed version and the desired version match.
31
+ * `false` or `nil` - no chef is installed.
32
+
33
+ The default value is unset, or `nil`.
34
+
35
+ ## <a name="development"></a> Development
36
+
37
+ * Source hosted at [GitHub][repo]
38
+ * Report issues/questions/feature requests on [GitHub Issues][issues]
39
+
40
+ Pull requests are very welcome! Make sure your patches are well tested.
41
+ Ideally create a topic branch for every separate change you make. For
42
+ example:
43
+
44
+ 1. Fork the repo
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create new Pull Request
49
+
50
+ ## <a name="authors"></a> Authors
51
+
52
+ Created and maintained by [Sean Porter][author] (<portertech@gmail.com>)
53
+
54
+ ## <a name="license"></a> License
55
+
56
+ Apache 2.0 (see [LICENSE][license])
57
+
58
+
59
+ [author]: https://github.com/enter-github-user
60
+ [issues]: https://github.com/enter-github-user/kitchen-docker/issues
61
+ [license]: https://github.com/enter-github-user/kitchen-docker/blob/master/LICENSE
62
+ [repo]: https://github.com/enter-github-user/kitchen-docker
63
+ [driver_usage]: http://docs.kitchen-ci.org/drivers/usage
64
+ [chef_omnibus_dl]: http://www.opscode.com/chef/install/
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ require "bundler/gem_tasks"
2
+ require 'cane/rake_task'
3
+ require 'tailor/rake_task'
4
+
5
+ desc "Run cane to check quality metrics"
6
+ Cane::RakeTask.new do |cane|
7
+ cane.canefile = './.cane'
8
+ end
9
+
10
+ Tailor::RakeTask.new
11
+
12
+ desc "Display LOC stats"
13
+ task :stats do
14
+ puts "\n## Production Code Stats"
15
+ sh "countloc -r lib"
16
+ end
17
+
18
+ desc "Run all quality tasks"
19
+ task :quality => [:cane, :tailor, :stats]
20
+
21
+ task :default => [:quality]
@@ -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_version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'kitchen-docker'
8
+ spec.version = Kitchen::Driver::DOCKER_VERSION
9
+ spec.authors = ['Sean Porter']
10
+ spec.email = ['portertech@gmail.com']
11
+ spec.description = %q{A Test Kitchen Driver for Docker}
12
+ spec.summary = spec.description
13
+ spec.homepage = 'https://github.com/portertech/kitchen-docker'
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', '~> 1.0.0.alpha.3'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.3'
24
+ spec.add_development_dependency 'rake'
25
+
26
+ spec.add_development_dependency 'cane'
27
+ spec.add_development_dependency 'tailor'
28
+ spec.add_development_dependency 'countloc'
29
+ end
@@ -0,0 +1,116 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ # Author:: Sean Porter (<portertech@gmail.com>)
4
+ # Author:: AJ Christensen (<aj@junglist.gen.nz>)
5
+ #
6
+ # Copyright (C) 2013, Sean Porter
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+
20
+ require 'kitchen'
21
+
22
+ module Kitchen
23
+
24
+ module Driver
25
+
26
+ # Docker driver for Kitchen.
27
+ #
28
+ # @author Sean Porter <portertech@gmail.com>
29
+ class Docker < Kitchen::Driver::SSHBase
30
+
31
+ default_config :image, 'ubuntu'
32
+ default_config :port, '22'
33
+ default_config :username, 'kitchen'
34
+ default_config :password, 'kitchen'
35
+ default_config :require_chef_omnibus, 'latest'
36
+
37
+ def create(state)
38
+ state[:image_id] = build_image(state) unless state[:image_id]
39
+ state[:container_id] = run_container(state) unless state[:container_id]
40
+ state[:hostname] = container_address(state) unless state[:hostname]
41
+ wait_for_sshd(state[:hostname])
42
+ ensure_fqdn(state)
43
+ end
44
+
45
+ def destroy(state)
46
+ kill_container(state) if state[:container_id]
47
+ rm_image(state) if state[:image_id]
48
+ end
49
+
50
+ protected
51
+
52
+ def dockerfile
53
+ path = File.join(File.dirname(__FILE__), 'docker', 'Dockerfile')
54
+ File.expand_path(path)
55
+ end
56
+
57
+ def parse_image_id(output)
58
+ output.each_line do |line|
59
+ return line.split(/\s+/).last if line =~ /image id/i
60
+ end
61
+ raise ActionFailed, 'Could not parse Docker build output for image ID'
62
+ end
63
+
64
+ def build_image(state)
65
+ output = run_command("cat #{dockerfile} | docker build -")
66
+ parse_image_id(output)
67
+ end
68
+
69
+ def parse_container_id(output)
70
+ container_id = output.chomp
71
+ unless container_id.size == 12
72
+ raise ActionFailed,
73
+ 'Could not parse Docker run output for container ID'
74
+ end
75
+ container_id
76
+ end
77
+
78
+ def run_container(state)
79
+ image_id = state[:image_id]
80
+ output = run_command("docker run -d #{image_id} /usr/sbin/sshd -D -u0")
81
+ parse_container_id(output)
82
+ end
83
+
84
+ def parse_container_ip(output)
85
+ begin
86
+ info = JSON.parse(output)
87
+ info['NetworkSettings']['IpAddress']
88
+ rescue
89
+ raise ActionFailed,
90
+ 'Could not parse Docker inspect output for container IP address'
91
+ end
92
+ end
93
+
94
+ def container_address(state)
95
+ container_id = state[:container_id]
96
+ output = run_command("docker inspect #{container_id}", :quiet => true)
97
+ parse_container_ip(output)
98
+ end
99
+
100
+ def ensure_fqdn(state)
101
+ ssh_args = build_ssh_args(state)
102
+ ssh(ssh_args, 'echo "127.0.0.1 `hostname`" | sudo tee -a /etc/hosts')
103
+ end
104
+
105
+ def kill_container(state)
106
+ container_id = state[:container_id]
107
+ run_command("docker kill #{container_id}")
108
+ end
109
+
110
+ def rm_image(state)
111
+ image_id = state[:image_id]
112
+ run_command("docker rmi #{image_id}")
113
+ end
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,17 @@
1
+ FROM ubuntu
2
+
3
+ ENV DEBIAN_FRONTEND noninteractive
4
+
5
+ RUN apt-get update
6
+
7
+ RUN apt-get install -y sudo openssh-server
8
+
9
+ RUN mkdir /var/run/sshd
10
+
11
+ RUN useradd -d /home/kitchen -m -s /bin/bash kitchen
12
+
13
+ RUN echo kitchen:kitchen | chpasswd
14
+
15
+ RUN echo 'kitchen ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
16
+
17
+ RUN echo '127.0.0.1 localhost.localdomain localhost' >> /etc/hosts
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ # Author:: Sean Porter (<portertech@gmail.com>)
4
+ #
5
+ # Copyright (C) 2013, Sean Porter
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 Docker Kitchen driver
24
+ DOCKER_VERSION = "0.1.0.dev"
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kitchen-docker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.dev
5
+ prerelease: 6
6
+ platform: ruby
7
+ authors:
8
+ - Sean Porter
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.0.alpha.3
20
+ none: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ~>
24
+ - !ruby/object:Gem::Version
25
+ version: 1.0.0.alpha.3
26
+ none: false
27
+ prerelease: false
28
+ name: test-kitchen
29
+ type: :runtime
30
+ - !ruby/object:Gem::Dependency
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: '1.3'
36
+ none: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ version: '1.3'
42
+ none: false
43
+ prerelease: false
44
+ name: bundler
45
+ type: :development
46
+ - !ruby/object:Gem::Dependency
47
+ requirement: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ none: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ none: false
59
+ prerelease: false
60
+ name: rake
61
+ type: :development
62
+ - !ruby/object:Gem::Dependency
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ none: false
69
+ version_requirements: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ none: false
75
+ prerelease: false
76
+ name: cane
77
+ type: :development
78
+ - !ruby/object:Gem::Dependency
79
+ requirement: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ none: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ none: false
91
+ prerelease: false
92
+ name: tailor
93
+ type: :development
94
+ - !ruby/object:Gem::Dependency
95
+ requirement: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ none: false
101
+ version_requirements: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ! '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ none: false
107
+ prerelease: false
108
+ name: countloc
109
+ type: :development
110
+ description: A Test Kitchen Driver for Docker
111
+ email:
112
+ - portertech@gmail.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - .cane
118
+ - .gitignore
119
+ - .tailor
120
+ - .travis.yml
121
+ - CHANGELOG.md
122
+ - Gemfile
123
+ - LICENSE
124
+ - README.md
125
+ - Rakefile
126
+ - kitchen-docker.gemspec
127
+ - lib/kitchen/driver/docker.rb
128
+ - lib/kitchen/driver/docker/Dockerfile
129
+ - lib/kitchen/driver/docker_version.rb
130
+ homepage: https://github.com/portertech/kitchen-docker
131
+ licenses:
132
+ - Apache 2.0
133
+ post_install_message:
134
+ rdoc_options: []
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ hash: 1116186526893056534
142
+ version: '0'
143
+ segments:
144
+ - 0
145
+ none: false
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ! '>'
149
+ - !ruby/object:Gem::Version
150
+ version: 1.3.1
151
+ none: false
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 1.8.24
155
+ signing_key:
156
+ specification_version: 3
157
+ summary: A Test Kitchen Driver for Docker
158
+ test_files: []