Class: Docker::Rails::CLI::Main

Inherits:
Thor
  • Object
show all
Defined in:
lib/docker/rails/cli/main.rb

Instance Method Summary collapse

Instance Method Details

#bash_connect(target, service_name) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/docker/rails/cli/main.rb', line 142

def bash_connect(target, service_name)
  # init singleton with full options
  app = App.configured(target, options)

  invoke :compose, [target], []

  container = app.bash_connect(service_name)

  # Automatically cleanup any remnants of a simple bash session.
  return if container.nil?
  container.stop
  container.remove(v: true, force: true)
end

#before(target) ⇒ Object



95
96
97
98
99
# File 'lib/docker/rails/cli/main.rb', line 95

def before(target)
  app = App.configured(target, options)
  invoke :compose, [target], []
  app.before_command
end

#build(target) ⇒ Object



82
83
84
85
# File 'lib/docker/rails/cli/main.rb', line 82

def build(target)
  invoke :compose
  App.configured(target, options).compose_build
end

#ci(target) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/docker/rails/cli/main.rb', line 23

def ci(target)
  # init singleton with full options
  app = App.configured(target, options)

  invoke :before, [target], []
  invoke :compose, [target], []
  invoke CLI::GemsetVolume, :create, [target], options
  begin
    invoke :build # on CI - always build to ensure dockerfile hasn't been altered - small price to pay for consistent CI.
    invoke :up
  ensure
    invoke :cleanup
  end

  exit app.exit_code
end

#cleanup(target) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/docker/rails/cli/main.rb', line 51

def cleanup(target)
  invoke :stop
  invoke :extract if options[:extract]
  invoke :rm_volumes
  invoke :rm_compose
  invoke :rm_dangling
  invoke :ps_all
end

#compose(target) ⇒ Object



89
90
91
# File 'lib/docker/rails/cli/main.rb', line 89

def compose(target)
  App.configured(target, options).compose
end

#exec(target, service_name, command) ⇒ Object



158
159
160
161
162
163
164
165
166
# File 'lib/docker/rails/cli/main.rb', line 158

def exec(target, service_name, command)
  # init singleton with full options
  app = App.configured(target, options)

  invoke :compose, [target], []
  invoke CLI::GemsetVolume, :create, [target], []

  app.run_service_command(service_name, command)
end

#extract(target) ⇒ Object



42
43
44
45
46
# File 'lib/docker/rails/cli/main.rb', line 42

def extract(target)
  app = App.configured(target, options)
  invoke :compose, [target], []
  app.extract_all
end

#ps(target) ⇒ Object



129
130
131
132
# File 'lib/docker/rails/cli/main.rb', line 129

def ps(target)
  invoke :compose
  App.configured(target, options).ps
end

#ps_all(build = nil, target = nil) ⇒ Object



136
137
138
# File 'lib/docker/rails/cli/main.rb', line 136

def ps_all(build = nil, target = nil)
  App.instance.ps_all
end

#rm_compose(build = nil, target = nil) ⇒ Object



117
118
119
# File 'lib/docker/rails/cli/main.rb', line 117

def rm_compose(build = nil, target = nil)
  App.instance.rm_compose
end

#rm_dangling(build = nil, target = nil) ⇒ Object



123
124
125
# File 'lib/docker/rails/cli/main.rb', line 123

def rm_dangling(build = nil, target = nil)
  App.instance.rm_dangling
end

#rm_volumes(target) ⇒ Object



110
111
112
113
# File 'lib/docker/rails/cli/main.rb', line 110

def rm_volumes(target)
  invoke :stop
  App.configured(target, options).rm_volumes
end

#stop(target) ⇒ Object



103
104
105
106
# File 'lib/docker/rails/cli/main.rb', line 103

def stop(target)
  invoke :compose
  App.configured(target, options).stop_all
end

#up(target) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/docker/rails/cli/main.rb', line 63

def up(target)
  # init singleton with full options
  app = App.configured(target, options)
  base_options = options.except(:detached)

  invoke :before, [target], base_options
  invoke CLI::GemsetVolume, :create, [target], base_options

  if options[:detached]
    compose_options = '-d'
  else
    compose_options = '--abort-on-container-exit'
  end

  app.up(compose_options)
end