Class: Kamal::Lint::Checks::TraefikLegacyKeys

Inherits:
Kamal::Lint::Check show all
Defined in:
lib/kamal/lint/checks/traefik_legacy_keys.rb

Instance Attribute Summary

Attributes inherited from Kamal::Lint::Check

#context

Instance Method Summary collapse

Methods inherited from Kamal::Lint::Check

applies_to?, autofixable, id, #initialize, severity, since, title, until_version

Constructor Details

This class inherits a constructor from Kamal::Lint::Check

Instance Method Details

#apply_fix(ctx) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/kamal/lint/checks/traefik_legacy_keys.rb', line 23

def apply_fix(ctx)
  file = ctx.file_for_finding
  text = File.read(file)
  parsed = YAML.safe_load(text, aliases: true) || {}
  return false unless parsed.is_a?(Hash) && parsed.key?("traefik")

  traefik = parsed.delete("traefik") || {}
  proxy = parsed["proxy"] || {}

  # Conservative translation:
  # - traefik.host           → proxy.host
  # - traefik.ssl_redirect   → proxy.ssl: true (Kamal 2 handles SSL via proxy.ssl)
  # - traefik.args.entryPoints.address: ":<port>" → proxy.app_port: <port>
  if (host = traefik["host"]) && !proxy["host"]
    proxy["host"] = host
  end
  if traefik["ssl_redirect"] == true || traefik.dig("args", "entrypoints.websecure.address")
    proxy["ssl"] = true unless proxy.key?("ssl")
  end
  if (addr = traefik.dig("args", "entrypoints.web.address")) && addr.is_a?(String)
    port = addr.scan(/\d+/).first
    proxy["app_port"] = port.to_i if port && !proxy.key?("app_port")
  end

  parsed["proxy"] = proxy unless proxy.empty?
  File.write(file, YAML.dump(parsed))
  true
rescue => _e
  false
end

#callObject



13
14
15
16
17
18
19
20
21
# File 'lib/kamal/lint/checks/traefik_legacy_keys.rb', line 13

def call
  return [] unless parsed.key?("traefik")

  [ finding(
    message: "`traefik:` block is Kamal 1.x legacy and is ignored in Kamal 2+; use `proxy:` instead",
    line: context.line_for([ "traefik" ]),
    autofix: method(:apply_fix)
  ) ]
end