Class: Kamal::Commands::Traefik

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

Constant Summary collapse

DEFAULT_IMAGE =
"traefik:v2.9"
CONTAINER_PORT =
80
DEFAULT_ARGS =
{
  'log.level' => 'DEBUG'
}

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, #make_directory, #make_directory_for, #remove_directory, #run_over_ssh

Constructor Details

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

Instance Method Details

#env_fileObject



66
67
68
# File 'lib/kamal/commands/traefik.rb', line 66

def env_file
  Kamal::EnvFile.new(config.traefik.fetch("env", {}))
end

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



47
48
49
50
51
52
# File 'lib/kamal/commands/traefik.rb', line 47

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

#host_env_file_pathObject



70
71
72
# File 'lib/kamal/commands/traefik.rb', line 70

def host_env_file_path
  File.join host_env_directory, "traefik.env"
end

#infoObject



37
38
39
# File 'lib/kamal/commands/traefik.rb', line 37

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

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



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

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

#make_env_directoryObject



74
75
76
# File 'lib/kamal/commands/traefik.rb', line 74

def make_env_directory
  make_directory(host_env_directory)
end

#portObject



62
63
64
# File 'lib/kamal/commands/traefik.rb', line 62

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

#remove_containerObject



54
55
56
# File 'lib/kamal/commands/traefik.rb', line 54

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

#remove_env_fileObject



78
79
80
# File 'lib/kamal/commands/traefik.rb', line 78

def remove_env_file
  [:rm, "-f", host_env_file_path]
end

#remove_imageObject



58
59
60
# File 'lib/kamal/commands/traefik.rb', line 58

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

#runObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/kamal/commands/traefik.rb', line 10

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

#startObject



25
26
27
# File 'lib/kamal/commands/traefik.rb', line 25

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

#start_or_runObject



33
34
35
# File 'lib/kamal/commands/traefik.rb', line 33

def start_or_run
  combine start, run, by: "||"
end

#stopObject



29
30
31
# File 'lib/kamal/commands/traefik.rb', line 29

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