Skip to content

Commit

Permalink
Revert "parse binds to match docker cli parsing of -v"
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean OMeara committed Jan 3, 2016
1 parent 84e7410 commit 7725588
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 55 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1019,11 +1019,10 @@ Most `docker_container` properties are the `snake_case` version of the
- `command` - The command to run when starting the container.
- `autoremove` - Boolean - Automatically delete a container when it's
command exits. Defaults to `false`.
- `binds` - An array of volume bindings for this container. Each volume binding
is a string in one of these forms:
`container_path` to create a new volume for the container.
`host_path:container_path` to bind-mount a host path into the container.
`host_path:container_path:ro` to make the bind-mount read-only inside the container.
- `binds` - An array of `:` separated paths to bind mount from the
host into the container in the form
`['/host-bits:/container-bits', '/more-host-bits:/more-container-bits']`.
Defaults to `nil`.
- `cap_add` - An array Linux Capabilities (`man 7 capabilities`) to
add to grant the container beyond what it normally gets.
- `cap_drop` - An array Linux Capabilities (`man 7 capabilities`) to
Expand Down Expand Up @@ -1087,6 +1086,9 @@ Most `docker_container` properties are the `snake_case` version of the
Defaults to `SIGKILL`.
- `tty` - Boolean value to allocate a pseudo-TTY. Defaults to `false`.
- `user` - A string value specifying the user inside the container.
- `volumes` - An Array of paths inside the container to expose. Does
the same thing as the `VOLUME` directive in a Dockerfile, but works
on container creation.
- `volumes_from` - A list of volumes to inherit from another
container. Specified in the form `<container name>[:<ro|rw>]`
- `working_dir` - A string specifying the working directory for
Expand Down
2 changes: 1 addition & 1 deletion libraries/docker_container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class DockerContainer < DockerBase
property :attach_stdin, Boolean, desired_state: false
property :attach_stdout, Boolean, desired_state: false
property :autoremove, Boolean, desired_state: false
property :binds, ArrayType, coerce: proc { |v| coerce_binds(v) }
property :binds, ArrayType
property :cap_add, NonEmptyArray
property :cap_drop, NonEmptyArray
property :cgroup_parent, String, default: ''
Expand Down
19 changes: 1 addition & 18 deletions libraries/helpers_container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,6 @@ def coerce_ulimits(v)
end
end

def coerce_binds(v)
return v if v.nil?
Array(v).delete_if do |x|
parts = x.split(':')
if parts.length == 1
container_path = parts[0]
if property_is_set?(:volumes)
volumes.merge!(coerce_volumes(container_path))
else
volumes container_path
end
next true
end
false
end
end

def coerce_volumes(v)
case v
when nil, DockerBase::PartialHash
Expand Down Expand Up @@ -120,7 +103,7 @@ def parse_port(v)
if port_range.include?('-')
port_range = container_port.split('-')
port_range.map!(&:to_i)
fail Chef::Exceptions::ValidationFailed, "Invalid port range! #{container_port}" if port_range[0] > port_range[1]
Chef::Log.fatal("FATAL: Invalid port range! #{container_port}") if port_range[0] > port_range[1]
port_range = (port_range[0]..port_range[1]).to_a
end
# qualify the port-binding protocol even when it is implicitly tcp #427.
Expand Down
3 changes: 1 addition & 2 deletions spec/docker_test/container_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,7 @@
expect(chef_run).to run_if_missing_docker_container('bind_mounter').with(
repo: 'busybox',
command: 'ls -la /bits /more-bits',
binds: ['/hostbits:/bits', '/more-hostbits:/more-bits'],
volumes: { '/snow' => {}, '/winter' => {} }
binds: ['/hostbits:/bits', '/more-hostbits:/more-bits']
)
end
end
Expand Down
10 changes: 5 additions & 5 deletions test/cookbooks/docker_test/recipes/container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@
docker_container 'bind_mounter' do
repo 'busybox'
command 'ls -la /bits /more-bits'
binds ['/hostbits:/bits', '/more-hostbits:/more-bits', '/snow', '/winter']
binds ['/hostbits:/bits', '/more-hostbits:/more-bits']
action :run_if_missing
end

Expand Down Expand Up @@ -316,7 +316,7 @@
# create a volume container
docker_container 'chef_container' do
command 'true'
binds '/opt/chef'
volumes '/opt/chef'
action :create
end

Expand Down Expand Up @@ -395,7 +395,6 @@
repo 'debian'
volumes_from 'chef_container'
autoremove true
detach false
not_if { ::File.exist? '/marker_container_sean_was_here' }
action :run
end
Expand Down Expand Up @@ -804,8 +803,9 @@
mac_address '00:00:DE:AD:BE:EF'
network_disabled false
tty true
volumes ['/root']
working_dir '/'
binds ['/root', '/hostbits:/bits', '/more-hostbits:/more-bits']
binds ['/hostbits:/bits', '/more-hostbits:/more-bits']
cap_add %w(NET_ADMIN SYS_RESOURCE)
cap_drop 'MKNOD'
cpu_shares 512
Expand Down Expand Up @@ -876,7 +876,7 @@
user 'operator'
command 'sh -c "trap exit 0 SIGTERM; while :; do sleep 1; done"'
env ['FOO=biz']
binds '/var/log'
volumes '/var/log'
workdir '/tmp'
port ['9988:9988', '8877:8877']
action :run
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,6 @@
its(:stdout) { should match(%r{\[\/hostbits\:\/bits \/more-hostbits\:\/more-bits\]}) }
end

describe command("docker inspect -f \"{{ .Config.Volumes }}\" bind_mounter") do
its(:exit_status) { should eq 0 }
its(:stdout) { should match(%r{\/snow:\{\}}) }
its(:stdout) { should match(%r{\/winter:\{\}}) }
end

# docker_container[chef_container]

describe command("docker ps -af 'name=chef_container$'") do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,6 @@
its(:stdout) { should match(%r{\[\/hostbits\:\/bits \/more-hostbits\:\/more-bits\]}) }
end

describe command("docker inspect -f \"{{ .Config.Volumes }}\" bind_mounter") do
its(:exit_status) { should eq 0 }
its(:stdout) { should match(%r{\/snow:\{\}}) }
its(:stdout) { should match(%r{\/winter:\{\}}) }
end

# docker_container[chef_container]

describe command("docker ps -af 'name=chef_container$'") do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,6 @@
its(:stdout) { should match(%r{\[\/hostbits\:\/bits \/more-hostbits\:\/more-bits\]}) }
end

describe command("docker inspect -f \"{{ .Config.Volumes }}\" bind_mounter") do
its(:exit_status) { should eq 0 }
its(:stdout) { should match(%r{\/snow:\{\}}) }
its(:stdout) { should match(%r{\/winter:\{\}}) }
end

# docker_container[chef_container]

describe command("docker ps -af 'name=chef_container$'") do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,6 @@
its(:stdout) { should match(%r{\[\/hostbits\:\/bits \/more-hostbits\:\/more-bits\]}) }
end

describe command("docker inspect -f \"{{ .Config.Volumes }}\" bind_mounter") do
its(:exit_status) { should eq 0 }
its(:stdout) { should match(%r{\/snow:\{\}}) }
its(:stdout) { should match(%r{\/winter:\{\}}) }
end

# docker_container[chef_container]

describe command("docker ps -af 'name=chef_container$'") do
Expand Down

0 comments on commit 7725588

Please sign in to comment.