Class: DocktorRails::Checks::ComposeBuildPaths

Inherits:
BaseCheck
  • Object
show all
Defined in:
lib/docktor_rails/checks/compose_build_paths.rb

Instance Method Summary collapse

Methods inherited from BaseCheck

#name

Instance Method Details

#idObject



9
10
11
# File 'lib/docktor_rails/checks/compose_build_paths.rb', line 9

def id
  "compose.build_paths"
end

#run(ctx) ⇒ Object



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
# File 'lib/docktor_rails/checks/compose_build_paths.rb', line 13

def run(ctx)
  root = ctx.fetch(:root)
  compose_path = Compose.find_file(root)
  return pass("No compose file found (skipping build path check)") unless compose_path

  doc = Compose.load_file(compose_path)
  services = Compose.services(doc)

  problems = []

  services.each do |svc_name, svc|
    next unless svc.is_a?(Hash)

    build = svc["build"]
    next if build.nil?

    context, dockerfile = extract_build(build)
    context ||= "."

    context_abs = File.expand_path(context, root)
    unless Dir.exist?(context_abs)
      problems << "#{svc_name}: build.context missing (#{context})"
      next
    end

    dockerfile ||= "Dockerfile"
    dockerfile_abs = File.expand_path(dockerfile, context_abs)
    unless File.file?(dockerfile_abs)
      problems << "#{svc_name}: build.dockerfile missing (#{File.join(context, dockerfile)})"
    end
  end

  if problems.empty?
    pass("Compose build paths look valid")
  else
    fail("Compose build path issues detected", files: problems)
  end
end