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



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/firespring_dev_commands/templates/docker/application.rb', line 141

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



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/firespring_dev_commands/templates/docker/application.rb', line 122

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



222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/firespring_dev_commands/templates/docker/application.rb', line 222

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



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/firespring_dev_commands/templates/docker/application.rb', line 203

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



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/firespring_dev_commands/templates/docker/application.rb', line 186

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



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/firespring_dev_commands/templates/docker/application.rb', line 104

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



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/firespring_dev_commands/templates/docker/application.rb', line 167

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



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

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
    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



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/firespring_dev_commands/templates/docker/application.rb', line 66

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
    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



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/firespring_dev_commands/templates/docker/application.rb', line 47

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
    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
# 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
    end
  end
end