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

docker::services: Fix using multiple published ports #447

Merged
merged 1 commit into from
Mar 4, 2019
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ docker::services {'redis':
}
```

To base the service off an image, include the `image` parameter and include the `publish` parameter to expose the service ports. To set the amount of containers running in the service, include the `replicas` parameter. To attach one or multiple filesystems to the service, use the `mounts` parameter. For information regarding the `extra_params` parameter, see `docker service create --help`.
To base the service off an image, include the `image` parameter and include the `publish` parameter to expose the service port (use an array to specify multiple published ports). To set the amount of containers running in the service, include the `replicas` parameter. To attach one or multiple filesystems to the service, use the `mounts` parameter. For information regarding the `extra_params` parameter, see `docker service create --help`.

To update the service, add the following code to the manifest file:

Expand Down
6 changes: 5 additions & 1 deletion lib/puppet/parser/functions/docker_service_flags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ module Puppet::Parser::Functions
end
end

if opts['publish'] && opts['publish'].to_s != 'undef'
if opts['publish'].is_a? Array
opts['publish'].each do |port|
flags << "--publish #{port}"
end
elsif opts['publish'].to_s != 'undef'
flags << "--publish '#{opts['publish']}'"
end

Expand Down
3 changes: 2 additions & 1 deletion manifests/services.pp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# Defaults to []
#
# [*publish*]
# Publish a port as a node port.
# Publish port(s) as node ports.
# Defaults to undef
#
# [*replicas*]
Expand Down Expand Up @@ -66,6 +66,7 @@
# [*registry_mirror*]
# This will allow the service to set a registry mirror.
# defaults to undef
#
# [*mounts*]
# Allows attacking filesystem mounts to the service (specified as an array)
# defaults to []
Expand Down
14 changes: 14 additions & 0 deletions spec/defines/services_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@
it { should contain_exec('test_service docker service create').with_command(/docker service create/) }
it { should contain_exec('test_service_2 docker service create').with_command(/docker service create/) }
end

context 'multiple publish ports' do
let(:pre_condition) {
"
docker::services { 'test_service_3':
service_name => 'foo_3',
image => 'foo:bar',
publish => ['80:8080', '9000:9000' ],
}
"
}
it { should contain_exec('test_service_3 docker service create').with_command(/--publish 80:8080/) }
it { should contain_exec('test_service_3 docker service create').with_command(/--publish 9000:9000/) }
end
end

context 'with ensure => present and service update' do
Expand Down