docker-provider 0.0.1
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 +7 -0
- data/.gitignore +19 -0
- data/.rspec +2 -0
- data/.travis.yml +8 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +21 -0
- data/Gemfile.lock +125 -0
- data/Guardfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +134 -0
- data/Rakefile +20 -0
- data/boxes/dummy/README.md +17 -0
- data/boxes/dummy/metadata.json +3 -0
- data/boxes/nginx/.gitignore +1 -0
- data/boxes/nginx/Dockerfile +4 -0
- data/boxes/nginx/README.md +25 -0
- data/boxes/nginx/Vagrantfile.sample +6 -0
- data/boxes/nginx/metadata.json +3 -0
- data/boxes/nginx/start +5 -0
- data/boxes/precise/.gitignore +1 -0
- data/boxes/precise/Dockerfile +42 -0
- data/boxes/precise/README.md +18 -0
- data/boxes/precise/Vagrantfile.sample +6 -0
- data/boxes/precise/metadata.json +3 -0
- data/development/Vagrantfile +91 -0
- data/docker-provider.gemspec +25 -0
- data/example/Vagrantfile +36 -0
- data/lib/docker-provider.rb +1 -0
- data/lib/docker-provider/action.rb +161 -0
- data/lib/docker-provider/action/check_running.rb +25 -0
- data/lib/docker-provider/action/create.rb +56 -0
- data/lib/docker-provider/action/created.rb +18 -0
- data/lib/docker-provider/action/destroy.rb +24 -0
- data/lib/docker-provider/action/forward_ports.rb +54 -0
- data/lib/docker-provider/action/is_running.rb +20 -0
- data/lib/docker-provider/action/message.rb +23 -0
- data/lib/docker-provider/action/share_folders.rb +63 -0
- data/lib/docker-provider/action/start.rb +18 -0
- data/lib/docker-provider/action/stop.rb +21 -0
- data/lib/docker-provider/config.rb +28 -0
- data/lib/docker-provider/driver.rb +114 -0
- data/lib/docker-provider/plugin.rb +24 -0
- data/lib/docker-provider/provider.rb +59 -0
- data/lib/docker-provider/version.rb +5 -0
- data/locales/en.yml +21 -0
- data/spec/acceptance/Vagrantfile +25 -0
- data/spec/acceptance/vagrant_ssh.bats +34 -0
- data/spec/acceptance/vagrant_up.bats +35 -0
- data/spec/spec_helper.rb +19 -0
- data/spec/support/unit_example_group.rb +39 -0
- data/spec/unit/driver_spec.rb +143 -0
- metadata +142 -0
data/locales/en.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
en:
|
2
|
+
docker_provider:
|
3
|
+
messages:
|
4
|
+
not_created: |-
|
5
|
+
The container hasn't been created yet.
|
6
|
+
not_running: |-
|
7
|
+
The container is not currently running.
|
8
|
+
will_not_destroy: |-
|
9
|
+
The container '%{name}' will not be destroyed, since the confirmation
|
10
|
+
was declined.
|
11
|
+
starting: |-
|
12
|
+
Starting container...
|
13
|
+
stopping: |-
|
14
|
+
Stopping container...
|
15
|
+
container_ready: |-
|
16
|
+
Container started and ready for use!
|
17
|
+
|
18
|
+
errors:
|
19
|
+
config:
|
20
|
+
image_not_set: 'The base Docker image has not been set!'
|
21
|
+
image_not_set: 'The Docker command has not been set!'
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
# vi: set ft=ruby :
|
3
|
+
|
4
|
+
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'docker'
|
5
|
+
|
6
|
+
# This is only needed if you are using the plugin from sources with bundler
|
7
|
+
Vagrant.require_plugin 'docker-provider'
|
8
|
+
|
9
|
+
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
|
10
|
+
VAGRANTFILE_API_VERSION = "2"
|
11
|
+
|
12
|
+
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
13
|
+
config.vm.box = "precise"
|
14
|
+
|
15
|
+
config.vm.provider :docker do |docker|
|
16
|
+
docker.image = "fgrehm/vagrant-ubuntu:precise"
|
17
|
+
docker.cmd = ["/usr/sbin/sshd", "-D", "-e"]
|
18
|
+
end
|
19
|
+
|
20
|
+
config.vm.provision :shell, inline: %[
|
21
|
+
echo 'hello from docker'
|
22
|
+
# mkdir -p /vagrant/tmp
|
23
|
+
# touch /vagrant/tmp/provisioned
|
24
|
+
]
|
25
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env bats
|
2
|
+
|
3
|
+
setup() {
|
4
|
+
if ! [ $USER = 'vagrant' ]; then
|
5
|
+
echo 'The specs should be run from a Vagrant VM'
|
6
|
+
exit 1
|
7
|
+
fi
|
8
|
+
|
9
|
+
# Destroy all of acceptance specs related containers
|
10
|
+
containers=$(docker ps -a | grep acceptance | wc -l)
|
11
|
+
if [ "$containers" -gt 0 ]; then
|
12
|
+
test_containers=$(docker ps -a | grep acceptance | cut -d' ' -f1)
|
13
|
+
docker stop -t=1 $test_containers
|
14
|
+
docker rm $test_containers
|
15
|
+
fi
|
16
|
+
rm -rf /vagrant/spec/acceptance/{.vagrant,tmp}
|
17
|
+
}
|
18
|
+
|
19
|
+
@test "vagrant ssh on a stopped container errors out" {
|
20
|
+
cd /vagrant/spec/acceptance
|
21
|
+
|
22
|
+
run bundle exec vagrant ssh
|
23
|
+
[ "$status" -eq 1 ]
|
24
|
+
}
|
25
|
+
|
26
|
+
@test "vagrant ssh on a runing container" {
|
27
|
+
cd /vagrant/spec/acceptance
|
28
|
+
bundle exec vagrant up
|
29
|
+
|
30
|
+
run bundle exec vagrant ssh -c 'echo "hello from ssh"'
|
31
|
+
|
32
|
+
[ "$status" -eq 0 ]
|
33
|
+
echo $output | grep -q 'hello from ssh'
|
34
|
+
}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/usr/bin/env bats
|
2
|
+
|
3
|
+
setup() {
|
4
|
+
if ! [ $USER = 'vagrant' ]; then
|
5
|
+
echo 'The specs should be run from a Vagrant VM'
|
6
|
+
exit 1
|
7
|
+
fi
|
8
|
+
|
9
|
+
# Destroy all of acceptance specs related containers
|
10
|
+
containers=$(docker ps -a | grep acceptance | wc -l)
|
11
|
+
if [ "$containers" -gt 0 ]; then
|
12
|
+
test_containers=$(docker ps -a | grep acceptance | cut -d' ' -f1)
|
13
|
+
docker stop -t=1 $test_containers
|
14
|
+
docker rm $test_containers
|
15
|
+
fi
|
16
|
+
rm -rf /vagrant/spec/acceptance/{.vagrant,tmp}
|
17
|
+
}
|
18
|
+
|
19
|
+
@test "vagrant up from scratch runs a docker container" {
|
20
|
+
cd /vagrant/spec/acceptance
|
21
|
+
|
22
|
+
run bundle exec vagrant up
|
23
|
+
[ "$status" -eq 0 ]
|
24
|
+
|
25
|
+
# How many test containers have we got?
|
26
|
+
count=$(docker ps | grep acceptance | wc -l)
|
27
|
+
[ "$count" -eq 1 ]
|
28
|
+
}
|
29
|
+
|
30
|
+
@test "vagrant up from scratch provisions docker container" {
|
31
|
+
cd /vagrant/spec/acceptance
|
32
|
+
run bundle exec vagrant up
|
33
|
+
|
34
|
+
echo $output | grep -q 'hello from docker'
|
35
|
+
}
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
|
3
|
+
Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each { |f| require f }
|
4
|
+
|
5
|
+
RSpec.configure do |config|
|
6
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
7
|
+
config.run_all_when_everything_filtered = true
|
8
|
+
config.filter_run :focus
|
9
|
+
|
10
|
+
# Run specs in random order to surface order dependencies. If you find an
|
11
|
+
# order dependency and want to debug it, you can fix the order by providing
|
12
|
+
# the seed, which is printed after each run.
|
13
|
+
# --seed 1234
|
14
|
+
config.order = 'random'
|
15
|
+
|
16
|
+
config.include UnitExampleGroup, :type => :unit, :example_group => {
|
17
|
+
:file_path => /\bspec\/unit\//
|
18
|
+
}
|
19
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module UnitExampleGroup
|
2
|
+
def self.included(base)
|
3
|
+
base.metadata[:type] = :unit
|
4
|
+
base.before do
|
5
|
+
Object.any_instance.stub(:system) { |*args, &block|
|
6
|
+
UnitExampleGroup.prevent_system_calls(*args, &block)
|
7
|
+
}
|
8
|
+
Object.any_instance.stub(:`) { |*args, &block|
|
9
|
+
UnitExampleGroup.prevent_system_calls(*args, &block)
|
10
|
+
}
|
11
|
+
Object.any_instance.stub(:exec) { |*args, &block|
|
12
|
+
UnitExampleGroup.prevent_system_calls(*args, &block)
|
13
|
+
}
|
14
|
+
Object.any_instance.stub(:fork) { |*args, &block|
|
15
|
+
UnitExampleGroup.prevent_system_calls(*args, &block)
|
16
|
+
}
|
17
|
+
Object.any_instance.stub(:spawn) { |*args, &block|
|
18
|
+
UnitExampleGroup.prevent_system_calls(*args, &block)
|
19
|
+
}
|
20
|
+
require 'vagrant/util/subprocess'
|
21
|
+
Vagrant::Util::Subprocess.stub(:execute) { |*args, &block|
|
22
|
+
UnitExampleGroup.prevent_system_calls(*args, &block)
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.prevent_system_calls(*args, &block)
|
28
|
+
args.pop if args.last.is_a?(Hash)
|
29
|
+
|
30
|
+
raise <<-MSG
|
31
|
+
Somehow your code under test is trying to execute a command on your system,
|
32
|
+
please stub it out or move your spec code to an acceptance spec.
|
33
|
+
|
34
|
+
Block: #{block.inspect}
|
35
|
+
Command: "#{args.join(' ')}"
|
36
|
+
MSG
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
@@ -0,0 +1,143 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'docker-provider/driver'
|
4
|
+
|
5
|
+
describe VagrantPlugins::DockerProvider::Driver do
|
6
|
+
let(:cmd_executed) { @cmd }
|
7
|
+
let(:cid) { 'side-1-song-10' }
|
8
|
+
|
9
|
+
before do
|
10
|
+
subject.stub(:execute) { |*args| @cmd = args.join(' ') }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#create' do
|
14
|
+
let(:params) { {
|
15
|
+
image: 'jimi/hendrix:eletric-ladyland',
|
16
|
+
cmd: ['play', 'voodoo-chile'],
|
17
|
+
ports: '8080:80',
|
18
|
+
volumes: '/host/path:guest/path',
|
19
|
+
name: cid,
|
20
|
+
hostname: 'jimi-hendrix'
|
21
|
+
} }
|
22
|
+
|
23
|
+
before { subject.create(params) }
|
24
|
+
|
25
|
+
it 'runs a detached docker image' do
|
26
|
+
expect(cmd_executed).to match(/^docker run .+ -d .+ #{Regexp.escape params[:image]}/)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'sets container name' do
|
30
|
+
expect(cmd_executed).to match(/-name #{Regexp.escape params[:name]}/)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'forwards ports' do
|
34
|
+
expect(cmd_executed).to match(/-p #{params[:ports]} .+ #{Regexp.escape params[:image]}/)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'shares folders' do
|
38
|
+
expect(cmd_executed).to match(/-v #{params[:volumes]} .+ #{Regexp.escape params[:image]}/)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'sets the hostname if specified' do
|
42
|
+
expect(cmd_executed).to match(/-h #{params[:hostname]} #{Regexp.escape params[:image]}/)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'executes the provided command' do
|
46
|
+
expect(cmd_executed).to match(/#{Regexp.escape params[:image]} #{Regexp.escape params[:cmd].join(' ')}/)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '#created?' do
|
51
|
+
let(:result) { subject.created?(cid) }
|
52
|
+
|
53
|
+
it 'performs the check on all containers list' do
|
54
|
+
subject.created?(cid)
|
55
|
+
expect(cmd_executed).to match(/docker ps \-a \-q/)
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'when container exists' do
|
59
|
+
before { subject.stub(execute: "foo\n#{cid}\nbar") }
|
60
|
+
it { expect(result).to be_true }
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'when container does not exist' do
|
64
|
+
before { subject.stub(execute: "foo\n#{cid}extra\nbar") }
|
65
|
+
it { expect(result).to be_false }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe '#running?' do
|
70
|
+
let(:result) { subject.running?(cid) }
|
71
|
+
|
72
|
+
it 'performs the check on the running containers list' do
|
73
|
+
subject.running?(cid)
|
74
|
+
expect(cmd_executed).to match(/docker ps \-q/)
|
75
|
+
expect(cmd_executed).to_not include('-a')
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'when container exists' do
|
79
|
+
before { subject.stub(execute: "foo\n#{cid}\nbar") }
|
80
|
+
it { expect(result).to be_true }
|
81
|
+
end
|
82
|
+
|
83
|
+
context 'when container does not exist' do
|
84
|
+
before { subject.stub(execute: "foo\n#{cid}extra\nbar") }
|
85
|
+
it { expect(result).to be_false }
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe '#start' do
|
90
|
+
context 'when container is running' do
|
91
|
+
before { subject.stub(running?: true) }
|
92
|
+
|
93
|
+
it 'does not start the container' do
|
94
|
+
subject.should_not_receive(:execute).with('docker', 'start', cid)
|
95
|
+
subject.start(cid)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context 'when container is not running' do
|
100
|
+
before { subject.stub(running?: false) }
|
101
|
+
|
102
|
+
it 'starts the container' do
|
103
|
+
subject.should_receive(:execute).with('docker', 'start', cid)
|
104
|
+
subject.start(cid)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe '#stop' do
|
110
|
+
context 'when container is running' do
|
111
|
+
before { subject.stub(running?: true) }
|
112
|
+
|
113
|
+
it 'stops the container' do
|
114
|
+
subject.should_receive(:execute).with('docker', 'stop', cid)
|
115
|
+
subject.stop(cid)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
context 'when container is not running' do
|
120
|
+
before { subject.stub(running?: false) }
|
121
|
+
|
122
|
+
it 'does not stop container' do
|
123
|
+
subject.should_not_receive(:execute).with('docker', 'stop', cid)
|
124
|
+
subject.stop(cid)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe '#inspect' do
|
130
|
+
let(:data) { '[{"json": "value"}]' }
|
131
|
+
|
132
|
+
before { subject.stub(execute: data) }
|
133
|
+
|
134
|
+
it 'inspects the container' do
|
135
|
+
subject.should_receive(:execute).with('docker', 'inspect', cid)
|
136
|
+
subject.inspect(cid)
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'parses the json output' do
|
140
|
+
expect(subject.inspect(cid)).to eq('json' => 'value')
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: docker-provider
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Fabio Rehm
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-11-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
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
|
+
description: Experimental Docker provider for Vagrant
|
56
|
+
email:
|
57
|
+
- fgrehm@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- .rspec
|
64
|
+
- .travis.yml
|
65
|
+
- CHANGELOG.md
|
66
|
+
- Gemfile
|
67
|
+
- Gemfile.lock
|
68
|
+
- Guardfile
|
69
|
+
- LICENSE.txt
|
70
|
+
- README.md
|
71
|
+
- Rakefile
|
72
|
+
- boxes/dummy/README.md
|
73
|
+
- boxes/dummy/metadata.json
|
74
|
+
- boxes/nginx/.gitignore
|
75
|
+
- boxes/nginx/Dockerfile
|
76
|
+
- boxes/nginx/README.md
|
77
|
+
- boxes/nginx/Vagrantfile.sample
|
78
|
+
- boxes/nginx/metadata.json
|
79
|
+
- boxes/nginx/start
|
80
|
+
- boxes/precise/.gitignore
|
81
|
+
- boxes/precise/Dockerfile
|
82
|
+
- boxes/precise/README.md
|
83
|
+
- boxes/precise/Vagrantfile.sample
|
84
|
+
- boxes/precise/metadata.json
|
85
|
+
- development/Vagrantfile
|
86
|
+
- docker-provider.gemspec
|
87
|
+
- example/Vagrantfile
|
88
|
+
- lib/docker-provider.rb
|
89
|
+
- lib/docker-provider/action.rb
|
90
|
+
- lib/docker-provider/action/check_running.rb
|
91
|
+
- lib/docker-provider/action/create.rb
|
92
|
+
- lib/docker-provider/action/created.rb
|
93
|
+
- lib/docker-provider/action/destroy.rb
|
94
|
+
- lib/docker-provider/action/forward_ports.rb
|
95
|
+
- lib/docker-provider/action/is_running.rb
|
96
|
+
- lib/docker-provider/action/message.rb
|
97
|
+
- lib/docker-provider/action/share_folders.rb
|
98
|
+
- lib/docker-provider/action/start.rb
|
99
|
+
- lib/docker-provider/action/stop.rb
|
100
|
+
- lib/docker-provider/config.rb
|
101
|
+
- lib/docker-provider/driver.rb
|
102
|
+
- lib/docker-provider/plugin.rb
|
103
|
+
- lib/docker-provider/provider.rb
|
104
|
+
- lib/docker-provider/version.rb
|
105
|
+
- locales/en.yml
|
106
|
+
- spec/acceptance/Vagrantfile
|
107
|
+
- spec/acceptance/vagrant_ssh.bats
|
108
|
+
- spec/acceptance/vagrant_up.bats
|
109
|
+
- spec/spec_helper.rb
|
110
|
+
- spec/support/unit_example_group.rb
|
111
|
+
- spec/unit/driver_spec.rb
|
112
|
+
homepage: https://github.com/fgrehm/docker-provider
|
113
|
+
licenses:
|
114
|
+
- MIT
|
115
|
+
metadata: {}
|
116
|
+
post_install_message:
|
117
|
+
rdoc_options: []
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - '>='
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
requirements: []
|
131
|
+
rubyforge_project:
|
132
|
+
rubygems_version: 2.1.5
|
133
|
+
signing_key:
|
134
|
+
specification_version: 4
|
135
|
+
summary: Experimental Docker provider for Vagrant
|
136
|
+
test_files:
|
137
|
+
- spec/acceptance/Vagrantfile
|
138
|
+
- spec/acceptance/vagrant_ssh.bats
|
139
|
+
- spec/acceptance/vagrant_up.bats
|
140
|
+
- spec/spec_helper.rb
|
141
|
+
- spec/support/unit_example_group.rb
|
142
|
+
- spec/unit/driver_spec.rb
|