Skip to content

Commit 164d2c2

Browse files
committed
Fix windows default paths
1 parent 30194fa commit 164d2c2

18 files changed

+117
-89
lines changed

Diff for: lib/facter/docker.rb

+21
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,24 @@ def interfaces
6767
end
6868
end
6969
end
70+
71+
Facter.add(:systemroot) do
72+
confine :osfamily => :windows
73+
setcode do
74+
ENV['SystemRoot']
75+
end
76+
end
77+
78+
Facter.add(:program_files_path) do
79+
confine :osfamily => :windows
80+
setcode do
81+
ENV['ProgramFiles']
82+
end
83+
end
84+
85+
Facter.add(:program_data_path) do
86+
confine :osfamily => :windows
87+
setcode do
88+
ENV['ProgramData']
89+
end
90+
end

Diff for: manifests/compose.pp

+19-21
Original file line numberDiff line numberDiff line change
@@ -55,26 +55,24 @@
5555
$docker_download_command = "if (Invoke-WebRequest ${docker_compose_url} ${proxy_opt} -UseBasicParsing -OutFile \"${docker_compose_location_versioned}\") { exit 0 } else { exit 1}"
5656

5757
exec { 'Enable TLS 1.2 in powershell':
58-
path => ['c:/Windows/Temp/', 'C:/Program Files/Docker/'],
58+
path => ["${::systemroot}/Temp/", "${::program_files_path}/Docker/"],
5959
command => '[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12',
6060
provider => powershell,
6161
creates => $docker_compose_location_versioned,
6262
}
6363

64-
$script_path = 'C:/Windows/Temp/download_docker_compose.ps1'
65-
file{ $script_path:
66-
ensure => present,
67-
force => true,
68-
content => template('docker/windows/download_docker_compose.ps1.erb'),
69-
notify => Exec["Install Docker Compose ${version}"],
70-
}
71-
7264
exec { "Install Docker Compose ${version}":
73-
path => ['c:/Windows/Temp/', 'C:/Program Files/Docker/'],
74-
command => "& ${script_path}",
65+
path => ["${::systemroot}/Temp/", "${::program_files_path}/Docker/"],
66+
command => template('docker/windows/download_docker_compose.ps1.erb'),
7567
provider => powershell,
7668
creates => $docker_compose_location_versioned,
7769
}
70+
71+
file { $docker_compose_location:
72+
ensure => 'link',
73+
target => $docker_compose_location_versioned,
74+
require => Exec["Install Docker Compose ${version}"]
75+
}
7876
} else {
7977
ensure_packages(['curl'])
8078
exec { "Install Docker Compose ${version}":
@@ -84,18 +82,18 @@
8482
creates => $docker_compose_location_versioned,
8583
require => Package['curl'],
8684
}
87-
}
8885

89-
file { $docker_compose_location_versioned:
90-
owner => $file_owner,
91-
mode => '0755',
92-
require => Exec["Install Docker Compose ${version}"]
93-
}
86+
file { $docker_compose_location_versioned:
87+
owner => $file_owner,
88+
mode => '0755',
89+
require => Exec["Install Docker Compose ${version}"]
90+
}
9491

