Class: DockerCompose::Interactive::Instance

Inherits:
Object
  • Object
show all
Defined in:
lib/capistrano/dockercompose/interactive/instance.rb

Instance Method Summary collapse

Constructor Details

#initialize(file = '', project = nil) ⇒ Instance



7
8
9
10
# File 'lib/capistrano/dockercompose/interactive/instance.rb', line 7

def initialize(file='', project=nil)
  @file    = file
  @project = project
end

Instance Method Details

#build(args = '') ⇒ Object



74
75
76
# File 'lib/capistrano/dockercompose/interactive/instance.rb', line 74

def build(args='')
  execute_compose_command("build #{args}")
end

#configObject



12
13
14
15
16
# File 'lib/capistrano/dockercompose/interactive/instance.rb', line 12

def config
  return @config if @config
  raw_config = execute_compose_command('config', true)
  @config = YAML.load(raw_config)
end

#down(args = '') ⇒ Object



58
59
60
# File 'lib/capistrano/dockercompose/interactive/instance.rb', line 58

def down(args='')
  execute_compose_command("down #{args}")
end

#execute(cmd, capture = false) ⇒ Object



18
19
20
# File 'lib/capistrano/dockercompose/interactive/instance.rb', line 18

def execute(cmd, capture = false)
  execute_compose_command(cmd, capture)
end

#execute_compose_command(cmd, capture = false) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/capistrano/dockercompose/interactive/instance.rb', line 22

def execute_compose_command(cmd, capture = false)
  project = @project.empty? ? "" : "-p #{@project}"
  file    = @file.empty?    ? "" : "--file #{@file}"
  cmd     = "#{file} #{project} #{cmd}"

  if capture
    return DockerCompose::Interactive.capture_local_or_remote cmd
  else
    DockerCompose::Interactive.execute_local_or_remote_interactive cmd
  end
end

#isup?Boolean



38
39
40
41
42
43
# File 'lib/capistrano/dockercompose/interactive/instance.rb', line 38

def isup?
  count = execute_compose_command('ps -q | wc -l', capture = true)
  count.to_i
rescue
  false
end

#pull(args = '') ⇒ Object



78
79
80
# File 'lib/capistrano/dockercompose/interactive/instance.rb', line 78

def pull(args='')
  execute_compose_command("pull #{args}")
end

#restart(args = '') ⇒ Object



70
71
72
# File 'lib/capistrano/dockercompose/interactive/instance.rb', line 70

def restart(args='')
  execute_compose_command("restart #{args}")
end

#service(name) ⇒ Object



34
35
36
# File 'lib/capistrano/dockercompose/interactive/instance.rb', line 34

def service(name)
  Service.new(self, name, config()['services'][name])
end

#start(args = '') ⇒ Object



66
67
68
# File 'lib/capistrano/dockercompose/interactive/instance.rb', line 66

def start(args='')
  execute_compose_command("start #{args}")
end

#start_or_restartObject

starts or restarts a docker compose



46
47
48
49
50
51
52
# File 'lib/capistrano/dockercompose/interactive/instance.rb', line 46

def start_or_restart
  if isup?
    restart()
  else
    up()
  end
end

#stop(args = '') ⇒ Object



54
55
56
# File 'lib/capistrano/dockercompose/interactive/instance.rb', line 54

def stop(args='')
  execute_compose_command("stop #{args}")
end

#up(args = '-d') ⇒ Object



62
63
64
# File 'lib/capistrano/dockercompose/interactive/instance.rb', line 62

def up(args='-d')
  execute_compose_command("up #{args}")
end