Class: RubyYacht::Runner::Implode

Inherits:
Command
  • Object
show all
Defined in:
lib/ruby_yacht/runner/implode.rb

Overview

This class provides a command for destroying the local docker environment.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Command

#backtick, #default_project, #docker, #get_machine_info, #log, #option_parser, #parse_positional_arguments, #project_named, #projects, short_script_name, #system

Class Method Details

.commandObject

The name of the command.


5
# File 'lib/ruby_yacht/runner/implode.rb', line 5

def self.command; 'implode'; end

.descriptionObject

The description of the command.


8
9
10
# File 'lib/ruby_yacht/runner/implode.rb', line 8

def self.description
  "Destroy your local environment"
end

Instance Method Details

#runObject

This method runs the logic of the command.


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ruby_yacht/runner/implode.rb', line 13

def run
  projects.each do |project|
    system_prefix = project.system_prefix
  
    machines = backtick("docker ps -a | grep #{system_prefix}").split("\n").map { |line| line.split(/\s+/)[0] }
    machines.each do |machine|
      docker "rm -f #{machine}"
    end
  
    images = backtick("docker images | grep #{system_prefix}").split("\n").map { |line| line.split(/\s+/)[0] }
    images.each do |image|
      docker "rmi #{image}"
    end
  end

  backtick("docker images -q --filter dangling=true").split("\n").each do |image|
    docker "rmi #{image}"
  end
end