Class: Kamal::Cli::Traefik

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

Instance Method Summary collapse

Methods inherited from Base

exit_on_failure?, #initialize

Constructor Details

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

Instance Method Details

#bootObject



3
4
5
6
7
8
9
10
# File 'lib/kamal/cli/traefik.rb', line 3

def boot
  with_lock do
    on(KAMAL.traefik_hosts) do
      execute *KAMAL.registry.
      execute *KAMAL.traefik.start_or_run
    end
  end
end

#detailsObject



64
65
66
# File 'lib/kamal/cli/traefik.rb', line 64

def details
  on(KAMAL.traefik_hosts) { |host| puts_by_host host, capture_with_info(*KAMAL.traefik.info), type: "Traefik" }
end

#downgradeObject



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/kamal/cli/traefik.rb', line 126

def downgrade
  invoke_options = { "version" => KAMAL.config.latest_tag }.merge(options)

  confirming "This will cause a brief outage on each host. Are you sure?" do
    host_groups = options[:rolling] ? KAMAL.hosts : [ KAMAL.hosts ]
    host_groups.each do |hosts|
      host_list = Array(hosts).join(",")
      say "Downgrading to Traefik on #{host_list}...", :magenta
      run_hook "pre-traefik-reboot", hosts: host_list
      on(hosts) do |host|
        execute *KAMAL.auditor.record("Rebooted Traefik"), verbosity: :debug
        execute *KAMAL.registry.

        "Stopping and removing kamal-proxy on #{host}, if running..."
        execute *KAMAL.traefik.cleanup_kamal_proxy

        "Stopping and removing Traefik on #{host}, if running..."
        execute *KAMAL.traefik.stop, raise_on_non_zero_exit: false
        execute *KAMAL.traefik.remove_container
        execute *KAMAL.traefik.remove_image
      end

      KAMAL.with_specific_hosts(hosts) do
        invoke "kamal:cli:traefik:boot", [], invoke_options
        reset_invocation(Kamal::Cli::Traefik)
        invoke "kamal:cli:app:boot", [], invoke_options
        reset_invocation(Kamal::Cli::App)
        invoke "kamal:cli:prune:all", [], invoke_options
        reset_invocation(Kamal::Cli::Prune)
      end

      run_hook "post-traefik-reboot", hosts: host_list
      say "Downgraded to Traefik on #{host_list}", :magenta
    end
  end
end

#logsObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/kamal/cli/traefik.rb', line 74

def logs
  grep = options[:grep]
  grep_options = options[:grep_options]

  if options[:follow]
    run_locally do
      info "Following logs on #{KAMAL.primary_host}..."
      info KAMAL.traefik.follow_logs(host: KAMAL.primary_host, grep: grep, grep_options: grep_options)
      exec KAMAL.traefik.follow_logs(host: KAMAL.primary_host, grep: grep, grep_options: grep_options)
    end
  else
    since = options[:since]
    lines = options[:lines].presence || ((since || grep) ? nil : 100) # Default to 100 lines if since or grep isn't set

    on(KAMAL.traefik_hosts) do |host|
      puts_by_host host, capture(*KAMAL.traefik.logs(since: since, lines: lines, grep: grep, grep_options: grep_options)), type: "Traefik"
    end
  end
end

#rebootObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/kamal/cli/traefik.rb', line 15

def reboot
  confirming "This will cause a brief outage on each host. Are you sure?" do
    with_lock do
      host_groups = options[:rolling] ? KAMAL.traefik_hosts : [ KAMAL.traefik_hosts ]
      host_groups.each do |hosts|
        host_list = Array(hosts).join(",")
        run_hook "pre-traefik-reboot", hosts: host_list
        on(hosts) do
          execute *KAMAL.auditor.record("Rebooted traefik"), verbosity: :debug
          execute *KAMAL.registry.
          execute *KAMAL.traefik.stop, raise_on_non_zero_exit: false
          execute *KAMAL.traefik.remove_container
          execute *KAMAL.traefik.run
        end
        run_hook "post-traefik-reboot", hosts: host_list
      end
    end
  end
end

#removeObject



95
96
97
98
99
100
101
# File 'lib/kamal/cli/traefik.rb', line 95

def remove
  with_lock do
    stop
    remove_container
    remove_image
  end
end

#remove_containerObject



104
105
106
107
108
109
110
111
# File 'lib/kamal/cli/traefik.rb', line 104

def remove_container
  with_lock do
    on(KAMAL.traefik_hosts) do
      execute *KAMAL.auditor.record("Removed traefik container"), verbosity: :debug
      execute *KAMAL.traefik.remove_container
    end
  end
end

#remove_imageObject



114
115
116
117
118
119
120
121
# File 'lib/kamal/cli/traefik.rb', line 114

def remove_image
  with_lock do
    on(KAMAL.traefik_hosts) do
      execute *KAMAL.auditor.record("Removed traefik image"), verbosity: :debug
      execute *KAMAL.traefik.remove_image
    end
  end
end

#restartObject



56
57
58
59
60
61
# File 'lib/kamal/cli/traefik.rb', line 56

def restart
  with_lock do
    stop
    start
  end
end

#startObject



36
37
38
39
40
41
42
43
# File 'lib/kamal/cli/traefik.rb', line 36

def start
  with_lock do
    on(KAMAL.traefik_hosts) do
      execute *KAMAL.auditor.record("Started traefik"), verbosity: :debug
      execute *KAMAL.traefik.start
    end
  end
end

#stopObject



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

def stop
  with_lock do
    on(KAMAL.traefik_hosts) do
      execute *KAMAL.auditor.record("Stopped traefik"), verbosity: :debug
      execute *KAMAL.traefik.stop, raise_on_non_zero_exit: false
    end
  end
end