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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/docktor_rails/checks/compose_entrypoint_sanity.rb', line 13
def run(ctx)
root = ctx.fetch(:root)
compose_path = Compose.find_file(root)
return pass("No compose file found (skipping entrypoint check)") unless compose_path
doc = Compose.load_file(compose_path)
services = Compose.services(doc)
entrypoints = services.flat_map do |svc_name, svc|
next [] unless svc.is_a?(Hash)
ep = svc["entrypoint"]
ep = normalize_entrypoint(ep)
next [] unless ep
[{ service: svc_name, entrypoint: ep }]
end
return pass("No compose entrypoints referenced") if entrypoints.empty?
failures = []
entrypoints.each do |ep|
file = entrypoint_file_candidate(ep.fetch(:entrypoint))
next unless file
abs = File.expand_path(file, root)
unless abs.start_with?(File.expand_path(root) + File::SEPARATOR)
failures << { file: file, message: "entrypoint points outside repo root" }
next
end
unless File.file?(abs)
failures << { file: file, message: "file not found" }
next
end
if File.binread(abs).include?("\r\n")
failures << { file: file, message: "CRLF line endings" }
end
end
if failures.empty?
pass("Entrypoint files look sane")
else
files = failures.map { |f| f.fetch(:file) }
fail("Compose entrypoint issues detected", files: files, hint: "Ensure entrypoint scripts exist and use LF line endings (not CRLF).")
end
end
|