Skip to content

Commit

Permalink
Use dns* attributes to set docker daemon options, not defaults per-co…
Browse files Browse the repository at this point in the history
…ntainer, closes #125
  • Loading branch information
bflad committed Apr 12, 2014
1 parent 715bfe7 commit 6978b83
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ Attribute deprecations so you can be sure you can upgrade:

Attributes now available for all docker daemon flags as well as system IP forwarding.

* REMOVED: container_dns* attributes (use replacement dns* attributes on daemon for all containers or docker_container dns* attributes instead)
* Enhancement: [#115][]: Add IP forwarding attributes
* Enhancement: [#125][]: Use dns* attributes to set docker daemon options, not defaults per-container
* Enhancement: [#128][]: Add checksum attribute for binary downloads
* Enhancement: [#126][]: Set long option names for specified docker daemon options
* Enhancement: [#127][]: Use a helper function to specify single line docker daemon options
Expand Down Expand Up @@ -441,6 +443,7 @@ Lots of community contributions this release -- thanks!
[#112]: https://github.com/bflad/chef-docker/issues/112
[#113]: https://github.com/bflad/chef-docker/issues/113
[#115]: https://github.com/bflad/chef-docker/issues/115
[#125]: https://github.com/bflad/chef-docker/issues/125
[#126]: https://github.com/bflad/chef-docker/issues/126
[#127]: https://github.com/bflad/chef-docker/issues/127
[#128]: https://github.com/bflad/chef-docker/issues/128
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ Attribute | Description | Type | Default
----------|-------------|------|--------
bind_socket | Socket path that docker should bind | String | unix:///var/run/docker.sock
bind_uri | TCP URI docker should bind | String | nil
dns | DNS server(s) for containers | String, Array | nil
dns_search | DNS search domain(s) for containers | String, Array | nil
exec_driver | Execution driver for docker | String | nil (implicitly native as of 0.9.0)
group | Group for docker socket and group_members | String | nil (implicitly docker)
http_proxy | HTTP_PROXY environment variable | String | nil
Expand All @@ -150,8 +152,6 @@ These attributes are under the `node['docker']` namespace.
Attribute | Description | Type | Default
----------|-------------|------|--------
container_cmd_timeout | container LWRP default cmd_timeout seconds | Fixnum | 60
container_dns | container LWRP default DNS server(s) | String, Array | nil
container_dns_search | container LWRP default DNS search domain(s) | String, Array | nil
container_init_type | Init type for docker containers (nil, "runit", "systemd", "sysv", or "upstart") | String | `node['docker']['init_type']`

#### docker_image Attributes
Expand Down Expand Up @@ -409,8 +409,8 @@ container_name | Name for container/service | String | nil
cookbook | Cookbook to grab any templates | String | docker
cpu_shares | CPU shares for container | Fixnum | nil
detach | Detach from container when starting | TrueClass, FalseClass | nil
dns | DNS servers for container | String, Array | `node['docker']['container_dns']`
dns_search | DNS search domains for container | String, Array | `node['docker']['container_dns_search']`
dns | DNS servers for container | String, Array | nil
dns_search | DNS search domains for container | String, Array | nil
entrypoint | Overwrite the default entrypoint set by the image | String | nil
env | Environment variables to pass to container | String, Array | nil
expose | Expose a port from the container without publishing it to your host | Fixnum, String, Array | nil
Expand Down
4 changes: 2 additions & 2 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
default['docker']['bind_socket'] = 'unix:///var/run/docker.sock'
default['docker']['bind_uri'] = nil
default['docker']['container_cmd_timeout'] = 60
default['docker']['container_dns'] = nil
default['docker']['container_dns_search'] = nil
default['docker']['dns'] = nil
default['docker']['dns_search'] = nil
default['docker']['docker_daemon_timeout'] = 10
default['docker']['exec_driver'] = nil

Expand Down
2 changes: 2 additions & 0 deletions libraries/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class CommandTimeout < RuntimeError; end

def self.daemon_cli_args(node)
daemon_options = Helpers::Docker.cli_args(
'dns' => Array(node['docker']['dns']),
'dns-search' => Array(node['docker']['dns_search']),
'exec-driver' => node['docker']['exec_driver'],
'host' => Array(node['docker']['bind_socket']) +
Array(node['docker']['bind_uri']),
Expand Down
4 changes: 2 additions & 2 deletions resources/container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
attribute :cpu_shares, :kind_of => [Fixnum]
attribute :destination, :kind_of => [String]
attribute :detach, :kind_of => [TrueClass, FalseClass]
attribute :dns, :kind_of => [String, Array], :default => node['docker']['container_dns']
attribute :dns_search, :kind_of => [String, Array], :default => node['docker']['container_dns_search']
attribute :dns, :kind_of => [String, Array]
attribute :dns_search, :kind_of => [String, Array]
attribute :entrypoint, :kind_of => [String]
attribute :env, :kind_of => [String, Array]
attribute :expose, :kind_of => [Fixnum, String, Array]
Expand Down
52 changes: 52 additions & 0 deletions spec/systemd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,58 @@
end
end

context 'when dns is set with String' do
let(:chef_run) do
runner = ChefSpec::Runner.new
runner.node.set['docker']['dns'] = '8.8.8.8'
runner.converge(described_recipe)
end

it 'adds dns flag to docker service' do
expect(chef_run).to render_file('/usr/lib/systemd/system/docker.service').with_content(
%r{^ExecStart=/usr/bin/docker -d.* --dns="8.8.8.8".*})
end
end

context 'when dns is set with Array' do
let(:chef_run) do
runner = ChefSpec::Runner.new
runner.node.set['docker']['dns'] = %w(8.8.8.8 8.8.4.4)
runner.converge(described_recipe)
end

it 'adds dns flags to docker service' do
expect(chef_run).to render_file('/usr/lib/systemd/system/docker.service').with_content(
%r{^ExecStart=/usr/bin/docker -d.* --dns="8.8.8.8" --dns="8.8.4.4".*})
end
end

context 'when dns_search is set with String' do
let(:chef_run) do
runner = ChefSpec::Runner.new
runner.node.set['docker']['dns_search'] = 'example.com'
runner.converge(described_recipe)
end

it 'adds dns-search flag to docker service' do
expect(chef_run).to render_file('/usr/lib/systemd/system/docker.service').with_content(
%r{^ExecStart=/usr/bin/docker -d.* --dns-search="example.com".*})
end
end

context 'when dns_search is set with Array' do
let(:chef_run) do
runner = ChefSpec::Runner.new
runner.node.set['docker']['dns_search'] = %w(foo.example.com bar.example.com)
runner.converge(described_recipe)
end

it 'adds dns-search flags to docker service' do
expect(chef_run).to render_file('/usr/lib/systemd/system/docker.service').with_content(
%r{^ExecStart=/usr/bin/docker -d.* --dns-search="foo.example.com" --dns-search="bar.example.com".*})
end
end

context 'when exec_driver is set' do
let(:chef_run) do
runner = ChefSpec::Runner.new
Expand Down
52 changes: 52 additions & 0 deletions spec/sysv_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,58 @@
end
end

context 'when dns is set with String' do
let(:chef_run) do
runner = ChefSpec::Runner.new
runner.node.set['docker']['dns'] = '8.8.8.8'
runner.converge(described_recipe)
end

it 'adds dns flag to docker service' do
expect(chef_run).to render_file('/etc/default/docker').with_content(
/^DOCKER_OPTS='.* --dns="8.8.8.8".*'$/)
end
end

context 'when dns is set with Array' do
let(:chef_run) do
runner = ChefSpec::Runner.new
runner.node.set['docker']['dns'] = %w(8.8.8.8 8.8.4.4)
runner.converge(described_recipe)
end

it 'adds dns flags to docker service' do
expect(chef_run).to render_file('/etc/default/docker').with_content(
/^DOCKER_OPTS='.* --dns="8.8.8.8" --dns="8.8.4.4".*'$/)
end
end

context 'when dns_search is set with String' do
let(:chef_run) do
runner = ChefSpec::Runner.new
runner.node.set['docker']['dns_search'] = 'example.com'
runner.converge(described_recipe)
end

it 'adds dns-search flag to docker service' do
expect(chef_run).to render_file('/etc/default/docker').with_content(
/^DOCKER_OPTS='.* --dns-search="example.com".*'$/)
end
end

context 'when dns_search is set with Array' do
let(:chef_run) do
runner = ChefSpec::Runner.new
runner.node.set['docker']['dns_search'] = %w(foo.example.com bar.example.com)
runner.converge(described_recipe)
end

it 'adds dns-search flags to docker service' do
expect(chef_run).to render_file('/etc/default/docker').with_content(
/^DOCKER_OPTS='.* --dns-search="foo.example.com" --dns-search="bar.example.com".*'$/)
end
end

context 'when exec_driver is set' do
let(:chef_run) do
runner = ChefSpec::Runner.new
Expand Down
52 changes: 52 additions & 0 deletions spec/upstart_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,58 @@
end
end

context 'when dns is set with String' do
let(:chef_run) do
runner = ChefSpec::Runner.new
runner.node.set['docker']['dns'] = '8.8.8.8'
runner.converge(described_recipe)
end

it 'adds dns flag to docker service' do
expect(chef_run).to render_file('/etc/default/docker').with_content(
/^DOCKER_OPTS='.* --dns="8.8.8.8".*'$/)
end
end

context 'when dns is set with Array' do
let(:chef_run) do
runner = ChefSpec::Runner.new
runner.node.set['docker']['dns'] = %w(8.8.8.8 8.8.4.4)
runner.converge(described_recipe)
end

it 'adds dns flags to docker service' do
expect(chef_run).to render_file('/etc/default/docker').with_content(
/^DOCKER_OPTS='.* --dns="8.8.8.8" --dns="8.8.4.4".*'$/)
end
end

context 'when dns_search is set with String' do
let(:chef_run) do
runner = ChefSpec::Runner.new
runner.node.set['docker']['dns_search'] = 'example.com'
runner.converge(described_recipe)
end

it 'adds dns-search flag to docker service' do
expect(chef_run).to render_file('/etc/default/docker').with_content(
/^DOCKER_OPTS='.* --dns-search="example.com".*'$/)
end
end

context 'when dns_search is set with Array' do
let(:chef_run) do
runner = ChefSpec::Runner.new
runner.node.set['docker']['dns_search'] = %w(foo.example.com bar.example.com)
runner.converge(described_recipe)
end

it 'adds dns-search flags to docker service' do
expect(chef_run).to render_file('/etc/default/docker').with_content(
/^DOCKER_OPTS='.* --dns-search="foo.example.com" --dns-search="bar.example.com".*'$/)
end
end

context 'when exec_driver is set' do
let(:chef_run) do
runner = ChefSpec::Runner.new
Expand Down

0 comments on commit 6978b83

Please sign in to comment.