Skip to content

Commit 15ee0e4

Browse files
jacksgtdavejrt
authored andcommitted
Docker::Services: Add networks parameter for swarm services (#450)
Allows attaching the service to one or multiple networks
1 parent 226be6c commit 15ee0e4

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

Diff for: lib/puppet/parser/functions/docker_service_flags.rb

+6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ module Puppet::Parser::Functions
3636
end
3737
end
3838

39+
if opts['networks'].is_a? Array
40+
opts['networks'].each do |network|
41+
flags << "--network #{network}"
42+
end
43+
end
44+
3945
if opts['publish'].is_a? Array
4046
opts['publish'].each do |port|
4147
flags << "--publish #{port}"

Diff for: manifests/services.pp

+7-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@
6868
# defaults to undef
6969
#
7070
# [*mounts*]
71-
# Allows attacking filesystem mounts to the service (specified as an array)
71+
# Allows attaching filesystem mounts to the service (specified as an array)
72+
# defaults to []
73+
#
74+
# [*networks*]
75+
# Allows attaching the service to networks (specified as an array)
7276
# defaults to []
7377
#
7478
# [*command*]
@@ -94,6 +98,7 @@
9498
Variant[String,Array,Undef] $host_socket = undef,
9599
Variant[String,Array,Undef] $registry_mirror = undef,
96100
Variant[String,Array,Undef] $mounts = undef,
101+
Variant[Array,Undef] $networks = undef,
97102
Variant[String,Array,Undef] $command = undef,
98103
){
99104

@@ -138,6 +143,7 @@
138143
host_socket => $host_socket,
139144
registry_mirror => $registry_mirror,
140145
mounts => $mounts,
146+
networks => $networks,
141147
command => $command,
142148
})
143149

Diff for: spec/defines/services_spec.rb

+6-1
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@
2222
'env' => ['MY_ENV=1', 'MY_ENV2=2'],
2323
'label' => ['com.example.foo="bar"', 'bar=baz'],
2424
'mounts' => ['type=bind,src=/tmp/a,dst=/tmp/a', 'type=bind,src=/tmp/b,dst=/tmp/b,readonly'],
25+
'networks' => ['overlay'],
2526
} }
2627
it { is_expected.to compile.with_all_deps }
2728
it { should contain_exec('test_service docker service create').with_command(/docker service create/) }
2829
it { should contain_exec('test_service docker service create').with_command(/--env MY_ENV=1/) }
2930
it { should contain_exec('test_service docker service create').with_command(/--label bar=baz/) }
3031
it { should contain_exec('test_service docker service create').with_command(/--mount type=bind,src=\/tmp\/b,dst=\/tmp\/b,readonly/) }
32+
it { should contain_exec('test_service docker service create').with_command(/--network overlay/) }
3133

3234
context 'multiple services declaration' do
3335
let(:pre_condition) {
@@ -42,18 +44,21 @@
4244
it { should contain_exec('test_service_2 docker service create').with_command(/docker service create/) }
4345
end
4446

45-
context 'multiple publish ports' do
47+
context 'multiple publish ports and multiple networks' do
4648
let(:pre_condition) {
4749
"
4850
docker::services { 'test_service_3':
4951
service_name => 'foo_3',
5052
image => 'foo:bar',
5153
publish => ['80:8080', '9000:9000' ],
54+
networks => ['foo_1', 'foo_2'],
5255
}
5356
"
5457
}
5558
it { should contain_exec('test_service_3 docker service create').with_command(/--publish 80:8080/) }
5659
it { should contain_exec('test_service_3 docker service create').with_command(/--publish 9000:9000/) }
60+
it { should contain_exec('test_service_3 docker service create').with_command(/--network foo_1/) }
61+
it { should contain_exec('test_service_3 docker service create').with_command(/--network foo_2/) }
5762
end
5863
end
5964

0 commit comments

Comments
 (0)