Class: Mrsk::Commands::Traefik

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

Constant Summary collapse

DEFAULT_IMAGE =
"traefik:v2.9"
CONTAINER_PORT =
80

Constants inherited from Base

Base::DOCKER_HEALTH_LOG_FORMAT, Base::DOCKER_HEALTH_STATUS_FORMAT

Instance Attribute Summary

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods inherited from Base

#container_id_for, #initialize, #run_over_ssh

Constructor Details

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

Instance Method Details

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



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

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

#infoObject



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

def info
  docker :ps, "--filter", "name=^traefik$"
end

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



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

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

#portObject



56
57
58
# File 'lib/mrsk/commands/traefik.rb', line 56

def port
  "#{host_port}:#{CONTAINER_PORT}"
end

#remove_containerObject



48
49
50
# File 'lib/mrsk/commands/traefik.rb', line 48

def remove_container
  docker :container, :prune, "--force", "--filter", "label=org.opencontainers.image.title=Traefik"
end

#remove_imageObject



52
53
54
# File 'lib/mrsk/commands/traefik.rb', line 52

def remove_image
  docker :image, :prune, "--all", "--force", "--filter", "label=org.opencontainers.image.title=Traefik"
end

#runObject



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

def run
  docker :run, "--name traefik",
    "--detach",
    "--restart", "unless-stopped",
    "--publish", port,
    "--volume", "/var/run/docker.sock:/var/run/docker.sock",
    *env_args,
    *config.logging_args,
    *label_args,
    *docker_options_args,
    image,
    "--providers.docker",
    "--log.level=DEBUG",
    *cmd_option_args
end

#startObject



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

def start
  docker :container, :start, "traefik"
end

#stopObject



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

def stop
  docker :container, :stop, "traefik"
end