Skip to content

Commit 1c1562f

Browse files
committed
Suggestions applied 1
1 parent 9dbc13b commit 1c1562f

17 files changed

+74
-85
lines changed

manifests/compose.pp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@
7171
}
7272

7373
if $facts['os']['family'] == 'windows' {
74-
$docker_download_command = ['if', '(Invoke-WebRequest', $docker_compose_url, $proxy_opt, '-UseBasicParsing', '-OutFile', "\"${docker_compose_location_versioned}\") { exit 0 } else { exit 1}"] # lint:ignore:140chars
75-
7674
exec { "Install Docker Compose ${version}":
7775
command => template('docker/windows/download_docker_compose.ps1.erb'),
7876
provider => powershell,

manifests/install.pp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,8 @@
113113
}
114114
}
115115

116-
$fail_restart_command = 'SC.exe failure Docker reset= 432000 actions= restart/30000/restart/60000/restart/60000'
117116
exec { 'service-restart-on-failure':
118-
command => $fail_restart_command,
117+
command => 'SC.exe failure Docker reset= 432000 actions= restart/30000/restart/60000/restart/60000',
119118
refreshonly => true,
120119
logoutput => true,
121120
provider => powershell,

manifests/machine.pp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@
5656
}
5757

5858
if $facts['os']['family'] == 'windows' {
59-
$docker_download_command = ['if', '(Invoke-WebRequest', $docker_machine_url, $proxy_opt, '-UseBasicParsing', '-OutFile', "\"${docker_machine_location_versioned}\") { exit 0 } else { exit 1}"] # lint:ignore:140chars
60-
6159
exec { "Install Docker Machine ${version}":
6260
command => template('docker/windows/download_docker_machine.ps1.erb'),
6361
provider => powershell,

manifests/registry.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
default => $pass_hash
113113
}
114114

115-
$_auth_command = "${auth_cmd} || (rm -f \"/${_local_user_home}/registry-auth-puppet_receipt_${server_strip}_${local_user}\"; exit 1;)"
115+
$_auth_command = [$auth_cmd, '||', "(rm -f \"/${_local_user_home}/registry-auth-puppet_receipt_${server_strip}_${local_user}\"; exit 1;)"] # lint:ignore:140chars
116116

117117
file { "/${_local_user_home}/registry-auth-puppet_receipt_${server_strip}_${local_user}":
118118
ensure => $ensure,

manifests/run.pp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,8 @@
387387

388388
if $restart {
389389
if $ensure == 'absent' {
390-
$restart_stop_command = [$docker_command, 'stop', "--time=${stop_wait_time}", $sanitised_title]
391-
$restart_stop_onlyif = [$docker_command, 'inspect', $sanitised_title]
390+
$restart_stop_command = [$docker_command, 'stop', '--time', $stop_wait_time, $sanitised_title]
391+
$restart_stop_onlyif = [[$docker_command, 'inspect', $sanitised_title]]
392392

393393
exec { "stop ${title} with docker":
394394
command => $restart_stop_command,
@@ -400,7 +400,7 @@
400400
}
401401

402402
$restart_remove_command = "${docker_command} rm -v ${sanitised_title}"
403-
$restart_remove_onlyif = [$docker_command, 'inspect', $sanitised_title]
403+
$restart_remove_onlyif = [[$docker_command, 'inspect', $sanitised_title]]
404404

405405
exec { "remove ${title} with docker":
406406
command => $restart_remove_command,
@@ -440,7 +440,7 @@
440440
}
441441

442442
if $running == false {
443-
$running_stop_command = [$docker_command, 'stop', "--time=${stop_wait_time}", $sanitised_title]
443+
$running_stop_command = [$docker_command, 'stop', '--time', $stop_wait_time, $sanitised_title]
444444
exec { "stop ${title} with docker":
445445
command => $running_stop_command,
446446
onlyif => $container_running_check,
@@ -527,7 +527,7 @@
527527

528528
if $ensure == 'absent' {
529529
if $facts['os']['family'] == 'windows' {
530-
$absent_stop_command = "${docker_command} stop --time=${stop_wait_time} ${sanitised_title}"
530+
$absent_stop_command = "${docker_command} stop --time ${stop_wait_time} ${sanitised_title}"
531531
$absent_stop_onlyif = "${docker_command} inspect ${sanitised_title}"
532532

533533
exec { "stop container ${service_prefix}${sanitised_title}":

tasks/node_ls.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
require 'puppet'
77

88
def node_ls(filter, quiet)
9-
cmd_string = ['docker', 'node', 'ls']
10-
cmd_string += [" --filter=#{filter}"] unless filter.nil?
11-
cmd_string += [' --quiet'] unless quiet.nil?
9+
cmd = ['docker', 'node', 'ls']
10+
cmd.concat([" --filter=#{filter}"]) unless filter.nil?
11+
cmd.concat([' --quiet']) unless quiet.nil?
1212

13-
stdout, stderr, status = Open3.capture3(cmd_string)
13+
stdout, stderr, status = Open3.capture3(cmd)
1414
raise Puppet::Error, "stderr: '#{stderr}'" if status != 0
1515
stdout.strip
1616
end

tasks/node_rm.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
require 'puppet'
77

88
def node_rm(force, node)
9-
cmd_string = ['docker', 'node', 'rm']
10-
cmd_string += [' --force'] unless force.nil?
11-
cmd_string += [" #{node}"] unless node.nil?
9+
cmd = ['docker', 'node', 'rm']
10+
cmd.concat([' --force']) unless force.nil?
11+
cmd.concat([" #{node}"]) unless node.nil?
1212

13-
stdout, stderr, status = Open3.capture3(cmd_string)
13+
stdout, stderr, status = Open3.capture3(cmd)
1414
raise Puppet::Error, "stderr: '#{stderr}'" if status != 0
1515
stdout.strip
1616
end

tasks/node_update.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@
66
require 'puppet'
77

88
def node_update(availability, role, label_add, label_rm, node)
9-
cmd_string = ['docker', 'node', 'update']
10-
cmd_string += [" --availability #{availability}"] unless availability.nil?
11-
cmd_string += [" --role #{role}"] unless role.nil?
9+
cmd = ['docker', 'node', 'update']
10+
cmd.concat([" --availability #{availability}"]) unless availability.nil?
11+
cmd.concat([" --role #{role}"]) unless role.nil?
1212

1313
if label_add.is_a? Array
1414
label_add.each do |param|
15-
cmd_string += [" --label-add #{param}"]
15+
cmd.concat([" --label-add #{param}"])
1616
end
1717
end
1818

1919
if label_rm.is_a? Array
2020
label_rm.each do |param|
21-
cmd_string += [" --label-rm #{param}"]
21+
cmd.concat([" --label-rm #{param}"])
2222
end
2323
end
2424

25-
cmd_string += " #{node}" unless node.nil?
25+
cmd.concat([" #{node}"]) unless node.nil?
2626

27-
stdout, stderr, status = Open3.capture3(cmd_string)
27+
stdout, stderr, status = Open3.capture3(cmd)
2828
raise Puppet::Error, "stderr: '#{stderr}'" if status != 0
2929
stdout.strip
3030
end

tasks/service_create.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
},
1717
"expose": {
1818
"description": "Publish service ports externally to the swarm",
19-
"type": "Variant[String,Array,Undef]"
19+
"type": "Variant[Array,Undef]"
2020
},
2121
"env": {
2222
"description": "Set environment variables",
2323
"type": "Optional[Hash]"
2424
},
2525
"command": {
2626
"description": "Command to run on the container",
27-
"type": "Variant[String,Array,Undef]"
27+
"type": "Variant[Array,Undef]"
2828
},
2929
"extra_params": {
3030
"description": "Allows you to pass any other flag that the Docker service create supports.",

tasks/service_create.rb

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,27 @@
44
require 'json'
55
require 'open3'
66
require 'puppet'
7+
require 'shellwords'
78

89
def service_create(image, replicas, expose, env, command, extra_params, service, detach)
9-
cmd_string = ['docker', 'service', 'create']
10-
if extra_params.is_a? Array
11-
extra_params.each do |param|
12-
cmd_string += [" #{param}"]
13-
end
14-
end
15-
cmd_string += [" --name #{service}"] unless service.nil?
16-
cmd_string += [" --replicas #{replicas}"] unless replicas.nil?
17-
cmd_string += [" --publish #{expose}"] unless expose.nil?
10+
cmd = ['docker', 'service', 'create']
11+
cmd.concat(extra_params) unless extra_params.nil? || extra_params.empty?
12+
13+
cmd.concat(['--name', service]) unless service.nil?
14+
cmd.concat(['--replicas', replicas.to_s]) unless replicas.nil?
15+
cmd.concat(['--publish', Shellwords.join(expose)]) unless expose.nil?
16+
1817
if env.is_a? Hash
1918
env.each do |key, value|
20-
cmd_string += [" --env #{key}='#{value}'"]
19+
cmd.concat(['--env', Shellwords.escape("#{key}=#{value}")])
2120
end
2221
end
2322

24-
if command.is_a? Array
25-
cmd_string += command.join(' ')
26-
elsif command && command.to_s != 'undef'
27-
cmd_string += command.to_s
28-
end
29-
30-
cmd_string += [' -d'] unless detach.nil?
31-
cmd_string += [" #{image}"] unless image.nil?
23+
cmd.append(image) unless image.nil?
24+
cmd.append('-d') unless !detach || detach.nil?
25+
cmd.concat(command) unless command.nil? || command.empty?
3226

33-
stdout, stderr, status = Open3.capture3(cmd_string)
27+
stdout, stderr, status = Open3.capture3(*cmd)
3428
raise Puppet::Error, "stderr: '#{stderr}'" if status != 0
3529
stdout.strip
3630
end

0 commit comments

Comments
 (0)