Class: Kamal::Lint::Checks::AccessoryImageLatest

Inherits:
Kamal::Lint::Check show all
Defined in:
lib/kamal/lint/checks/accessory_image_latest.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
32
33
34
35
36
37
# File 'lib/kamal/lint/checks/accessory_image_latest.rb', line 12

def call
  accessories = parsed["accessories"]
  return [] unless accessories.is_a?(Hash)

  findings = []
  accessories.each do |name, accessory|
    next unless accessory.is_a?(Hash)

    image = accessory["image"]
    next unless image.is_a?(String) && !image.empty?

    tag = image.split(":", 2)[1]
    if tag.nil?
      findings << finding(
        message: "accessory `#{name}` image `#{image}` has no tag; defaults to `:latest` and updates unexpectedly",
        line: context.line_for([ "accessories", name, "image" ])
      )
    elsif tag == "latest"
      findings << finding(
        message: "accessory `#{name}` image pinned to `:latest`; pin to a specific version to keep deploys reproducible",
        line: context.line_for([ "accessories", name, "image" ])
      )
    end
  end
  findings
end