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

Returns a new instance of 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



80
81
82
# File 'lib/capistrano/dockercompose/interactive/instance.rb', line 80

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

#count_containerObject



44
45
46
47
48
49
# File 'lib/capistrano/dockercompose/interactive/instance.rb', line 44

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

#down(args = '') ⇒ Object



64
65
66
# File 'lib/capistrano/dockercompose/interactive/instance.rb', line 64

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

Returns:

  • (Boolean)


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

def isup?
  count_container > 0
rescue
  false
end

#pull(args = '') ⇒ Object



84
85
86
# File 'lib/capistrano/dockercompose/interactive/instance.rb', line 84

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

#restart(args = '') ⇒ Object



76
77
78
# File 'lib/capistrano/dockercompose/interactive/instance.rb', line 76

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



72
73
74
# File 'lib/capistrano/dockercompose/interactive/instance.rb', line 72

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

#start_or_restartObject

starts or restarts a docker compose



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

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

#stop(args = '') ⇒ Object



60
61
62
# File 'lib/capistrano/dockercompose/interactive/instance.rb', line 60

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

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



68
69
70
# File 'lib/capistrano/dockercompose/interactive/instance.rb', line 68

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