Class: Dev::Template::Docker::Default

Inherits:
BaseInterface show all
Defined in:
lib/firespring_dev_commands/templates/docker/default.rb

Overview

Class containing default rake tasks which are application agnostic (run against all containers)

Instance Method Summary collapse

Methods inherited from BaseInterface

#create_tasks!, #initialize

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



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

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) do
      LOG.debug('In base build')
      Dev::Docker::Compose.new.build
    end
  end
end

#create_clean_task! ⇒ Object

Create the rake task which runs a docker compose clean



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/firespring_dev_commands/templates/docker/default.rb', line 90

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) do
      LOG.debug 'In base clean'
      Dev::Docker.new.prune
      LOG.info
    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



60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/firespring_dev_commands/templates/docker/default.rb', line 60

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) do
      LOG.debug('In base down')
      Dev::Docker::Compose.new.down
    end
  end
end

#create_images_task! ⇒ Object

Create the rake task which shows all docker images on the system



139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/firespring_dev_commands/templates/docker/default.rb', line 139

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) do
      Dev::Docker.new.print_images
    end
  end
end

#create_logs_task! ⇒ Object

Create the rake task which runs a docker compose logs



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/firespring_dev_commands/templates/docker/default.rb', line 43

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) do
      LOG.debug('In base logs')
      Dev::Docker::Compose.new.logs
    end
  end
end

#create_ps_task! ⇒ Object

Create the rake task which shows all docker containers on the system



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

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) do
      Dev::Docker.new.print_containers
    end
  end
end

#create_pull_task! ⇒ Object

Create the rake task which runs a docker compose pull



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

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) do
      LOG.debug 'In base pull'
      Dev::Docker::Compose.new.pull
    end
  end
end

#create_push_task! ⇒ Object

Create the rake task which runs a docker compose push



109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/firespring_dev_commands/templates/docker/default.rb', line 109

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) do
      LOG.debug 'In base push'
      Dev::Docker::Compose.new.push
    end
  end
end

#create_reload_task! ⇒ Object

Create the rake task which runs a docker compose down followed by an up



76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/firespring_dev_commands/templates/docker/default.rb', line 76

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(down up) do
      LOG.debug('In reload')
    end
  end
end

#create_up_task! ⇒ Object

Create the rake task which runs a docker compose up



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/firespring_dev_commands/templates/docker/default.rb', line 27

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) do
      LOG.debug('In base up')
      Dev::Docker::Compose.new.up
    end
  end
end