Class: Mrsk::Commands::App

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

Instance Attribute Summary

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Mrsk::Commands::Base

Instance Method Details

#bash(host:) ⇒ Object



79
80
81
# File 'lib/mrsk/commands/app.rb', line 79

def bash(host:)
  exec_over_ssh "bash", host: host
end

#console(host:) ⇒ Object



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

def console(host:)
  exec_over_ssh "bin/rails", "c", host: host
end

#current_container_idObject



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

def current_container_id
  docker :ps, "-q", *service_filter
end

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



42
43
44
45
46
47
48
49
50
# File 'lib/mrsk/commands/app.rb', line 42

def exec(*command, interactive: false)
  docker :exec,
    ("-it" if interactive),
    *rails_master_key_arg,
    *config.env_args,
    *config.volume_args,
    config.service_with_version,
    *command
end

#exec_over_ssh(*command, host:) ⇒ Object



63
64
65
# File 'lib/mrsk/commands/app.rb', line 63

def exec_over_ssh(*command, host:)
  run_over_ssh run_exec(*command, interactive: true).join(" "), host: host
end

#follow_logs(host:, grep: nil) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/mrsk/commands/app.rb', line 67

def follow_logs(host:, grep: nil)
  run_over_ssh pipe(
    current_container_id,
    "xargs docker logs -t -n 10 -f 2>&1",
    ("grep '#{grep}'" if grep)
  ).join(" "), host: host
end

#infoObject



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

def info
  docker :ps, *service_filter
end

#list_containersObject



83
84
85
# File 'lib/mrsk/commands/app.rb', line 83

def list_containers
  docker :container, :ls, "-a", *service_filter
end

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



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

def logs(since: nil, lines: nil, grep: nil)
  pipe \
    current_container_id,
    "xargs docker logs#{" --since #{since}" if since}#{" -n #{lines}" if lines} -t 2>&1",
    ("grep '#{grep}'" if grep)
end

#remove_containersObject



87
88
89
# File 'lib/mrsk/commands/app.rb', line 87

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

#remove_imagesObject



91
92
93
# File 'lib/mrsk/commands/app.rb', line 91

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

#run(role: :web) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/mrsk/commands/app.rb', line 4

def run(role: :web)
  role = config.role(role)

  docker :run,
    "-d",
    "--restart unless-stopped",
    "--name", config.service_with_version,
    *rails_master_key_arg,
    *role.env_args,
    *config.volume_args,
    *role.label_args,
    config.absolute_image,
    role.cmd
end

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



52
53
54
55
56
57
58
59
60
61
# File 'lib/mrsk/commands/app.rb', line 52

def run_exec(*command, interactive: false)
  docker :run,
    ("-it" if interactive),
    "--rm",
    *rails_master_key_arg,
    *config.env_args,
    *config.volume_args,
    config.absolute_image,
    *command
end

#start(version: config.version) ⇒ Object



19
20
21
# File 'lib/mrsk/commands/app.rb', line 19

def start(version: config.version)
  docker :start, "#{config.service}-#{version}"
end

#stopObject



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

def stop
  pipe current_container_id, "xargs docker stop"
end