Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple mirrors #659 #669

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ Default value: `$docker::params::tmp_dir`

##### `registry_mirror`

Data type: `Optional[String]`
Data type: `Optional[Variant[String,Array]]`

Sets the prefered container registry mirror.

Expand Down
10 changes: 8 additions & 2 deletions lib/puppet/parser/functions/docker_service_flags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,14 @@ module Puppet::Parser::Functions
flags << "-H '#{opts['host_socket']}'"
end

if opts['registry_mirror'] && opts['registry_mirror'].to_s != 'undef'
flags << "--registry-mirror='#{opts['registry_mirror']}'"
if opts['registry_mirror'].is_a? Array
opts['registry_mirror'].each do |param|
flags << "--registry-mirror='#{param}'"
end
else
if opts['registry_mirror'] && opts['registry_mirror'].to_s != 'undef'
flags << "--registry-mirror='#{opts['registry_mirror']}'"
end
end

if opts['image'] && opts['image'].to_s != 'undef'
Expand Down
2 changes: 1 addition & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@
Optional[Variant[String,Boolean]] $service_after_override = $docker::params::service_after_override,
Optional[Boolean] $service_hasstatus = $docker::params::service_hasstatus,
Optional[Boolean] $service_hasrestart = $docker::params::service_hasrestart,
Optional[String] $registry_mirror = $docker::params::registry_mirror,
Optional[Variant[String,Array]] $registry_mirror = $docker::params::registry_mirror,
Boolean $acknowledge_unsupported_os = false,

# Windows specific parameters
Expand Down
21 changes: 21 additions & 0 deletions spec/acceptance/docker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,27 @@ class { 'docker':
end
end

context 'When registry_mirror is array', win_broken: broken do
let(:pp) do
"
class { 'docker':
registry_mirror => ['http://testmirror1.io', 'http://testmirror2.io']
}
"
end

it 'applies with no errors' do
apply_manifest(pp, catch_failures: true)
end

it 'has all registry mirrors set' do
run_shell('ps -aux | grep docker') do |r|
expect(r.stdout).to match(%r{--registry-mirror=http:\/\/testmirror1.io})
expect(r.stdout).to match(%r{--registry-mirror=http:\/\/testmirror2.io})
end
end
end

context 'registry' do
let(:registry_address) do
"#{registry_host}:#{registry_port}"
Expand Down
10 changes: 8 additions & 2 deletions spec/helper/get_docker_service_flags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,14 @@ def get_docker_service_flags(args)
flags << "-H '#{args['host_socket']}'"
end

if args['registry_mirror'] && args['registry_mirror'].to_s != 'undef'
flags << "--registry-mirror='#{args['registry_mirror']}'"
if args['registry_mirror'].is_a? Array
args['registry_mirror'].each do |param|
flags << "--registry-mirror='#{param}'"
end
else
if args['registry_mirror'] && args['registry_mirror'].to_s != 'undef'
flags << "--registry-mirror='#{args['registry_mirror']}'"
end
end

if args['image'] && args['image'].to_s != 'undef'
Expand Down
3 changes: 2 additions & 1 deletion templates/etc/default/docker.erb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ DOCKER_OPTS="\
<% if @execdriver %> -e <%= @execdriver %> <% end -%>
<% if @bip %> --bip=<%= @bip %> <% end -%>
<% if @mtu %> --mtu=<%= @mtu %> <% end -%>
<% if @registry_mirror %> --registry-mirror=<%= @registry_mirror %><% end -%>
<% if @registry_mirror.is_a? String %> --registry-mirror=<%= @registry_mirror %><% end -%>
<% if @registry_mirror.is_a? Array %><% @registry_mirror.each do |param| %> --registry-mirror=<%= param %><% end %><% end -%>
<% if @storage_driver %> --storage-driver=<%= @storage_driver %><% end -%>
<% if @storage_driver == 'devicemapper' -%>
<%- if @dm_basesize %> --storage-opt dm.basesize=<%= @dm_basesize %><% end -%>
Expand Down
3 changes: 2 additions & 1 deletion templates/etc/sysconfig/docker.systemd.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ OPTIONS="<% if @root_dir %><%= @root_dir_flag %> <%= @root_dir %><% end -%>
--iptables=<%= @iptables -%>
--ip-masq=<%= @ip_masq -%>
<% unless @icc == nil %> --icc=<%= @icc %><% end -%>
<% if @registry_mirror %> --registry-mirror=<%= @registry_mirror %><% end -%>
<% if @registry_mirror.is_a? String %> --registry-mirror=<%= @registry_mirror %><% end -%>
<% if @registry_mirror.is_a? Array %><% @registry_mirror.each do |param| %> --registry-mirror=<%= param %><% end %><% end -%>
<% if @fixed_cidr %> --fixed-cidr <%= @fixed_cidr %><% end -%>
<% if @default_gateway %> --default-gateway <%= @default_gateway %><% end -%>
<% if @ipv6 %> --ipv6<% end -%>
Expand Down
5 changes: 3 additions & 2 deletions templates/windows/config/daemon.json.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
<% if @socket_group %>"group": "<%= @socket_group %>",<% end -%>
<% if @bridge %>"bridge": "<%= @bridge %>",<% end -%>
<% if @fixed_cidr %>"fixed-cidr": "<%= @fixed_cidr %>",<% end -%>
<% if @registry_mirror %>"registry-mirrors": ["<%= @registry_mirror%>"], <% end -%>
<% if @registry_mirror.is_a? String %>"registry-mirrors": ["<%= @registry_mirror %>"], <% end -%>
<% if @registry_mirror.is_a? Array %>"registry-mirrors": ["<%= @registry_mirror.join('", "') %>"], <% end -%>
<% if @extra_parameters %><% @extra_parameters_array.each do |param| %>
<%= param %> ,<% end %>
<% end -%>
<% if @root_dir %>"data-root": "<%= @root_dir %>",<% end -%>
"labels": <%= @labels_array.to_json %>
}
}