Puppet Function: docker_service_flags

Defined in:
lib/puppet/parser/functions/docker_service_flags.rb
Function type:
Ruby 3.x API

Overview

docker_service_flags()Any

Transforms a hash into a string of docker swarm init flags

Returns:

  • (Any)


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/puppet/parser/functions/docker_service_flags.rb', line 5

newfunction(:docker_service_flags, :type => :rvalue) do |args|
  opts = args[0] || {}
  flags = []

  if opts['detach'].to_s != 'true'
    flags << '--detach'
  end
  
  if opts['service_name'].to_s != 'undef'
    flags << "'#{opts['service_name']}'"	    
  end

  if opts['env'].to_s != 'undef'
    flags << "--env '#{opts['env']}'"
  end
  
  if opts['label'].to_s != 'undef'
    flags << "--label '#{opts['label']}'"
  end

  if opts['publish'].to_s != 'undef'
    flags << "--publish '#{opts['publish']}'"
  end
  
  if opts['replicas'].to_s != 'undef'
    flags << "--replicas '#{opts['replicas']}'"
  end      

  if opts['tty'].to_s != 'false'
    flags << '--tty'
  end   
  
  if opts['user'].to_s != 'undef'
    flags << "--user '#{opts['publish']}'"
  end   
  
  if opts['workdir'].to_s != 'undef'
    flags << "--workdir '#{opts['workdir']}'"
  end  
  
  if opts['extra_params'].each do |param|
    flags << param
   end
  end
 
  if opts['image'].to_s != 'undef'
    flags << "'#{opts['image']}'"      
  end

  flags.flatten.join(" ")
end