95-
file { $docker_compose_location:
96-
ensure => 'link',
97-
target => $docker_compose_location_versioned,
98-
require => File[$docker_compose_location_versioned]
92+
file { $docker_compose_location:
93+
ensure => 'link',
94+
target => $docker_compose_location_versioned,
95+
require => File[$docker_compose_location_versioned]
96+
}
9997
}
10098
} else {
10199
file { [

Diff for: manifests/exec.pp

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
$docker_command = $docker::params::docker_command
2020

2121
if $::osfamily == 'windows' {
22-
$exec_environment = 'PATH=C:/Program Files/Docker/'
22+
$exec_environment = "PATH=${::program_files_path}/Docker/"
2323
$exec_timeout = 3000
24-
$exec_path = ['c:/Windows/Temp/', 'C:/Program Files/Docker/']
24+
$exec_path = ["${::systemroot}/Temp/", "${::program_files_path}/Docker/"]
2525
$exec_provider = 'powershell'
2626
} else {
2727
$exec_environment = 'HOME=/root'

Diff for: manifests/image.pp

+5-5
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@
3838

3939
if $::osfamily == 'windows' {
4040
$update_docker_image_template = 'docker/windows/update_docker_image.ps1.erb'
41-
$update_docker_image_path = 'C:/Windows/Temp/update_docker_image.ps1'
42-
$exec_environment = 'PATH=C:/Program Files/Docker/'
41+
$update_docker_image_path = "${::systemroot}/Temp/update_docker_image.ps1"
42+
$exec_environment = "PATH=${::program_files_path}/Docker/"
4343
$exec_timeout = 3000
4444
$update_docker_image_owner = undef
45-
$exec_path = ['c:/Windows/Temp/', 'C:/Program Files/Docker/']
45+
$exec_path = ["${::systemroot}/Temp/", "${::program_files_path}/Docker/"]
4646
$exec_provider = 'powershell'
4747
} else {
4848
$update_docker_image_template = 'docker/update_docker_image.sh.erb'
@@ -117,15 +117,15 @@
117117
$image_install = "${docker_command} build -t ${image_arg} ${docker_dir}"
118118
} elsif $docker_file {
119119
if $::osfamily == windows {
120-
$image_install = "Get-Content ${docker_file} | ${docker_command} build -t ${image_arg} -"
120+
$image_install = "Get-Content ${docker_file} -Raw | ${docker_command} build -t ${image_arg} -"
121121
} else {
122122
$image_install = "${docker_command} build -t ${image_arg} - < ${docker_file}"
123123
}
124124
} elsif $docker_tar {
125125
$image_install = "${docker_command} load -i ${docker_tar}"
126126
} else {
127127
if $::osfamily == 'windows' {
128-
$image_install = "& ${update_docker_image_path} ${image_arg}"
128+
$image_install = "& ${update_docker_image_path} -DockerImage ${image_arg}"
129129
} else {
130130
$image_install = "${update_docker_image_path} ${image_arg}"
131131
}

Diff for: manifests/params.pp

+5-5
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
$tls_enable = false
2626
$tls_verify = true
2727
if ($::osfamily == 'windows') {
28-
$tls_cacert = 'C:/ProgramData/docker/certs.d/ca.pem'
29-
$tls_cert = 'C:/ProgramData/docker/certs.d/server-cert.pem'
30-
$tls_key = 'C:/ProgramData/docker/certs.d/server-key.pem'
28+
$tls_cacert = "${::program_data_path}/docker/certs.d/ca.pem"
29+
$tls_cert = "${::program_data_path}/docker/certs.d/server-cert.pem"
30+
$tls_key = "${::program_data_path}/docker/certs.d/server-key.pem"
3131
$compose_version = '1.21.2'
32-
$compose_install_path = 'C:/Program Files/Docker'
32+
$compose_install_path = "${::program_files_path}/Docker"
3333
} else {
3434
$tls_cacert = '/etc/docker/tls/ca.pem'
3535
$tls_cert = '/etc/docker/tls/cert.pem'
@@ -224,7 +224,7 @@
224224
$msft_provider_version = $docker_msft_provider_version
225225
$msft_package_version = $version
226226
$service_config_template = 'docker/windows/config/daemon.json.erb'
227-
$service_config = 'C:/ProgramData/docker/config/daemon.json'
227+
$service_config = "${::program_data_path}/docker/config/daemon.json"
228228
$docker_group = 'docker'
229229
$package_ce_source_location = undef
230230
$package_ce_key_source = undef

Diff for: manifests/plugin.pp

+4
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@
6464

6565
$docker_command = "${docker::params::docker_command} plugin"
6666

67+
if ($::osfamily == 'windows') {
68+
fail(translate(('Feature not implemented on windows.')))
69+
}
70+
6771
if $ensure == 'present' {
6872
$docker_plugin_install_flags = docker_plugin_install_flags({
6973
plugin_name => $plugin_name,

Diff for: manifests/registry.pp

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@
4848
$docker_command = $docker::params::docker_command
4949

5050
if $::osfamily == 'windows' {
51-
$exec_environment = ['PATH=C:/Program Files/Docker/']
51+
$exec_environment = ["PATH=${::program_files_path}/Docker/"]
5252
$exec_timeout = 3000
53-
$exec_path = ['c:/Windows/Temp/', 'C:/Program Files/Docker/']
53+
$exec_path = ["${::systemroot}/Temp/", "${::program_files_path}/Docker/"]
5454
$exec_provider = 'powershell'
5555
$password_env = '$env:password'
5656
$exec_user = undef
@@ -113,7 +113,7 @@
113113
} else {
114114
# server may be an URI, which can contain /
115115
$server_strip = regsubst($server, '[/:]', '_', 'G')
116-
$passfile = "C:/Windows/Temp/registry-auth-puppet_receipt_${server_strip}_${local_user}"
116+
$passfile = "${::systemroot}/Temp/registry-auth-puppet_receipt_${server_strip}_${local_user}"
117117
$_auth_command = "if (-not (${auth_cmd})) { Remove-Item -Path ${passfile} -Force -Recurse -EA SilentlyContinue; exit 0 } else { exit 0 }"
118118

119119
if $ensure == 'absent' {

Diff for: manifests/run.pp

+3-3
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,11 @@
218218
}
219219

220220
if $::osfamily == 'windows' {
221-
$exec_environment = 'PATH=C:/Program Files/Docker/;C:/Windows/System32/'
221+
$exec_environment = "PATH=${::program_files_path}/Docker/;${::systemroot}/System32/"
222222
$exec_timeout = 3000
223-
$exec_path = ['c:/Windows/Temp/', 'C:/Program Files/Docker/']
223+
$exec_path = ["${::systemroot}/Temp/", "${::program_files_path}/Docker/"]
224224
$exec_provider = 'powershell'
225-
$cidfile = "c:/Windows/Temp/${service_prefix}${sanitised_title}.cid"
225+
$cidfile = "${::systemroot}/Temp/${service_prefix}${sanitised_title}.cid"
226226
$restart_check = "${docker_command} inspect ${sanitised_title} -f '{{ if eq \\\"unhealthy\\\" .State.Health.Status }} {{ .Name }}{{ end }}' | findstr ${sanitised_title}"
227227
} else {
228228
$exec_environment = 'HOME=/root'

Diff for: manifests/service.pp

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@
152152
}
153153
}
154154
if $::osfamily == 'windows' {
155-
file { ['C:/ProgramData/docker/', 'C:/ProgramData/docker/config/']:
155+
file { ["${::program_data_path}/docker/", "${::program_data_path}/docker/config/"]:
156156
ensure => directory,
157157
}
158158
}

Diff for: manifests/services.pp

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@
106106
}
107107

108108
if $::osfamily == 'windows' {
109-
$exec_environment = 'PATH=C:/Program Files/Docker/'
109+
$exec_environment = "PATH=${::program_files_path}/Docker/"
110110
$exec_timeout = 3000
111-
$exec_path = ['c:/Windows/Temp/', 'C:/Program Files/Docker/']
111+
$exec_path = ["${::systemroot}/Temp/", "${::program_files_path}/Docker/"]
112112
$exec_provider = 'powershell'
113113
} else {
114114
$exec_environment = 'HOME=/root'

Diff for: manifests/swarm.pp

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@
9191
include docker::params
9292

9393
if $::osfamily == 'windows' {
94-
$exec_environment = 'PATH=C:/Program Files/Docker/'
95-
$exec_path = ['c:/Windows/Temp/', 'C:/Program Files/Docker/']
94+
$exec_environment = "PATH=${::program_files_path}/Docker/"
95+
$exec_path = ["${::systemroot}/Temp/", "${::program_files_path}/Docker/"]
9696
$exec_timeout = 3000
9797
$exec_provider = 'powershell'
9898
$unless_init = '$info = docker info | select-string -pattern "Swarm: active"

Diff for: spec/classes/compose_winsows_spec.rb renamed to spec/classes/compose_windows_spec.rb

+10-23
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
:kernelrelease => '10.0.14393',
1111
:operatingsystemrelease => '2016',
1212
:operatingsystemmajrelease => '2016',
13+
:program_data_path => 'C:/ProgramData',
14+
:program_files_path => 'C:/Program Files',
15+
:systemroot => 'C:/Windows',
1316
:os => { :family => 'windows', :name => 'windows', :release => { :major => '2016', :full => '2016' } }
1417
}
1518
end
@@ -19,20 +22,15 @@
1922
context 'with defaults for all parameters' do
2023
it { should compile.with_all_deps }
2124
it { should contain_exec('Install Docker Compose 1.21.2').with(
22-
'path' => ['c:/Windows/Temp/', 'C:/Program Files/Docker/'],
23-
'command' => '& C:/Windows/Temp/download_docker_compose.ps1',
25+
'path' => ['C:/Windows/Temp/', 'C:/Program Files/Docker/'],
2426
'provider' => 'powershell',
2527
'creates' => 'C:/Program Files/Docker/docker-compose-1.21.2.exe'
2628
)}
27-
it { should contain_file('C:/Program Files/Docker/docker-compose-1.21.2.exe').with(
28-
'owner' => 'Administrator',
29-
'mode' => '0755',
30-
'require' => 'Exec[Install Docker Compose 1.21.2]'
31-
)}
29+
3230
it { should contain_file('C:/Program Files/Docker/docker-compose.exe').with(
3331
'ensure' => 'link',
3432
'target' => 'C:/Program Files/Docker/docker-compose-1.21.2.exe',
35-
'require' => 'File[C:/Program Files/Docker/docker-compose-1.21.2.exe]'
33+
'require' => 'Exec[Install Docker Compose 1.21.2]'
3634
)}
3735
end
3836

@@ -44,19 +42,14 @@
4442

4543
context 'when no proxy is provided' do
4644
let(:params) { {:version => '1.7.0'} }
47-
it { is_expected.to contain_exec('Install Docker Compose 1.7.0').with_command(
48-
'& C:/Windows/Temp/download_docker_compose.ps1')
49-
}
45+
it { is_expected.to contain_exec('Install Docker Compose 1.7.0') }
5046
end
5147

5248
context 'when proxy is provided' do
5349
let(:params) { {:proxy => 'http://proxy.example.org:3128/',
5450
:version => '1.7.0'} }
5551
it { is_expected.to compile }
56-
it { is_expected.to contain_exec('Install Docker Compose 1.7.0').with_command(
57-
'& C:/Windows/Temp/download_docker_compose.ps1')
58-
}
59-
it { should contain_file('C:/Windows/Temp/download_docker_compose.ps1').with_content(/WebProxy/) }
52+
it { is_expected.to contain_exec('Install Docker Compose 1.7.0') }
6053
end
6154

6255
context 'when proxy is not a http proxy' do
@@ -72,19 +65,13 @@
7265
let(:params) { {:proxy => 'http://user:[email protected]:3128/',
7366
:version => '1.7.0'} }
7467
it { is_expected.to compile }
75-
it { is_expected.to contain_exec('Install Docker Compose 1.7.0').with_command(
76-
'& C:/Windows/Temp/download_docker_compose.ps1')
77-
}
78-
it { should contain_file('C:/Windows/Temp/download_docker_compose.ps1').with_content(/Credentials/) }
68+
it { is_expected.to contain_exec('Install Docker Compose 1.7.0') }
7969
end
8070

8171
context 'when proxy IP is provided' do
8272
let(:params) { {:proxy => 'http://10.10.10.10:3128/',
8373
:version => '1.7.0'} }
8474
it { is_expected.to compile }
85-
it { is_expected.to contain_exec('Install Docker Compose 1.7.0').with_command(
86-
'& C:/Windows/Temp/download_docker_compose.ps1')
87-
}
88-
it { should contain_file('C:/Windows/Temp/download_docker_compose.ps1').with_content(/10.10.10.10:3128/) }
75+
it { is_expected.to contain_exec('Install Docker Compose 1.7.0') }
8976
end
9077
end

Diff for: spec/classes/docker_windows_spec.rb

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
:kernelrelease => '10.0.14393',
1111
:operatingsystemrelease => '2016',
1212
:operatingsystemmajrelease => '2016',
13+
:program_data_path => 'C:/ProgramData',
14+
:program_files_path => 'C:/Program Files',
15+
:systemroot => 'C:/Windows',
1316
:os => { :family => 'windows', :name => 'windows', :release => { :major => '2016', :full => '2016' } }
1417
} }
1518
service_config_file = 'C:/ProgramData/docker/config/daemon.json'

Diff for: spec/defines/exec_windows_spec.rb

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
:kernelrelease => '10.0.14393',
1010
:operatingsystemrelease => '2016',
1111
:operatingsystemmajrelease => '2016',
12+
:program_data_path => 'C:/ProgramData',
13+
:program_files_path => 'C:/Program Files',
14+
:systemroot => 'C:/Windows',
1215
:os => { :family => 'windows', :name => 'windows', :release => { :major => '2016', :full => '2016' } }
1316
} }
1417

Diff for: spec/defines/image_windows_spec.rb

+10-7
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,45 @@
99
:kernelrelease => '10.0.14393',
1010
:operatingsystemrelease => '2016',
1111
:operatingsystemmajrelease => '2016',
12+
:program_data_path => 'C:/ProgramData',
13+
:program_files_path => 'C:/Program Files',
14+
:systemroot => 'C:/Windows',
1215
:os => { :family => 'windows', :name => 'windows', :release => { :major => '2016', :full => '2016' } }
1316
} }
1417
context 'with ensure => present' do
1518
let(:params) { { 'ensure' => 'present' } }
1619
it { should contain_file('C:/Windows/Temp/update_docker_image.ps1') }
17-
it { should contain_exec('& C:/Windows/Temp/update_docker_image.ps1 base') }
20+
it { should contain_exec('& C:/Windows/Temp/update_docker_image.ps1 -DockerImage base') }
1821
end
1922

2023
context 'with docker_file => Dockerfile' do
2124
let(:params) { { 'docker_file' => 'Dockerfile' }}
22-
it { should contain_exec('Get-Content Dockerfile | docker build -t base -') }
25+
it { should contain_exec('Get-Content Dockerfile -Raw | docker build -t base -') }
2326
end
2427

2528
context 'with ensure => present and docker_file => Dockerfile' do
2629
let(:params) { { 'ensure' => 'present', 'docker_file' => 'Dockerfile' } }
27-
it { should contain_exec('Get-Content Dockerfile | docker build -t base -') }
30+
it { should contain_exec('Get-Content Dockerfile -Raw | docker build -t base -') }
2831
end
2932

3033
context 'with ensure => present and image_tag => nanoserver' do
3134
let(:params) { { 'ensure' => 'present', 'image_tag' => 'nanoserver' } }
32-
it { should contain_exec('& C:/Windows/Temp/update_docker_image.ps1 base:nanoserver') }
35+
it { should contain_exec('& C:/Windows/Temp/update_docker_image.ps1 -DockerImage base:nanoserver') }
3336
end
3437

3538
context 'with ensure => present and image_digest => sha256:deadbeef' do
3639
let(:params) { { 'ensure' => 'present', 'image_digest' => 'sha256:deadbeef' } }
37-
it { should contain_exec('& C:/Windows/Temp/update_docker_image.ps1 base@sha256:deadbeef') }
40+
it { should contain_exec('& C:/Windows/Temp/update_docker_image.ps1 -DockerImage base@sha256:deadbeef') }
3841
end
3942

4043
context 'with ensure => present and image_tag => nanoserver and docker_file => Dockerfile' do
4144
let(:params) { { 'ensure' => 'present', 'image_tag' => 'nanoserver', 'docker_file' => 'Dockerfile' } }
42-
it { should contain_exec('Get-Content Dockerfile | docker build -t base:nanoserver -') }
45+
it { should contain_exec('Get-Content Dockerfile -Raw | docker build -t base:nanoserver -') }
4346
end
4447

4548
context 'with ensure => latest' do
4649
let(:params) { { 'ensure' => 'latest' } }
47-
it { should contain_exec("& C:/Windows/Temp/update_docker_image.ps1 base") }
50+
it { should contain_exec("& C:/Windows/Temp/update_docker_image.ps1 -DockerImage base") }
4851
end
4952

5053
end

0 commit comments

Comments
 (0)