Skip to content

Commit 204e367

Browse files
committed
Configure docker swarm on windows
1 parent bf89661 commit 204e367

File tree

3 files changed

+88
-53
lines changed

3 files changed

+88
-53
lines changed

lib/puppet/parser/functions/docker_swarm_join_flags.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module Puppet::Parser::Functions
1717
end
1818

1919
if opts['listen_addr'].to_s != 'undef'
20-
flags << "--listen-addr '#{opts['listen_addr']}'"
20+
flags << "--listen-addr \"#{opts['listen_addr']}\""
2121
end
2222

2323
if opts['token'].to_s != 'undef'

manifests/swarm.pp

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,27 @@
9090

9191
include docker::params
9292

93+
if $::osfamily == 'windows' {
94+
$exec_environment = 'PATH=C:/Program Files/Docker/'
95+
$exec_path = ['c:/Windows/Temp/', 'C:/Program Files/Docker/']
96+
$exec_timeout = 3000
97+
$exec_provider = 'powershell'
98+
$unless_init = '$info = docker info | select-string -pattern "Swarm: active"
99+
if ($info -eq $null) { Exit 1 } else { Exit 0 }'
100+
$unless_join = '$info = docker info | select-string -pattern "Swarm: active"
101+
if ($info -eq $null) { Exit 1 } else { Exit 0 }'
102+
$onlyif_leave = '$info = docker info | select-string -pattern "Swarm: active"
103+
if ($info -eq $null) { Exit 1 } else { Exit 0 }'
104+
} else {
105+
$exec_environment = 'HOME=/root'
106+
$exec_path = ['/bin', '/usr/bin']
107+
$exec_timeout = 0
108+
$exec_provider = undef
109+
$unless_init = 'docker info | grep -w "Swarm: active"'
110+
$unless_join = 'docker info | grep -w "Swarm: active"'
111+
$onlyif_leave = 'docker info | grep -w "Swarm: active"'
112+
}
113+
93114
$docker_command = "${docker::params::docker_command} swarm"
94115

95116
if $init {
@@ -107,13 +128,13 @@
107128
})
108129

109130
$exec_init = "${docker_command} ${docker_swarm_init_flags}"
110-
$unless_init = 'docker info | grep -w "Swarm: active"'
111131

112132
exec { 'Swarm init':
113133
command => $exec_init,
114-
environment => 'HOME=/root',
115-
path => ['/bin', '/usr/bin'],
116-
timeout => 0,
134+
environment => $exec_environment,
135+
path => $exec_path,
136+
provider => $exec_provider,
137+
timeout => $exec_timeout,
117138
unless => $unless_init,
118139
}
119140
}
@@ -127,22 +148,23 @@
127148
})
128149

129150
$exec_join = "${docker_command} ${docker_swarm_join_flags} ${manager_ip}"
130-
$unless_join = 'docker info | grep -w "Swarm: active"'
131151

132152
exec { 'Swarm join':
133153
command => $exec_join,
134-
environment => 'HOME=/root',
135-
path => ['/bin', '/usr/bin'],
136-
timeout => 0,
154+
environment => $exec_environment,
155+
path => $exec_path,
156+
provider => $exec_provider,
157+
timeout => $exec_timeout,
137158
unless => $unless_join,
138159
}
139160
}
140161

141162
if $ensure == 'absent' {
142163
exec { 'Leave swarm':
143-
command => 'docker swarm leave --force',
144-
onlyif => 'docker info | grep -w "Swarm: active"',
145-
path => ['/bin', '/usr/bin'],
164+
command => 'docker swarm leave --force',
165+
onlyif => $onlyif_leave,
166+
path => $exec_path,
167+
provider => $exec_provider,
146168
}
147169
}
148170
}

spec/defines/swarm_spec.rb

Lines changed: 54 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,61 @@
11
require 'spec_helper'
22

