Skip to content

Commit fb2d756

Browse files
jacksgtdavejrt
authored andcommitted
Docker::Services:: fix command parameter used with an array (#452)
The module previously allowed specifying the command parameter to docker::services as an array, but did not correctly parse it as such (output with square brackets and quotations marks to docker). This patch fixes this behavior.
1 parent 15ee0e4 commit fb2d756

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -801,10 +801,11 @@ docker::services {'redis':
801801
replicas => '5',
802802
mounts => ['type=bind,source=/etc/my-redis.conf,target=/etc/redis/redis.conf,readonly'],
803803
extra_params => ['--update-delay 1m', '--restart-window 30s'],
804+
command => ['redis-server', '--appendonly', 'yes'],
804805
}
805806
```
806807

807-
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`.
808+
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`. The `command` parameter can either be specified as an array or a string.
808809

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

lib/puppet/parser/functions/docker_service_flags.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ module Puppet::Parser::Functions
8484
flags << "'#{opts['image']}'"
8585
end
8686

87-
if opts['command'] && opts['command'].to_s != 'undef'
87+
if opts['command'].is_a? Array
88+
flags << opts['command'].join(' ')
89+
elsif opts['command'] && opts['command'].to_s != 'undef'
8890
flags << opts['command'].to_s
8991
end
9092

spec/defines/services_spec.rb

+5
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,29 @@
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'],
2525
'networks' => ['overlay'],
26+
'command' => 'echo hello world',
2627
} }
2728
it { is_expected.to compile.with_all_deps }
2829
it { should contain_exec('test_service docker service create').with_command(/docker service create/) }
2930
it { should contain_exec('test_service docker service create').with_command(/--env MY_ENV=1/) }
3031
it { should contain_exec('test_service docker service create').with_command(/--label bar=baz/) }
3132
it { should contain_exec('test_service docker service create').with_command(/--mount type=bind,src=\/tmp\/b,dst=\/tmp\/b,readonly/) }
3233
it { should contain_exec('test_service docker service create').with_command(/--network overlay/) }
34+
it { should contain_exec('test_service docker service create').with_command(/echo hello world/) }
3335

3436
context 'multiple services declaration' do
3537
let(:pre_condition) {
3638
"
3739
docker::services { 'test_service_2':
3840
service_name => 'foo_2',
3941
image => 'foo:bar',
42+
command => ['echo', 'hello', 'world'],
4043
}
4144
"
4245
}
4346
it { should contain_exec('test_service docker service create').with_command(/docker service create/) }
4447
it { should contain_exec('test_service_2 docker service create').with_command(/docker service create/) }
48+
it { should contain_exec('test_service_2 docker service create').with_command(/echo hello world/) }
4549
end
4650

4751
context 'multiple publish ports and multiple networks' do
@@ -60,6 +64,7 @@
6064
it { should contain_exec('test_service_3 docker service create').with_command(/--network foo_1/) }
6165
it { should contain_exec('test_service_3 docker service create').with_command(/--network foo_2/) }
6266
end
67+
6368
end
6469

6570
context 'with ensure => present and service update' do

0 commit comments

Comments
 (0)