Class: Dependabot::Docker::FileParser

Inherits:
FileParsers::Base
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dependabot/docker/file_parser.rb

Constant Summary collapse

YAML_REGEXP =
/^[^\.].*\.ya?ml$/i
DOMAIN_COMPONENT =

Details of Docker regular expressions is at github.com/docker/distribution/blob/master/reference/regexp.go

/(?:[[:alnum:]]|[[:alnum:]][[[:alnum:]]-]*[[:alnum:]])/
DOMAIN =
/(?:#{DOMAIN_COMPONENT}(?:\.#{DOMAIN_COMPONENT})+)/
REGISTRY =
/(?<registry>#{DOMAIN}(?::\d+)?)/
NAME_COMPONENT =
/(?:[a-z\d]+(?:(?:[._]|__|[-]*)[a-z\d]+)*)/
IMAGE =
%r{(?<image>#{NAME_COMPONENT}(?:/#{NAME_COMPONENT})*)}
FROM =
/FROM/i
PLATFORM =
/--platform\=(?<platform>\S+)/
TAG_NO_PREFIX =
/(?<tag>[\w][\w.-]{0,127})/
TAG =
/:#{TAG_NO_PREFIX}/
DIGEST =
/(?<digest>[0-9a-f]{64})/
NAME =
/\s+AS\s+(?<name>[\w-]+)/
FROM_LINE =
%r{^#{FROM}\s+(#{PLATFORM}\s+)?(#{REGISTRY}/)?
#{IMAGE}#{TAG}?(?:@sha256:#{DIGEST})?#{NAME}?}x
TAG_WITH_DIGEST =
/^#{TAG_NO_PREFIX}(?:@sha256:#{DIGEST})?/x
AWS_ECR_URL =
/dkr\.ecr\.(?<region>[^.]+)\.amazonaws\.com/
IMAGE_SPEC =
%r{^(#{REGISTRY}/)?#{IMAGE}#{TAG}?(?:@sha256:#{DIGEST})?#{NAME}?}x

Instance Method Summary collapse

Instance Method Details

#parseObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/dependabot/docker/file_parser.rb', line 46

def parse
  dependency_set = DependencySet.new

  dockerfiles.each do |dockerfile|
    T.must(dockerfile.content).each_line do |line|
      next unless FROM_LINE.match?(line)

      parsed_from_line = T.must(FROM_LINE.match(line)).named_captures
      parsed_from_line["registry"] = nil if parsed_from_line["registry"] == "docker.io"

      version = version_from(parsed_from_line)
      next unless version

      dependency_set << Dependency.new(
        name: T.must(parsed_from_line.fetch("image")),
        version: version,
        package_manager: "docker",
        requirements: [
          requirement: nil,
          groups: [],
          file: dockerfile.name,
          source: source_from(parsed_from_line)
        ]
      )
    end
  end

  manifest_files.each do |file|
    dependency_set += workfile_file_dependencies(file)
  end

  dependency_set.dependencies
end