Skip to content

Commit

Permalink
Merge pull request #540 from DarrellMozingo/docker_1.8
Browse files Browse the repository at this point in the history
Docker 1.8 support
  • Loading branch information
mizzy committed Oct 28, 2015
2 parents b6e17df + 119fb85 commit e0e078b
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 6 deletions.
16 changes: 16 additions & 0 deletions lib/serverspec/type/docker_container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ def running?
end

def has_volume?(container_path, host_path)
if (inspection['Mounts'])
check_volume(container_path, host_path)
else
check_volume_pre_1_8(container_path, host_path)
end
end

private
def check_volume(container_path, host_path)
inspection['Mounts'].find {|mount|
mount['Destination'] == container_path &&
mount['Source'] == host_path
}
end

def check_volume_pre_1_8(container_path, host_path)
inspection['Volumes'][container_path] == host_path
end
end
Expand Down
124 changes: 124 additions & 0 deletions spec/type/linux/docker_container_pre_1_8_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# -*- coding: utf-8 -*-
require 'spec_helper'
require 'json'

property[:os] = nil
set :os, {:family => 'linux'}

describe docker_container('c1') do
it { should exist }
end

describe docker_container('c1 pre 1.8') do
let(:stdout) { inspect_container }
it { should be_running }
it { should have_volume('/tmp', '/data') }
it { should_not have_volume('/tmp', '/data-bad') }
its(:inspection) { should include 'Driver' => 'aufs' }
its(['Config.Cmd']) { should include '/bin/sh' }
its(['HostConfig.PortBindings.80.[0].HostPort']) { should eq '8080' }
end

describe docker_container('restarting pre 1.8') do
let(:stdout) do
attrs = JSON.parse(inspect_container)
attrs.first['State']['Restarting'] = true
attrs.to_json
end

it { should_not be_running }
end

def inspect_container
<<'EOS'
[{
"Args": [],
"Config": {
"AttachStderr": false,
"AttachStdin": false,
"AttachStdout": false,
"Cmd": [
"/bin/sh"
],
"CpuShares": 0,
"Cpuset": "",
"Domainname": "",
"Entrypoint": null,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"ExposedPorts": null,
"Hostname": "65cd2e2d7963",
"Image": "busybox",
"Memory": 0,
"MemorySwap": 0,
"NetworkDisabled": false,
"OnBuild": null,
"OpenStdin": true,
"PortSpecs": null,
"StdinOnce": false,
"Tty": true,
"User": "",
"Volumes": null,
"WorkingDir": ""
},
"Created": "2014-09-26T15:08:37.527931773Z",
"Driver": "aufs",
"ExecDriver": "native-0.2",
"HostConfig": {
"Binds": [
"/data:/tmp"
],
"ContainerIDFile": "",
"Dns": null,
"DnsSearch": null,
"Links": null,
"LxcConf": [],
"NetworkMode": "bridge",
"PortBindings": {
"80": [
{
"HostIp": "",
"HostPort": "8080"
}
]
},
"Privileged": false,
"PublishAllPorts": false,
"VolumesFrom": null
},
"HostnamePath": "/mnt/sda1/var/lib/docker/containers/65cd2e2d7963bacaecda2d7fcd89499010bc0d38d70bce5ad0af7112a94a4545/hostname",
"HostsPath": "/mnt/sda1/var/lib/docker/containers/65cd2e2d7963bacaecda2d7fcd89499010bc0d38d70bce5ad0af7112a94a4545/hosts",
"Id": "65cd2e2d7963bacaecda2d7fcd89499010bc0d38d70bce5ad0af7112a94a4545",
"Image": "e72ac664f4f0c6a061ac4ef332557a70d69b0c624b6add35f1c181ff7fff2287",
"MountLabel": "",
"Name": "/c1",
"NetworkSettings": {
"Bridge": "docker0",
"Gateway": "172.17.42.1",
"IPAddress": "172.17.0.24",
"IPPrefixLen": 16,
"PortMapping": null,
"Ports": {}
},
"Path": "/bin/sh",
"ProcessLabel": "",
"ResolvConfPath": "/mnt/sda1/var/lib/docker/containers/65cd2e2d7963bacaecda2d7fcd89499010bc0d38d70bce5ad0af7112a94a4545/resolv.conf",
"State": {
"ExitCode": 0,
"FinishedAt": "0001-01-01T00:00:00Z",
"Paused": false,
"Pid": 4123,
"Running": true,
"StartedAt": "2014-09-26T15:08:37.737780273Z"
},
"Volumes": {
"/tmp": "/data"
},
"VolumesRW": {
"/tmp": true
}
}
]
EOS
end
15 changes: 9 additions & 6 deletions spec/type/linux/docker_container_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
let(:stdout) { inspect_container }
it { should be_running }
it { should have_volume('/tmp', '/data') }
it { should_not have_volume('/tmp', '/data-bad') }
its(:inspection) { should include 'Driver' => 'aufs' }
its(['Config.Cmd']) { should include '/bin/sh' }
its(['HostConfig.PortBindings.80.[0].HostPort']) { should eq '8080' }
Expand Down Expand Up @@ -111,12 +112,14 @@ def inspect_container
"Running": true,
"StartedAt": "2014-09-26T15:08:37.737780273Z"
},
"Volumes": {
"/tmp": "/data"
},
"VolumesRW": {
"/tmp": true
}
"Mounts": [
{
"Source": "/data",
"Destination": "/tmp",
"Mode": "",
"RW": true
}
]
}
]
EOS
Expand Down

0 comments on commit e0e078b

Please sign in to comment.