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



150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/docker/rails/cli/main.rb', line 150

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



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

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

#build(target) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/docker/rails/cli/main.rb', line 77

def build(target)
  invoke :compose
  app = App.configured(target, options)
  app.create_dockito_vault
  begin
    app.compose_build
  ensure
    app.rm_dockito_vault
    app.after_build_command
  end
end

#ci(target) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/docker/rails/cli/main.rb', line 20

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

  invoke :before, [target], []
  invoke :compose, [target], []
  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



47
48
49
50
51
52
53
54
# File 'lib/docker/rails/cli/main.rb', line 47

def cleanup(target)
  invoke :stop
  invoke :extract if options[:extract]
  invoke :rm_volumes
  invoke :rm_compose
  # invoke :rm_dangling # causes a brand new dockerfile build - don't do that. See https://github.com/alienfast/docker-rails/issues/26
  invoke :ps_all
end

#compose(target) ⇒ Object



91
92
93
# File 'lib/docker/rails/cli/main.rb', line 91

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

#exec(target, service_name, command) ⇒ Object



166
167
168
169
170
171
172
173
# File 'lib/docker/rails/cli/main.rb', line 166

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

  invoke :compose, [target], []

  app.run_service_command(service_name, command)
end

#extract(target) ⇒ Object



38
39
40
41
42
# File 'lib/docker/rails/cli/main.rb', line 38

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

#ps(target) ⇒ Object



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

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

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



144
145
146
# File 'lib/docker/rails/cli/main.rb', line 144

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

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



119
120
121
# File 'lib/docker/rails/cli/main.rb', line 119

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

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



125
126
127
# File 'lib/docker/rails/cli/main.rb', line 125

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

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



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

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

#rm_volumes(target) ⇒ Object



112
113
114
115
# File 'lib/docker/rails/cli/main.rb', line 112

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

#stop(target) ⇒ Object



105
106
107
108
# File 'lib/docker/rails/cli/main.rb', line 105

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

#up(target) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/docker/rails/cli/main.rb', line 59

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

  invoke :before, [target], base_options

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

  app.up(compose_options)
end