Class: Dev::Template::Docker::Application

Inherits:
ApplicationInterface show all
Defined in:
lib/firespring_dev_commands/templates/docker/application.rb

Overview

Contains all default rake tasks for a docker application

Instance Attribute Summary

Attributes inherited from ApplicationInterface

#name

Attributes inherited from BaseInterface

#exclude

Instance Method Summary collapse

Methods inherited from ApplicationInterface

#initialize

Methods inherited from BaseInterface

#create_tasks!, #initialize

Constructor Details

This class inherits a constructor from Dev::Template::ApplicationInterface

Instance Method Details

#create_build_task!Object

Create the rake task which runs a docker compose build for the application name



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/firespring_dev_commands/templates/docker/application.rb', line 9

def create_build_task!
  application = @name
  exclude = @exclude

  DEV_COMMANDS_TOP_LEVEL.instance_eval do
    namespace application do
      return if exclude.include?(:build)

      desc "Builds the #{application} container"
      task build: %w(init_docker _pre_build_hooks) do
        LOG.debug "In #{application} build"
        Dev::Docker::Compose.new(services: [application]).build
        Rake::Task[:_post_build_hooks].execute
      end
    end
  end
end

#create_down_task!Object

Create the rake task which runs a docker compose down for the application name



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/firespring_dev_commands/templates/docker/application.rb', line 170

def create_down_task!
  application = @name
  exclude = @exclude

  DEV_COMMANDS_TOP_LEVEL.instance_eval do
    namespace application do
      return if exclude.include?(:down)

      desc "Shut down the #{application} container and remove associated resources"
      task down: %w(init_docker _pre_down_hooks) do
        LOG.debug "In #{application} down"

        # docker-copmose down shuts down everything (you can't only specify a single service)
        # therefore, stop the service manually and prune ununsed resources (just like a down would)
        Dev::Docker::Compose.new(services: [application]).stop
        Dev::Docker.new.prune_containers
        Dev::Docker.new.prune_networks
        Dev::Docker.new.prune_volumes if ENV['REMOVE_VOLUMES'].to_s.strip == 'true'
        Dev::Docker.new.prune_images
        Rake::Task[:_post_down_hooks].execute
      end
    end
  end
end

#create_logs_task!Object

Create the rake task which runs a docker compose logs for the application name



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/firespring_dev_commands/templates/docker/application.rb', line 151

def create_logs_task!
  application = @name
  exclude = @exclude

  DEV_COMMANDS_TOP_LEVEL.instance_eval do
    namespace application do
      return if exclude.include?(:logs)

      desc "Shows logs for the #{application} container"
      task logs: %w(init_docker _pre_logs_hooks) do
        LOG.debug "In #{application} logs"
        Dev::Docker::Compose.new(services: [application]).logs
        Rake::Task[:_post_logs_hooks].execute
      end
    end
  end
end

#create_pull_task!Object

Create the rake task which runs a docker compose pull for the application name



251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'lib/firespring_dev_commands/templates/docker/application.rb', line 251

def create_pull_task!
  application = @name
  exclude = @exclude

  DEV_COMMANDS_TOP_LEVEL.instance_eval do
    namespace application do
      return if exclude.include?(:pull)

      desc "Pull the #{application} container from the configured image repository"
      task pull: %w(init_docker _pre_pull_hooks) do
        LOG.debug "In #{application} pull"
        Dev::Docker::Compose.new(services: [application]).pull
        Rake::Task[:_post_pull_hooks].execute
      end
    end
  end
end

#create_push_task!Object

Create the rake task which runs a docker compose push for the application name



232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# File 'lib/firespring_dev_commands/templates/docker/application.rb', line 232

def create_push_task!
  application = @name
  exclude = @exclude

  DEV_COMMANDS_TOP_LEVEL.instance_eval do
    namespace application do
      return if exclude.include?(:push)

      desc "Push the #{application} container to the configured image repository"
      task push: %w(init_docker _pre_push_hooks) do
        LOG.debug "In #{application} push"
        Dev::Docker::Compose.new(services: [application]).push
        Rake::Task[:_post_push_hooks].execute
      end
    end
  end
end

#create_restart_task!Object

Create the rake task which stops, cleans, and starts the application



215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/firespring_dev_commands/templates/docker/application.rb', line 215

def create_restart_task!
  application = @name
  exclude = @exclude

  DEV_COMMANDS_TOP_LEVEL.instance_eval do
    namespace application do
      return if exclude.include?(:restart)

      desc "Reloads the #{application} container"
      task restart: %w(init_docker _pre_restart_hooks down up_no_deps) do
        Rake::Task[:_post_restart_hooks].execute
      end
    end
  end
end

#create_sh_task!Object

Create the rake task which runs a docker compose exec bash for the application name



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/firespring_dev_commands/templates/docker/application.rb', line 133

