Class: Dev::Template::Docker::Default
- Inherits:
-
BaseInterface
- Object
- BaseInterface
- Dev::Template::Docker::Default
- Defined in:
- lib/firespring_dev_commands/templates/docker/default.rb
Overview
Class containing default rake tasks which are application agnostic This means the commands will be run against all containers in the docker compose file (no service specified)
Instance Attribute Summary
Attributes inherited from BaseInterface
Instance Method Summary collapse
-
#create_build_task! ⇒ Object
Create the rake task which runs a docker compose build.
-
#create_clean_task! ⇒ Object
Create the rake task which runs a docker compose clean.
-
#create_down_task! ⇒ Object
Create the rake task which runs a docker compose down.
-
#create_images_task! ⇒ Object
Create the rake task which shows all docker images on the system.
-
#create_logs_task! ⇒ Object
Create the rake task which runs a docker compose logs.
-
#create_ps_task! ⇒ Object
Create the rake task which shows all docker containers on the system.
-
#create_pull_task! ⇒ Object
Create the rake task which runs a docker compose pull.
-
#create_push_task! ⇒ Object
Create the rake task which runs a docker compose push.
-
#create_reload_task! ⇒ Object
Create the rake task which runs a docker compose down followed by an up.
-
#create_stop_task! ⇒ Object
Create the rake task which stops all running containers.
-
#create_up_task! ⇒ Object
Create the rake task which runs a docker compose up.
Methods inherited from BaseInterface
Constructor Details
This class inherits a constructor from Dev::Template::BaseInterface
Instance Method Details
#create_build_task! ⇒ Object
Create the rake task which runs a docker compose build
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/firespring_dev_commands/templates/docker/default.rb', line 11 def create_build_task! exclude = @exclude DEV_COMMANDS_TOP_LEVEL.instance_eval do return if exclude.include?(:build) desc 'Builds all images used by services in the compose files' \ "\n\toptionally specify NO_CACHE=true to not use build cache" \ "\n\toptionally specify PULL=true to force pulling new base images" task build: %w(init_docker _pre_build_hooks) do LOG.debug('In base build') Dev::Docker::Compose.new.build Rake::Task[:_post_build_hooks].execute end end end |
#create_clean_task! ⇒ Object
Create the rake task which runs a docker compose clean
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/firespring_dev_commands/templates/docker/default.rb', line 119 def create_clean_task! exclude = @exclude DEV_COMMANDS_TOP_LEVEL.instance_eval do return if exclude.include?(:clean) desc 'Removes all stopped containers and unused images, volumes, and networks' task clean: %w(init_docker _pre_clean_hooks) do LOG.debug 'In base clean' Dev::Docker.new.prune LOG.info Rake::Task[:_post_clean_hooks].execute end task prune: [:clean] do # This is an alias to the clean command end end end |
#create_down_task! ⇒ Object
Create the rake task which runs a docker compose down
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/firespring_dev_commands/templates/docker/default.rb', line 64 def create_down_task! exclude = @exclude DEV_COMMANDS_TOP_LEVEL.instance_eval do return if exclude.include?(:down) desc 'Stops and removes containers and associated resources' \ "\n\toptionally specify REMOVE_VOLUMES=true to also remove unused volumes" task down: %w(init_docker _pre_down_hooks) do LOG.debug('In base down') Dev::Docker::Compose.new.down Rake::Task[:_post_down_hooks].execute end end end |
#create_images_task! ⇒ Object
Create the rake task which shows all docker images on the system
171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/firespring_dev_commands/templates/docker/default.rb', line 171 def create_images_task! exclude = @exclude DEV_COMMANDS_TOP_LEVEL.instance_eval do return if exclude.include?(:images) desc 'Print a table of all images' \ "\n\t(equivalent to docker images)" task images: %w(init_docker _pre_images_hooks) do Dev::Docker.new.print_images Rake::Task[:_post_images_hooks].execute end end end |
#create_logs_task! ⇒ Object
Create the rake task which runs a docker compose logs
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/firespring_dev_commands/templates/docker/default.rb', line 46 def create_logs_task! exclude = @exclude DEV_COMMANDS_TOP_LEVEL.instance_eval do return if exclude.include?(:logs) desc 'Connects to the output stream of all running containers' \ "\n\toptionally specify NO_FOLLOW=true to print all current output and exit" \ "\n\toptionally specify TAIL=n to print the last 'n' lines of output" task logs: %w(init_docker _pre_logs_hooks) do LOG.debug('In base logs') Dev::Docker::Compose.new.logs Rake::Task[:_post_logs_hooks].execute end end end |
#create_ps_task! ⇒ Object
Create the rake task which shows all docker containers on the system
187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/firespring_dev_commands/templates/docker/default.rb', line 187 def create_ps_task! exclude = @exclude DEV_COMMANDS_TOP_LEVEL.instance_eval do return if exclude.include?(:ps) desc 'Print a table of all running containers' \ "\n\t(equivalent to docker ps)" task ps: %w(init_docker _pre_ps_hooks) do Dev::Docker.new.print_containers Rake::Task[:_post_ps_hooks].execute end end end |
#create_pull_task! ⇒ Object
Create the rake task which runs a docker compose pull
155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/firespring_dev_commands/templates/docker/default.rb', line 155 def create_pull_task! exclude = @exclude DEV_COMMANDS_TOP_LEVEL.instance_eval do return if exclude.include?(:pull) desc 'Pull all images from their defined image repository' task pull: %w(init_docker _pre_pull_hooks) do LOG.debug 'In base pull' Dev::Docker::Compose.new.pull Rake::Task[:_post_pull_hooks].execute end end end |
#create_push_task! ⇒ Object
Create the rake task which runs a docker compose push
139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/firespring_dev_commands/templates/docker/default.rb', line 139 def create_push_task! exclude = @exclude DEV_COMMANDS_TOP_LEVEL.instance_eval do return if exclude.include?(:push) desc 'Push all local images to their defined image repository' task push: %w(init_docker _pre_push_hooks) do LOG.debug 'In base push' Dev::Docker::Compose.new.push Rake::Task[:_post_push_hooks].execute end end end |
#create_reload_task! ⇒ Object
Create the rake task which runs a docker compose down followed by an up
105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/firespring_dev_commands/templates/docker/default.rb', line 105 def create_reload_task! exclude = @exclude DEV_COMMANDS_TOP_LEVEL.instance_eval do return if exclude.include?(:reload) desc 'Runs a "down" followed by an "up"' task reload: %w(_pre_reload_hooks down up) do Rake::Task[:_post_reload_hooks].execute end end end |
#create_stop_task! ⇒ Object
Create the rake task which stops all running containers
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/firespring_dev_commands/templates/docker/default.rb', line 81 def create_stop_task! exclude = @exclude DEV_COMMANDS_TOP_LEVEL.instance_eval do return if exclude.include?(:stop) desc 'Stops all running containers' task stop: %w(init_docker _pre_stop_hooks) do LOG.debug('In base stop') containers = ::Docker::Container.all(filters: {status: %w(restarting running)}.to_json) containers.each do |container| next if container&.info&.dig('Names')&.any? { |name| name.start_with?('/windows_tcp') } LOG.info "Stopping container #{container.id[0, 12]}" container.stop(timeout: 120) end Rake::Task[:_post_stop_hooks].execute end end end |
#create_up_task! ⇒ Object
Create the rake task which runs a docker compose up
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/firespring_dev_commands/templates/docker/default.rb', line 29 def create_up_task! exclude = @exclude DEV_COMMANDS_TOP_LEVEL.instance_eval do return if exclude.include?(:up) desc 'Starts containers for all services listed in the compose files' \ "\n\toptionally specify DETACHED=false to not detach from the started services" task up: %w(init_docker _pre_up_hooks) do LOG.debug('In base up') Dev::Docker::Compose.new.up Rake::Task[:_post_up_hooks].execute end end end |