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
|
# File 'lib/docktor_rails/checks/compose_entrypoint_exec.rb', line 13
def run(ctx)
root = ctx.fetch(:root)
platform = ctx[:platform]
if platform&.windows?
return pass("Windows host: skipping executable/shebang checks")
end
compose_path = Compose.find_file(root)
return pass("No compose file found (skipping entrypoint exec check)") unless compose_path
doc = Compose.load_file(compose_path)
services = Compose.services(doc)
entrypoint_files = services.flat_map do |_svc_name, svc|
next [] unless svc.is_a?(Hash)
ep = svc["entrypoint"]
ep = normalize_entrypoint(ep)
next [] unless ep
file = entrypoint_file_candidate(ep)
file ? [file] : []
end
entrypoint_files.uniq!
return pass("No entrypoint file paths detected") if entrypoint_files.empty?
problems = []
entrypoint_files.each do |file|
abs = File.expand_path(file, root)
next unless File.file?(abs)
problems << "#{file}: not executable" unless File.executable?(abs)
first = File.open(abs, "rb", &:readline) rescue ""
problems << "#{file}: missing shebang" unless first.start_with?("#!")
end
if problems.empty?
pass("Entrypoint executable/shebang OK")
else
fail("Entrypoint executable/shebang issues detected", files: problems)
end
end
|