Skip to content

Commit

Permalink
the changes in the other PR are useful to make our support for contai…
Browse files Browse the repository at this point in the history
…nerFiles more robust.
  • Loading branch information
randhircs committed Dec 17, 2024
1 parent d7e0824 commit 6c9a5ff
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 4 deletions.
4 changes: 2 additions & 2 deletions docker/lib/dependabot/docker/file_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class FileFetcher < Dependabot::FileFetchers::Base
extend T::Helpers

YAML_REGEXP = /^[^\.].*\.ya?ml$/i
DOCKER_REGEXP = /dockerfile|containerfile/i
DOCKER_REGEXP = /(docker|container)file/i

sig { override.params(filenames: T::Array[String]).returns(T::Boolean) }
def self.required_files_in?(filenames)
Expand All @@ -23,7 +23,7 @@ def self.required_files_in?(filenames)

sig { override.returns(String) }
def self.required_files_message
"Repo must contain a Dockerfile or Kubernetes YAML files."
"Repo must contain a Dockerfile, Containerfile, or Kubernetes YAML files."
end

sig { override.returns(T::Array[DependencyFile]) }
Expand Down
4 changes: 2 additions & 2 deletions docker/lib/dependabot/docker/file_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class FileUpdater < Dependabot::FileUpdaters::Base
FROM_REGEX = /FROM(\s+--platform\=\S+)?/i

YAML_REGEXP = /^[^\.].*\.ya?ml$/i
DOCKER_REGEXP = /dockerfile/i
DOCKER_REGEXP = /(docker|container)file/i

sig { override.returns(T::Array[Regexp]) }
def self.updated_files_regex
Expand Down Expand Up @@ -63,7 +63,7 @@ def check_required_files
# Just check if there are any files at all.
return if dependency_files.any?

raise "No Dockerfile!"
raise "No Dockerfile or Containerfile!"
end

sig { params(file: Dependabot::DependencyFile).returns(String) }
Expand Down
28 changes: 28 additions & 0 deletions docker/spec/dependabot/docker/file_fetcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -323,5 +323,33 @@
.to match_array(matching_filenames)
end
end

context "with a Containerfile" do
before do
stub_request(:get, url + "?ref=sha").
with(headers: { "Authorization" => "token token" }).
to_return(
status: 200,
body: fixture("github", "contents_docker_repo.json"),
headers: { "content-type" => "application/json" }
)

stub_request(:get, File.join(url, "Dockerfile?ref=sha")).
with(headers: { "Authorization" => "token token" }).
to_return(
status: 200,
body: dockerfile_fixture,
headers: { "content-type" => "application/json" }
)
end

let(:dockerfile_fixture) { fixture("github", "contents_containerfile.json") }

