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

Add a receipt so auth_cmd exec only runs when parameters change. #726

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 => '[email protected]',
receipt => true,
}
```

You can logout of a registry if it is no longer required.

```puppet
Expand Down
32 changes: 25 additions & 7 deletions manifests/registry.pp
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,27 @@
# [*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

validate_re($ensure, '^(present|absent)$')
validate_bool($receipt)

$docker_command = $docker::params::docker_command

Expand All @@ -60,13 +68,23 @@
$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,
user => $local_user,
cwd => '/root',
path => ['/bin', '/usr/bin'],
timeout => 0,
refreshonly => $receipt,
}

}