Skip to content

Commit 5f285d7

Browse files
authored
Merge pull request #93 from elimin8r/master
Add task for updating existing service
2 parents f7a08e2 + a5b25b5 commit 5f285d7

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

tasks/swarm_update.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"description": "Updates an existing service.",
3+
"input_method": "stdin",
4+
"parameters": {
5+
"service": {
6+
"description": "The service to update",
7+
"type": "String[1]"
8+
},
9+
"image": {
10+
"description": "The new image to use for the service",
11+
"type": "String[1]"
12+
}
13+
}
14+
}

tasks/swarm_update.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/opt/puppetlabs/puppet/bin/ruby
2+
require 'json'
3+
require 'open3'
4+
require 'puppet'
5+
6+
def swarm_update(image, service)
7+
cmd_string = "docker service update"
8+
cmd_string << " --image #{image}" unless image.nil?
9+
cmd_string << " #{service}" unless service.nil?
10+
11+
stdout, stderr, status = Open3.capture3(cmd_string)
12+
raise Puppet::Error, ("stderr: '#{stderr}'") if status != 0
13+
stdout.strip
14+
end
15+
16+
params = JSON.parse(STDIN.read)
17+
image = params['image']
18+
service = params['service']
19+
20+
begin
21+
result = swarm_update(image, service)
22+
puts result
23+
exit 0
24+
rescue Puppet::Error => e
25+
puts({ status: 'failure', error: e.message })
26+
exit 1
27+
end

0 commit comments

Comments
 (0)