it "fetches the Containerfile" do
expect(file_fetcher_instance.files.count).to eq(1)
expect(file_fetcher_instance.files.map(&:name)).
to match_array(%w(Containerfile))
end
end
end
end
18 changes: 18 additions & 0 deletions docker/spec/fixtures/github/contents_containerfile.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "Containerfile",
"path": "Containerfile",
"sha": "311f9743315183cc6751313cb251cfeb3de45c1a",
"size": 4927,
"url": "https://api.github.com/repos/dependabot/dependabot-core/contents/Containerfile?ref=master",
"html_url": "https://github.com/dependabot/dependabot-core/blob/main/Containerfile",
"git_url": "https://api.github.com/repos/dependabot/dependabot-core/git/blobs/311f9743315183cc6751313cb251cfeb3de45c1a",
"download_url": "https://raw.githubusercontent.com/dependabot/dependabot-core/master/Containerfile",
"type": "file",
"content": "RlJPTSB1YnVudHU6MTguMDQKCiMjIyBTWVNURU0gREVQRU5ERU5DSUVTCgoj\nIEV2ZXJ5dGhpbmcgZnJvbSBgbWFrZWAgb253YXJkcyBpbiBhcHQtZ2V0IGlu\nc3RhbGwgaXMgb25seSBpbnN0YWxsZWQgdG8gZW5zdXJlCiMgUHl0aG9uIHN1\ncHBvcnQgd29ya3Mgd2l0aCBhbGwgcGFja2FnZXMgKHdoaWNoIG1heSByZXF1\naXJlIHNwZWNpZmljIGxpYnJhcmllcwojIGF0IGluc3RhbGwgdGltZSkuCkVO\nViBERUJJQU5fRlJPTlRFTkQgbm9uaW50ZXJhY3RpdmUKUlVOIGFwdC1nZXQg\ndXBkYXRlIFwKICAgICYmIGFwdC1nZXQgdXBncmFkZSAteSBcCiAgICAmJiBh\ncHQ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bCAteSBvcmFj\nbGUtamF2YTgtaW5zdGFsbGVyIG9yYWNsZS1qYXZhOC1zZXQtZGVmYXVsdCBc\nCiAgICAmJiBjZCAvdG1wIFwKICAgICYmIHdnZXQgaHR0cDovL2RsLmJpbnRy\nYXkuY29tL2dyb292eS9tYXZlbi9hcGFjaGUtZ3Jvb3Z5LWJpbmFyeS0yLjUu\nMi56aXAgXAogICAgJiYgdW56aXAgYXBhY2hlLWdyb292eS1iaW5hcnktMi41\nLjIuemlwIFwKICAgICYmIG12IGdyb292eS0yLjUuMiAvdXNyL2xvY2FsL2dy\nb292eSBcCiAgICAmJiBybSAtZiBhcGFjaGUtZ3Jvb3Z5LWJpbmFyeS0yLjUu\nMi56aXAgXAogICAgJiYgY2QgL3RtcCBcCiAgICAmJiB3Z2V0IGh0dHBzOi8v\nc2VydmljZXMuZ3JhZGxlLm9yZy9kaXN0cmlidXRpb25zL2dyYWRsZS00Ljkt\nYmluLnppcCBcCiAgICAmJiB1bnppcCBncmFkbGUtNC45LWJpbi56aXAgXAog\nICAgJiYgbXYgZ3JhZGxlLTQuOSAvdXNyL2xvY2FsL2dyYWRsZSBcCiAgICAm\nJiBybSAtZiBncmFkbGUtNC45LWJpbi56aXAKRU5WIEpBVkFfSE9NRT0vdXNy\nL2xpYi9qdm0vamF2YS04LW9yYWNsZSBcCiAgICBHUk9PVllfSE9NRT0vdXNy\nL2xvY2FsL2dyb292eSBcCiAgICBHUkFETEVfSE9NRT0vdXNyL2xvY2FsL2dy\nYWRsZSBcCiAgICBQQVRIPS91c3IvbG9jYWwvZ3Jvb3Z5L2Jpbi86L3Vzci9s\nb2NhbC9ncmFkbGUvYmluOiRQQVRICg==\n",
"encoding": "base64",
"_links": {
"self": "https://api.github.com/repos/dependabot/dependabot-core/contents/Containerfile?ref=master",
"git": "https://api.github.com/repos/dependabot/dependabot-core/git/blobs/311f9743315183cc6751313cb251cfeb3de45c1a",
"html": "https://github.com/dependabot/dependabot-core/blob/main/Containerfile"
}
}
16 changes: 16 additions & 0 deletions docker/spec/fixtures/github/contents_docker_repo.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,22 @@
"html": "https://github.com/dependabot/dependabot-core/blob/main/Dockerfile"
}
},
{
"name": "Containerfile",
"path": "Containerfile",
"sha": "311f9743315183cc6751313cb251cfeb3de45c1a",
"size": 4927,
"url": "https://api.github.com/repos/dependabot/dependabot-core/contents/Containerfile?ref=master",
"html_url": "https://github.com/dependabot/dependabot-core/blob/main/Containerfile",
"git_url": "https://api.github.com/repos/dependabot/dependabot-core/git/blobs/311f9743315183cc6751313cb251cfeb3de45c1a",
"download_url": "https://raw.githubusercontent.com/dependabot/dependabot-core/master/Containerfile",
"type": "file",
"_links": {
"self": "https://api.github.com/repos/dependabot/dependabot-core/contents/Containerfile?ref=master",
"git": "https://api.github.com/repos/dependabot/dependabot-core/git/blobs/311f9743315183cc6751313cb251cfeb3de45c1a",
"html": "https://github.com/dependabot/dependabot-core/blob/main/Containerfile"
}
},
{
"name": "Gemfile",
"path": "Gemfile",
Expand Down

0 comments on commit 6c9a5ff

Please sign in to comment.