3-
describe 'docker::swarm', :type => :define do
4-
let(:title) { 'create swarm' }
5-
let(:facts) { {
6-
:osfamily => 'Debian',
7-
:operatingsystem => 'Debian',
8-
:lsbdistid => 'Debian',
9-
:lsbdistcodename => 'jessie',
10-
:kernelrelease => '3.2.0-4-amd64',
11-
:operatingsystemmajrelease => '8',
12-
} }
3+
['Debian', 'Windows'].each do |osfamily|
4+
describe 'docker::swarm', :type => :define do
5+
let(:title) { 'create swarm' }
6+
context "on #{osfamily}" do
7+
if osfamily == 'Debian'
8+
let(:facts) { {
9+
:osfamily => 'Debian',
10+
:operatingsystem => 'Debian',
11+
:lsbdistid => 'Debian',
12+
:lsbdistcodename => 'jessie',
13+
:kernelrelease => '3.2.0-4-amd64',
14+
:operatingsystemmajrelease => '8',
15+
} }
16+
elsif osfamily == 'Windows'
17+
let(:facts) { {
18+
:osfamily => 'Windows',
19+
:operatingsystem => 'Windows',
20+
:kernelrelease => '10.0.14393',
21+
:operatingsystemmajrelease => '2016',
22+
} }
23+
end
1324

14-
context 'with ensure => present and swarm init' do
15-
let(:params) { {
16-
'init' => true,
17-
'advertise_addr' => '192.168.1.1',
18-
'listen_addr' => '192.168.1.1',
19-
} }
20-
it { is_expected.to compile.with_all_deps }
21-
it { should contain_exec('Swarm init').with_command(/docker swarm init/) }
22-
end
25+
context 'with ensure => present and swarm init' do
26+
let(:params) { {
27+
'init' => true,
28+
'advertise_addr' => '192.168.1.1',
29+
'listen_addr' => '192.168.1.1',
30+
} }
31+
it { is_expected.to compile.with_all_deps }
32+
it { should contain_exec('Swarm init').with_command(/docker swarm init/) }
33+
end
2334

24-
context 'with ensure => present and swarm join' do
25-
let(:params) { {
26-
'join' => true,
27-
'advertise_addr' => '192.168.1.1',
28-
'listen_addr' => '192.168.1.1',
29-
'token' => 'foo',
30-
'manager_ip' => '192.168.1.2'
31-
} }
32-
it { is_expected.to compile.with_all_deps }
33-
it { should contain_exec('Swarm join').with_command(/docker swarm join/) }
34-
end
35+
context 'with ensure => present and swarm join' do
36+
let(:params) { {
37+
'join' => true,
38+
'advertise_addr' => '192.168.1.1',
39+
'listen_addr' => '192.168.1.1',
40+
'token' => 'foo',
41+
'manager_ip' => '192.168.1.2'
42+
} }
43+
it { is_expected.to compile.with_all_deps }
44+
it { should contain_exec('Swarm join').with_command(/docker swarm join/) }
45+
end
3546

36-
context 'with ensure => absent' do
37-
let(:params) { {
38-
'ensure' => 'absent',
39-
'join' => true,
40-
'advertise_addr' => '192.168.1.1',
41-
'listen_addr' => '192.168.1.1',
42-
'token' => 'foo',
43-
'manager_ip' => '192.168.1.2'
44-
} }
45-
it { is_expected.to compile.with_all_deps }
46-
it { should contain_exec('Leave swarm').with_command(/docker swarm leave --force/) }
47+
context 'with ensure => absent' do
48+
let(:params) { {
49+
'ensure' => 'absent',
50+
'join' => true,
51+
'advertise_addr' => '192.168.1.1',
52+
'listen_addr' => '192.168.1.1',
53+
'token' => 'foo',
54+
'manager_ip' => '192.168.1.2'
55+
} }
56+
it { is_expected.to compile.with_all_deps }
57+
it { should contain_exec('Leave swarm').with_command(/docker swarm leave --force/) }
58+
end
59+
end
4760
end
4861
end

0 commit comments

Comments
 (0)