Class: Kamal::Lint::Checks::RegistryWithoutExplicitServer

Inherits:
Kamal::Lint::Check show all
Defined in:
lib/kamal/lint/checks/registry_without_explicit_server.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

#callObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/kamal/lint/checks/registry_without_explicit_server.rb', line 12

def call
  registry = parsed["registry"] || parsed.dig("builder", "registry")
  return [] unless registry.is_a?(Hash)

  server = registry["server"]
  return [] if server.is_a?(String) && !server.empty?

  image = parsed["image"]
  # If image already has an explicit registry prefix (host with a "."),
  # this is intentional and we don't warn.
  if image.is_a?(String) && image.include?("/")
    first_segment = image.split("/", 2).first
    return [] if first_segment.include?(".") || first_segment.include?(":")
  end

  [ finding(
    message: "registry has no `server:` set; Kamal will push/pull from Docker Hub by default",
    line: context.line_for([ "registry" ]) || context.line_for([ "registry", "username" ])
  ) ]
end