Class: Mrsk::Commands::Accessory

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

Instance Attribute Summary collapse

Attributes inherited from Base

#config

Instance Method Summary collapse

Constructor Details

#initialize(config, name:) ⇒ Accessory

Returns a new instance of Accessory.



7
8
9
10
# File 'lib/mrsk/commands/accessory.rb', line 7

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.



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

def accessory_config
  @accessory_config
end

Instance Method Details

#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, "-t", "-n", "10", "-f", "2>&1"),
    ("grep '#{grep}'" if grep)
  ).join(" "), host: host
end

#infoObject



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

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), (" -n #{lines}" if lines), "-t", "2>&1"),
    ("grep '#{grep}'" if grep)
end

#remove_containerObject



49
50
51
# File 'lib/mrsk/commands/accessory.rb', line 49

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

#remove_imageObject



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

def remove_image
  docker :image, :prune, "-a", "-f", *service_filter
end

#runObject



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

def run
  docker :run, 
    "--name", service_name,
    "-d",
    "--restart", "unless-stopped",
    "-p", port,
    *env_args,
    *volume_args,
    *label_args,
    image
end

#startObject



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

def start
  docker :container, :start, service_name
end

#stopObject



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

def stop
  docker :container, :stop, service_name
end