Puppet Function: docker_service_flags
- Defined in:
- lib/puppet/parser/functions/docker_service_flags.rb
- Function type:
- Ruby 3.x API
Overview
Transforms a hash into a string of docker swarm init flags
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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/puppet/parser/functions/docker_service_flags.rb', line 9 newfunction(:docker_service_flags, type: :rvalue) do |args| opts = args[0] || {} flags = [] if opts['service_name'] && opts['service_name'].to_s != 'undef' flags << "'#{opts['service_name']}'" end if opts['detach'].to_s != 'false' flags << '--detach' end if opts['env'].is_a? Array opts['env'].each do |env| flags << "--env '#{env}'" end end if opts['label'].is_a? Array opts['label'].each do |label| flags << "--label #{label}" end end if opts['mounts'].is_a? Array opts['mounts'].each do |mount| flags << "--mount #{mount}" end end if opts['networks'].is_a? Array opts['networks'].each do |network| flags << "--network #{network}" end end if opts['publish'].is_a? Array opts['publish'].each do |port| flags << "--publish #{port}" end elsif opts['publish'] && opts['publish'].to_s != 'undef' flags << "--publish '#{opts['publish']}'" end if opts['replicas'] && opts['replicas'].to_s != 'undef' flags << "--replicas '#{opts['replicas']}'" end if opts['tty'].to_s != 'false' flags << '--tty' end if opts['user'] && opts['user'].to_s != 'undef' flags << "--user '#{opts['user']}'" end if opts['workdir'] && opts['workdir'].to_s != 'undef' flags << "--workdir '#{opts['workdir']}'" end if opts['extra_params'].is_a? Array opts['extra_params'].each do |param| flags << param end end if opts['host_socket'] && opts['host_socket'].to_s != 'undef' flags << "-H '#{opts['host_socket']}'" end if opts['registry_mirror'].is_a? Array opts['registry_mirror'].each do |param| flags << "--registry-mirror='#{param}'" end elsif opts['registry_mirror'] && opts['registry_mirror'].to_s != 'undef' flags << "--registry-mirror='#{opts['registry_mirror']}'" end if opts['image'] && opts['image'].to_s != 'undef' flags << "'#{opts['image']}'" end if opts['command'].is_a? Array flags << opts['command'].join(' ') elsif opts['command'] && opts['command'].to_s != 'undef' flags << opts['command'].to_s end flags.flatten.join(' ') end |