Class: DockerApp::ManagerSwarm

Inherits:
Object
  • Object
show all
Defined in:
lib/docker_app/manager_swarm.rb

Class Method Summary collapse

Class Method Details

.cmd(s) ⇒ Object

helpers



60
61
62
# File 'lib/docker_app/manager_swarm.rb', line 60

def self.cmd(s)
  Command.cmd(s)
end

.create_service(server_name, settings = {}) ⇒ Object



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
# File 'lib/docker_app/manager_swarm.rb', line 15

def self.create_service(server_name, settings={})
  puts "create swarm service.."

  # destroy
  destroy_service(server_name, settings)


  # prepare
  create_volumes_dirs(settings)

  # create service
  docker_opts = settings.properties['docker']

  run_opts = []
  run_opts << "--network #{docker_opts['swarm_network']}" if docker_opts['swarm_network']
  run_opts << settings.docker_ports_string
  run_opts << settings.run_env_variables_string

  # volumes
  #--mount type=bind,source=/path/on/host,destination=/path/in/container
  run_opts << settings.docker_volumes.map{|r| "--mount type=bind,source=#{r[0]},destination=#{r[1]}" }.join(' ')

  #
  run_opts << docker_opts['swarm_options']

  cmd %Q(docker service create \
--name #{settings.service_name} \
#{run_opts.join(' ')} \
#{settings.image_name} #{settings['docker']['command']}
)
end

.create_volumes_dirs(settings) ⇒ Object

volumes



49
50
51
52
53
54
55
56
# File 'lib/docker_app/manager_swarm.rb', line 49

def self.create_volumes_dirs(settings)
  settings.docker_volumes.each do |r|
    dirpath = "#{r[0]}"
    if !Dir.exists?(dirpath)
      FileUtils.mkdir_p(dirpath) rescue nil
    end
  end
end

.destroy_service(server_name, settings) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/docker_app/manager_swarm.rb', line 4

def self.destroy_service(server_name, settings)
  puts "destroying service #{server_name}..."

  #
  cmd %Q(docker service rm #{settings.service_name} )

  #
  return true
end