Skip to content

Commit

Permalink
Revert "Docker: Support ARG FROM"
Browse files Browse the repository at this point in the history
This reverts commit b93ae98.
  • Loading branch information
mctofu committed Feb 22, 2022
1 parent 456cbfc commit 68f1409
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 48 deletions.
21 changes: 3 additions & 18 deletions docker/lib/dependabot/docker/file_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@ class FileParser < Dependabot::FileParsers::Base
# Details of Docker regular expressions is at
# https://github.com/docker/distribution/blob/master/reference/regexp.go
DOMAIN_COMPONENT =
/[[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]]/.freeze
/(?:[[:alnum:]]|[[:alnum:]][[[:alnum:]]-]*[[:alnum:]])/.freeze
DOMAIN = /(?:#{DOMAIN_COMPONENT}(?:\.#{DOMAIN_COMPONENT})+)/.freeze
REGISTRY = /(?<registry>#{DOMAIN}(?::\d+)?)/.freeze

NAME_COMPONENT = /[a-z\d]+(?:(?:[._]|__|[-]*)[a-z\d]+)*/.freeze
NAME_COMPONENT = /(?:[a-z\d]+(?:(?:[._]|__|[-]*)[a-z\d]+)*)/.freeze
IMAGE = %r{(?<image>#{NAME_COMPONENT}(?:/#{NAME_COMPONENT})*)}.freeze

ARG = /ARG/i.freeze
FROM = /FROM/i.freeze
PLATFORM = /--platform=(?<platform>\S+)/.freeze
PLATFORM = /--platform\=(?<platform>\S+)/.freeze
TAG = /:(?<tag>[\w][\w.-]{0,127})/.freeze
DIGEST = /@(?<digest>[^\s]+)/.freeze
NAME = /\s+AS\s+(?<name>[\w-]+)/.freeze
Expand All @@ -39,14 +38,7 @@ def parse
dependency_set = DependencySet.new

dockerfiles.each do |dockerfile|
args = {}
dockerfile.content.each_line do |line|
if ARG.match(line)
key_value = line.delete_prefix("ARG ").split("=")
args[key_value[0]] = key_value[1].delete_suffix("\n")
next
end
line = replace_args(line, args)
next unless FROM_LINE.match?(line)

parsed_from_line = FROM_LINE.match(line).named_captures
Expand Down Expand Up @@ -74,13 +66,6 @@ def parse

private

def replace_args(line, args)
line.gsub(/\${?\w+}?/) do |s|
escaped = s.delete_prefix("$").delete_prefix("{").delete_suffix("}")
args[escaped]
end
end

def dockerfiles
# The Docker file fetcher only fetches Dockerfiles, so no need to
# filter here
Expand Down
26 changes: 0 additions & 26 deletions docker/spec/dependabot/docker/file_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,32 +124,6 @@
end
end

context "arg from" do
let(:dockerfile_fixture_name) { "arg_from" }

describe "no curls" do
subject(:dependency) { dependencies.first }

it "can solve the dependency" do
expect(dependency).to be_a(Dependabot::Dependency)
expect(dependency.name).to eq("docker")
end
end
end

context "arg from" do
let(:dockerfile_fixture_name) { "arg_from_curls" }

describe "with curls" do
subject(:dependency) { dependencies.first }

it "can solve the dependency" do
expect(dependency).to be_a(Dependabot::Dependency)
expect(dependency.name).to eq("docker")
end
end
end

context "with a non-numeric version" do
let(:dockerfile_body) { "FROM ubuntu:artful" }

Expand Down
2 changes: 0 additions & 2 deletions docker/spec/fixtures/docker/dockerfiles/arg_from

This file was deleted.

2 changes: 0 additions & 2 deletions docker/spec/fixtures/docker/dockerfiles/arg_from_curls

This file was deleted.

0 comments on commit 68f1409

Please sign in to comment.