diff --git a/README.md b/README.md index 6b0242aec7..ae65b3b982 100644 --- a/README.md +++ b/README.md @@ -165,6 +165,7 @@ no_proxy | NO_PROXY environment variable | String | nil options | Additional options to pass to docker. These could be flags like "-api-enable-cors". | String | nil pidfile | Path to use for daemon PID file | String | nil (implicitly /var/run/docker.pid) ramdisk | Set DOCKER_RAMDISK when using RAM disk | TrueClass or FalseClass | false +registry-mirror | List of docker registry mirrors | String, Array | nil restart | Restart containers on boot | TrueClass or FalseClass | auto-detected (see attributes/default.rb) selinux_enabled | Enable SELinux | TrueClass or FalseClass | nil storage_driver | Storage driver for docker | String | nil diff --git a/attributes/default.rb b/attributes/default.rb index 8e739c539c..736ae6a43e 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -153,6 +153,7 @@ default['docker']['options'] = nil default['docker']['pidfile'] = nil default['docker']['ramdisk'] = false +default['docker']['registry-mirror'] = nil default['docker']['selinux_enabled'] = nil default['docker']['storage_driver'] = nil default['docker']['storage_opt'] = nil diff --git a/libraries/helpers.rb b/libraries/helpers.rb index e5bf4d798c..fccc5e3230 100644 --- a/libraries/helpers.rb +++ b/libraries/helpers.rb @@ -90,6 +90,7 @@ def self.daemon_cli_args(node) 'iptables' => node['docker']['iptables'], 'mtu' => node['docker']['mtu'], 'pidfile' => node['docker']['pidfile'], + 'registry-mirror' => Array(node['docker']['registry-mirror']), 'restart' => node['docker']['restart'], 'selinux-enabled' => node['docker']['selinux_enabled'], 'storage-driver' => node['docker']['storage_driver'], diff --git a/spec/systemd_spec.rb b/spec/systemd_spec.rb index 3cad9b4c20..d3c8c96015 100644 --- a/spec/systemd_spec.rb +++ b/spec/systemd_spec.rb @@ -347,6 +347,32 @@ end end + context 'when registry-mirror is set with String' do + let(:chef_run) do + runner = ChefSpec::Runner.new + runner.node.set['docker']['registry-mirror'] = 'http://registry.example.com:1337' + runner.converge(described_recipe) + end + + it 'adds registry-mirror 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.* --registry-mirror=http://registry\.example\.com:1337.*}) + end + end + + context 'when registry-mirror is set with Array' do + let(:chef_run) do + runner = ChefSpec::Runner.new + runner.node.set['docker']['registry-mirror'] = %w(http://registry.example.com:1337 http://registry.example.com:1338) + runner.converge(described_recipe) + end + + it 'adds registry-mirror 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.* --registry-mirror=http://registry\.example\.com:1337 --registry-mirror=http://registry\.example\.com:1338.*}) + end + end + context 'when storage_driver is set' do let(:chef_run) do runner = ChefSpec::Runner.new diff --git a/spec/sysv_spec.rb b/spec/sysv_spec.rb index 3debd590b2..07da6a033a 100644 --- a/spec/sysv_spec.rb +++ b/spec/sysv_spec.rb @@ -376,6 +376,32 @@ end end + context 'when registry-mirror is set with String' do + let(:chef_run) do + runner = ChefSpec::Runner.new + runner.node.set['docker']['registry-mirror'] = 'http://registry.example.com:1337' + runner.converge(described_recipe) + end + + it 'adds registry-mirror flag to docker service' do + expect(chef_run).to render_file('/etc/default/docker').with_content( + %r{^DOCKER_OPTS='.* --registry-mirror=http://registry\.example\.com:1337.*'$}) + end + end + + context 'when registry-mirror is set with Array' do + let(:chef_run) do + runner = ChefSpec::Runner.new + runner.node.set['docker']['registry-mirror'] = %w(http://registry.example.com:1337 http://registry.example.com:1338) + runner.converge(described_recipe) + end + + it 'adds registry-mirror flags to docker service' do + expect(chef_run).to render_file('/etc/default/docker').with_content( + %r{^DOCKER_OPTS='.* --registry-mirror=http://registry\.example\.com:1337 --registry-mirror=http://registry\.example\.com:1338.*'$}) + end + end + context 'when storage_driver is set' do let(:chef_run) do runner = ChefSpec::Runner.new diff --git a/spec/upstart_spec.rb b/spec/upstart_spec.rb index ee9e460fe6..56c66e5600 100644 --- a/spec/upstart_spec.rb +++ b/spec/upstart_spec.rb @@ -377,6 +377,32 @@ end end + context 'when registry-mirror is set with String' do + let(:chef_run) do + runner = ChefSpec::Runner.new + runner.node.set['docker']['registry-mirror'] = 'http://registry.example.com:1337' + runner.converge(described_recipe) + end + + it 'adds registry-mirror flag to docker service' do + expect(chef_run).to render_file('/etc/default/docker').with_content( + %r{^DOCKER_OPTS='.* --registry-mirror=http://registry\.example\.com:1337.*'$}) + end + end + + context 'when registry-mirror is set with Array' do + let(:chef_run) do + runner = ChefSpec::Runner.new + runner.node.set['docker']['registry-mirror'] = %w(http://registry.example.com:1337 http://registry.example.com:1338) + runner.converge(described_recipe) + end + + it 'adds registry-mirror flags to docker service' do + expect(chef_run).to render_file('/etc/default/docker').with_content( + %r{^DOCKER_OPTS='.* --registry-mirror=http://registry\.example\.com:1337 --registry-mirror=http://registry\.example\.com:1338.*'$}) + end + end + context 'when storage_driver is set' do let(:chef_run) do runner = ChefSpec::Runner.new