def create_sh_task!
  application = @name
  exclude = @exclude

  DEV_COMMANDS_TOP_LEVEL.instance_eval do
    namespace application do
      return if exclude.include?(:sh)

      desc "Open a shell into a running #{application} container"
      task sh: %W(init_docker #{application}:up_no_deps _pre_sh_hooks) do
        Dev::Docker::Compose.new(services: [application]).sh
        Rake::Task[:_post_sh_hooks].execute
      end
    end
  end
end

#create_stop_task!Object

Create the rake task which runs a docker compose stop for the application name



196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/firespring_dev_commands/templates/docker/application.rb', line 196

def create_stop_task!
  application = @name
  exclude = @exclude

  DEV_COMMANDS_TOP_LEVEL.instance_eval do
    namespace application do
      return if exclude.include?(:stop)

      desc "Stops the #{application} container"
      task stop: %w(init_docker _pre_stop_hooks) do
        LOG.debug "In #{application} stop"
        Dev::Docker::Compose.new(services: [application]).stop
        Rake::Task[:_post_stop_hooks].execute
      end
    end
  end
end

#create_up_empty_no_deps_task!Object

Create the rake task which starts a docker container with no dependencies for the application name which is not running anything



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/firespring_dev_commands/templates/docker/application.rb', line 106

def create_up_empty_no_deps_task!
  application = @name
  exclude = @exclude

  DEV_COMMANDS_TOP_LEVEL.instance_eval do
    namespace application do
      return if exclude.include?(:up_empty_no_deps)

      desc "Starts up an empty #{application} container but no dependencies"
      task up_empty_no_deps: %w(init_docker _pre_up_hooks) do
        LOG.debug "In #{application} up_empty_no_deps"
        Dev::Docker::Compose.new(services: [application], options: ['--no-deps', '--detach']).run(['sh', '-c', 'while [ true ]; do sleep 300; done;'])
        Rake::Task[:_post_up_hooks].execute
      end

      desc "Starts up an empty #{application} container silently but no dependencies"
      task up_empty_no_deps_silent: %w(init_docker _pre_up_hooks) do
        LOG.debug "In #{application} up_empty_no_deps_silent"
        Dev::Docker::Compose.new(running_silent: true, services: [application],
                                 options: ['--no-deps', '--detach']).run(['sh', '-c', 'while [ true ]; do sleep 300; done;'])
        Rake::Task[:_post_up_hooks].execute
      end
    end
  end
end

#create_up_empty_task!Object

Create the rake task which starts a docker container for the application name which is not running anything



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/firespring_dev_commands/templates/docker/application.rb', line 80

def create_up_empty_task!
  application = @name
  exclude = @exclude

  DEV_COMMANDS_TOP_LEVEL.instance_eval do
    namespace application do
      return if exclude.include?(:up_empty)

      desc "Starts up an empty #{application} container and it's dependencies"
      task up_empty: %w(init_docker _pre_up_hooks) do
        LOG.debug "In #{application} up_empty"
        Dev::Docker::Compose.new(services: [application], options: ['--detach']).run(['sh', '-c', 'while [ true ]; do sleep 300; done;'])
        Rake::Task[:_post_up_hooks].execute
      end

      desc "Starts up an empty #{application} container and it's dependencies silently"
      task up_empty_silent: %w(init_docker _pre_up_hooks) do
        LOG.debug "In #{application} up_empty_silent"
        Dev::Docker::Compose.new(running_silent: true, services: [application], options: ['--detach']).run(['sh', '-c', 'while [ true ]; do sleep 300; done;'])
        Rake::Task[:_post_up_hooks].execute
      end
    end
  end
end

#create_up_no_deps_task!Object

Create the rake task which runs a docker compose up –no-deps for the application name



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/firespring_dev_commands/templates/docker/application.rb', line 54

def create_up_no_deps_task!
  application = @name
  exclude = @exclude

  DEV_COMMANDS_TOP_LEVEL.instance_eval do
    namespace application do
      return if exclude.include?(:up_no_deps)

      desc "Starts up the #{application} container but no dependencies"
      task up_no_deps: %w(init_docker _pre_up_hooks) do
        LOG.debug "In #{application} up_no_deps"
        Dev::Docker::Compose.new(services: [application], options: ['--no-deps']).up
        Rake::Task[:_post_up_hooks].execute
      end

      desc "Starts up the #{application} container silently but no dependencies"
      task up_no_deps_silent: %w(init_docker _pre_up_hooks) do
        LOG.debug "In #{application} up_no_deps_silent"
        Dev::Docker::Compose.new(running_silent: true, services: [application], options: ['--no-deps']).up
        Rake::Task[:_post_up_hooks].execute
      end
    end
  end
end

#create_up_task!Object

Create the rake task which runs a docker compose up for the application name



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/firespring_dev_commands/templates/docker/application.rb', line 28

def create_up_task!
  application = @name
  exclude = @exclude

  DEV_COMMANDS_TOP_LEVEL.instance_eval do
    namespace application do
      return if exclude.include?(:up)

      desc "Starts up the #{application} container and it's dependencies"
      task up: %w(init_docker _pre_up_hooks) do
        LOG.debug "In #{application} up"
        Dev::Docker::Compose.new(services: [application]).up
        Rake::Task[:_post_up_hooks].execute
      end

      desc "Starts up the #{application} container and it's dependencies silently"
      task up_silent: %w(init_docker _pre_up_hooks) do
        LOG.debug "In #{application} up"
        Dev::Docker::Compose.new(running_silent: true, services: [application]).up
        Rake::Task[:_post_up_hooks].execute
      end
    end
  end
end