Class: Mrsk::Commands::Accessory

Inherits:
Base
  • Object
show all
Defined in:
lib/mrsk/commands/accessory.rb

Constant Summary

Constants inherited from Base

Base::MAX_LOG_SIZE

Instance Attribute Summary collapse

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods inherited from Base

#container_id_for

Constructor Details

#initialize(config, name:) ⇒ Accessory

Returns a new instance of Accessory.



5
6
7
8
# File 'lib/mrsk/commands/accessory.rb', line 5

def initialize(config, name:)
  super(config)
  @accessory_config = config.accessory(name)
end

Instance Attribute Details

#accessory_configObject (readonly)

Returns the value of attribute accessory_config.



2
3
4
# File 'lib/mrsk/commands/accessory.rb', line 2

def accessory_config
  @accessory_config
end

Instance Method Details

#ensure_local_file_present(local_file) ⇒ Object



80
81
82
83
84
# File 'lib/mrsk/commands/accessory.rb', line 80

def ensure_local_file_present(local_file)
  if !local_file.is_a?(StringIO) && !Pathname.new(local_file).exist?
    raise "Missing file: #{local_file}"
  end
end

#execute_in_existing_container(*command, interactive: false) ⇒ Object



50
51
52
53
54
55
# File 'lib/mrsk/commands/accessory.rb', line 50

def execute_in_existing_container(*command, interactive: false)
  docker :exec,
    ("-it" if interactive),
    service_name,
    *command
end

#execute_in_existing_container_over_ssh(*command) ⇒ Object



67
68
69
# File 'lib/mrsk/commands/accessory.rb', line 67

def execute_in_existing_container_over_ssh(*command)
  run_over_ssh execute_in_existing_container(*command, interactive: true)
end

#execute_in_new_container(*command, interactive: false) ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'lib/mrsk/commands/accessory.rb', line 57

def execute_in_new_container(*command, interactive: false)
  docker :run,
    ("-it" if interactive),
    "--rm",
    *env_args,
    *volume_args,
    image,
    *command
end

#execute_in_new_container_over_ssh(*command) ⇒ Object



71
72
73
# File 'lib/mrsk/commands/accessory.rb', line 71

def execute_in_new_container_over_ssh(*command)
  run_over_ssh execute_in_new_container(*command, interactive: true)
end

#follow_logs(grep: nil) ⇒ Object



42
43
44
45
46
47
# File 'lib/mrsk/commands/accessory.rb', line 42

def follow_logs(grep: nil)
  run_over_ssh \
    pipe \
      docker(:logs, service_name, "--timestamps", "--tail", "10", "--follow", "2>&1"),
      (%(grep "#{grep}") if grep)
end

#infoObject



31
32
33
# File 'lib/mrsk/commands/accessory.rb', line 31

def info
  docker :ps, *service_filter
end

#logs(since: nil, lines: nil, grep: nil) ⇒ Object



36
37
38
39
40
# File 'lib/mrsk/commands/accessory.rb', line 36

def logs(since: nil, lines: nil, grep: nil)
  pipe \
    docker(:logs, service_name, (" --since #{since}" if since), (" --tail #{lines}" if lines), "--timestamps", "2>&1"),
    ("grep '#{grep}'" if grep)
end

#make_directory(path) ⇒ Object



90
91
92
# File 'lib/mrsk/commands/accessory.rb', line 90

def make_directory(path)
  [ :mkdir, "-p", path ]
end

#make_directory_for(remote_file) ⇒ Object



86
87
88
# File 'lib/mrsk/commands/accessory.rb', line 86

def make_directory_for(remote_file)
  make_directory Pathname.new(remote_file).dirname.to_s
end

#remove_containerObject



98
99
100
# File 'lib/mrsk/commands/accessory.rb', line 98

def remove_container
  docker :container, :prune, "--force", *service_filter
end

#remove_imageObject



102
103
104
# File 'lib/mrsk/commands/accessory.rb', line 102

def remove_image
  docker :image, :prune, "--all", "--force", *service_filter
end

#remove_service_directoryObject



94
95
96
# File 'lib/mrsk/commands/accessory.rb', line 94

def remove_service_directory
  [ :rm, "-rf", service_name ]
end

#runObject



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/mrsk/commands/accessory.rb', line 10

def run
  docker :run,
    "--name", service_name,
    "--detach",
    "--restart", "unless-stopped",
    "--log-opt", "max-size=#{MAX_LOG_SIZE}",
    "--publish", port,
    *env_args,
    *volume_args,
    *label_args,
    image
end

#run_over_ssh(command) ⇒ Object



75
76
77
# File 'lib/mrsk/commands/accessory.rb', line 75

def run_over_ssh(command)
  super command, host: host
end

#startObject



23
24
25
# File 'lib/mrsk/commands/accessory.rb', line 23

def start
  docker :container, :start, service_name
end

#stopObject



27
28
29
# File 'lib/mrsk/commands/accessory.rb', line 27

def stop
  docker :container, :stop, service_name
end