Skip to content

Commit fb5d594

Browse files
mihaibuzgauflorindragos
authored andcommitted
add private registry support for docker on Windows
1 parent 690bd52 commit fb5d594

File tree

2 files changed

+66
-21
lines changed

2 files changed

+66
-21
lines changed

manifests/registry.pp

+56-21
Original file line numberDiff line numberDiff line change
@@ -47,55 +47,90 @@
4747

4848
$docker_command = $docker::params::docker_command
4949

50+
if $::osfamily == 'windows' {
51+
$exec_environment = ['PATH=C:/Program Files/Docker/']
52+
$exec_timeout = 3000
53+
$exec_path = ['c:/Windows/Temp/', 'C:/Program Files/Docker/']
54+
$exec_provider = 'powershell'
55+
$password_env = '$env:password'
56+
} else {
57+
$exec_environment = ['HOME=/root']
58+
$exec_path = ['/bin', '/usr/bin']
59+
$exec_timeout = 0
60+
$exec_provider = undef
61+
$password_env = "\${password}"
62+
}
63+
5064
if $ensure == 'present' {
5165
if $username != undef and $password != undef and $email != undef and $version != undef and $version =~ /1[.][1-9]0?/ {
52-
$auth_cmd = "${docker_command} login -u '${username}' -p \"\${password}\" -e '${email}' ${server}"
66+
$auth_cmd = "${docker_command} login -u '${username}' -p '${password_env}' -e '${email}' ${server}"
5367
$auth_environment = "password=${password}"
5468
}
5569
elsif $username != undef and $password != undef {
56-
$auth_cmd = "${docker_command} login -u '${username}' -p \"\${password}\" ${server}"
70+
$auth_cmd = "${docker_command} login -u '${username}' -p ${password_env} ${server}"
5771
$auth_environment = "password=${password}"
5872
}
5973
else {
6074
$auth_cmd = "${docker_command} login ${server}"
61-
$auth_environment = undef
75+
$auth_environment = ''
6276
}
6377
}
6478
else {
6579
$auth_cmd = "${docker_command} logout ${server}"
66-
$auth_environment = undef
80+
$auth_environment = ''
6781
}
6882

6983
if $receipt {
70-
# no - with pw_hash
71-
$local_user_strip = regsubst($local_user, '-', '', 'G')
72-
73-
$_pass_hash = $pass_hash ? {
74-
Undef => pw_hash("${title}${auth_environment}${auth_cmd}${local_user}", 'SHA-512', $local_user_strip),
75-
default => $pass_hash
76-
}
7784

7885
# server may be an URI, which can contain /
7986
$server_strip = regsubst($server, '/', '_', 'G')
80-
$_auth_command = "${auth_cmd} || rm -f \"/root/registry-auth-puppet_receipt_${server_strip}_${local_user}\""
8187

82-
file { "/root/registry-auth-puppet_receipt_${server_strip}_${local_user}":
83-
ensure => $ensure,
84-
content => $_pass_hash,
85-
notify => Exec["${title} auth"],
88+
if $::osfamily != 'windows' {
89+
# no - with pw_hash
90+
$local_user_strip = regsubst($local_user, '-', '', 'G')
91+
92+
$_pass_hash = $pass_hash ? {
93+
Undef => pw_hash("${title}${auth_environment}${auth_cmd}${local_user}", 'SHA-512', $local_user_strip),
94+
default => $pass_hash
95+
}
96+
$_auth_command = "${auth_cmd} || rm -f \"/root/registry-auth-puppet_receipt_${server_strip}_${local_user}\""
97+
98+
file { "/root/registry-auth-puppet_receipt_${server_strip}_${local_user}":
99+
ensure => $ensure,
100+
content => $_pass_hash,
101+
notify => Exec["${title} auth"],
102+
}
103+
} else {
104+
$pass = "${title}${auth_environment}${auth_cmd}${local_user}"
105+
$_auth_command = $auth_cmd
106+
$pw_hash_path = 'C:/Windows/Temp/compute_hash.ps1'
107+
$passfile = "C:/Windows/Temp/registry-auth-puppet_receipt_${server_strip}_${local_user}"
108+
file{ $pw_hash_path:
109+
ensure => present,
110+
force => true,
111+
content => template('docker/windows/compute_hash.ps1.erb'),
112+
notify => Exec['compute-hash']
113+
}
114+
exec { 'compute-hash':
115+
command => "& ${pw_hash_path}",
116+
provider => $exec_provider,
117+
refreshonly => true,
118+
logoutput => true,
119+
notify => Exec["${title} auth"],
120+
}
86121
}
87122
}
88123
else {
89124
$_auth_command = $auth_cmd
90125
}
91126

92127
exec { "${title} auth":
93-
environment => $auth_environment,
128+
environment => concat($exec_environment, $auth_environment),
94129
command => $_auth_command,
95-
user => $local_user,
96-
cwd => '/root',
97-
path => ['/bin', '/usr/bin'],
98-
timeout => 0,
130+
#user => $local_user,
131+
path => $exec_path,
132+
timeout => $exec_timeout,
133+
provider => $exec_provider,
99134
refreshonly => $receipt,
100135
}
101136

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#file computes the 512SHA for a given string and writes it to a file
2+
3+
$String = "<%= @pass %>"
4+
$HashName = "SHA512"
5+
$StringBuilder = New-Object System.Text.StringBuilder
6+
[System.Security.Cryptography.HashAlgorithm]::Create($HashName).ComputeHash([System.Text.Encoding]::UTF8.GetBytes($String))|%{
7+
[Void]$StringBuilder.Append($_.ToString("x2"))
8+
}
9+
10+
$StringBuilder.ToString() | Out-File <%= @passfile %>

0 commit comments

Comments
 (0)