diff --git a/README.md b/README.md index 2ba750e1d..e8588e019 100755 --- a/README.md +++ b/README.md @@ -559,6 +559,20 @@ docker::registry { 'example.docker.io:5000': } ``` +By default the exec to add registries will run on every Puppet run. To prevent this you can enable the use of a receipt. +Caveat: If the values in config.json for this registry are modified outside of Puppet, puppet will not correct them unless the receipt file is removed from /root/.docker/ + +Default: receipt => false + +```puppet +docker::registry { 'example.docker.io:5000': + username => 'user', + password => 'secret', + email => 'user@example.com', + receipt => true, +} +``` + You can logout of a registry if it is no longer required. ```puppet diff --git a/manifests/registry.pp b/manifests/registry.pp index d85c6138f..055f8689b 100644 --- a/manifests/registry.pp +++ b/manifests/registry.pp @@ -25,15 +25,22 @@ # [*local_user*] # The local user to log in as. Docker will store credentials in this # users home directory -# +# +# [*receipt*] +# Creates a receipt file for this specific registry preventing the exec +# modifing config.json from triggering every puppet run. +# Caveat: if you modify the entry for this registry in +# /root/.docker/config.json outside of puppet the exec won't trigger +# again unless the receipt is removed. # define docker::registry( - $server = $title, - $ensure = 'present', - $username = undef, - $password = undef, - $email = undef, - $local_user = 'root', + $server = $title, + $ensure = 'present', + $username = undef, + $password = undef, + $email = undef, + $local_user = 'root', + $receipt = false, ) { include docker::params @@ -60,6 +67,15 @@ $auth_environment = undef } + # Using Receipt? + if $receipt { + file { "/root/.docker/registry-auth-puppet_receipt_${title}": + ensure => $ensure, + content => pw_hash("${title}${auth_environment}${auth_cmd}${local_user}", 'SHA-512', $local_user), + notify => Exec["${title} auth"], + } + } + exec { "${title} auth": environment => $auth_environment, command => $auth_cmd, @@ -67,6 +83,7 @@ cwd => '/root', path => ['/bin', '/usr/bin'], timeout => 0, + refreshonly => $receipt, } }