From 2051b10ed0c1d83a2c04fc3f290a3c5738927341 Mon Sep 17 00:00:00 2001 From: Andrew Azores Date: Mon, 7 Nov 2022 10:55:32 -0500 Subject: [PATCH] docker support for Containerfile name --- docker/lib/dependabot/docker/file_fetcher.rb | 6 ++-- docker/lib/dependabot/docker/file_updater.rb | 4 +-- .../dependabot/docker/file_fetcher_spec.rb | 28 +++++++++++++++++++ .../github/contents_containerfile.json | 19 +++++++++++++ .../fixtures/github/contents_docker_repo.json | 16 +++++++++++ 5 files changed, 68 insertions(+), 5 deletions(-) create mode 100644 docker/spec/fixtures/github/contents_containerfile.json diff --git a/docker/lib/dependabot/docker/file_fetcher.rb b/docker/lib/dependabot/docker/file_fetcher.rb index 86fe86844e..874fd18b83 100644 --- a/docker/lib/dependabot/docker/file_fetcher.rb +++ b/docker/lib/dependabot/docker/file_fetcher.rb @@ -8,7 +8,7 @@ module Dependabot module Docker class FileFetcher < Dependabot::FileFetchers::Base YAML_REGEXP = /^[^\.]+\.ya?ml$/i - DOCKER_REGEXP = /dockerfile/i + DOCKER_REGEXP = /(docker|container)file/i HELM_REGEXP = /values[\-a-zA-Z_0-9]*\.yaml/i def self.required_files_in?(filenames) @@ -17,7 +17,7 @@ def self.required_files_in?(filenames) end 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 private @@ -41,7 +41,7 @@ def fetch_files elsif incorrectly_encoded_dockerfiles.none? && incorrectly_encoded_yamlfiles.none? raise( Dependabot::DependabotError, - "Found neither Kubernetes YAML nor Dockerfiles in #{directory}" + "Found neither Kubernetes YAML nor Dockerfiles nor Containerfiles in #{directory}" ) elsif incorrectly_encoded_dockerfiles.none? raise( diff --git a/docker/lib/dependabot/docker/file_updater.rb b/docker/lib/dependabot/docker/file_updater.rb index 05ab0a4d6a..b12e3d12b9 100644 --- a/docker/lib/dependabot/docker/file_updater.rb +++ b/docker/lib/dependabot/docker/file_updater.rb @@ -11,7 +11,7 @@ class FileUpdater < Dependabot::FileUpdaters::Base def self.updated_files_regex [ - /dockerfile/i, + /(docker|container)file/i, /^[^\.]+\.ya?ml/i ] end @@ -51,7 +51,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 def updated_dockerfile_content(file) diff --git a/docker/spec/dependabot/docker/file_fetcher_spec.rb b/docker/spec/dependabot/docker/file_fetcher_spec.rb index 983bbda888..4b96853d7b 100644 --- a/docker/spec/dependabot/docker/file_fetcher_spec.rb +++ b/docker/spec/dependabot/docker/file_fetcher_spec.rb @@ -72,6 +72,34 @@ 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 + context "with multiple Dockerfiles" do before do stub_request(:get, url + "?ref=sha"). diff --git a/docker/spec/fixtures/github/contents_containerfile.json b/docker/spec/fixtures/github/contents_containerfile.json new file mode 100644 index 0000000000..8343091591 --- /dev/null +++ b/docker/spec/fixtures/github/contents_containerfile.json @@ -0,0 +1,19 @@ +{ + "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\ncHQtZ2V0IGluc3RhbGwgLXkgLS1uby1pbnN0YWxsLXJlY29tbWVuZHMgXAog\nICAgICBidWlsZC1lc3NlbnRpYWwgXAogICAgICBkaXJtbmdyIFwKICAgICAg\nZ2l0IFwKICAgICAgZ251cGcyIFwKICAgICAgY3VybCBcCiAgICAgIHdnZXQg\nXAogICAgICB6bGliMWctZGV2IFwKICAgICAgbGlibHptYS1kZXYgXAogICAg\nICB0emRhdGEgXAogICAgICB6aXAgXAogICAgICB1bnppcCBcCiAgICAgIGxv\nY2FsZXMgXAogICAgICBvcGVuc3NoLWNsaWVudCBcCiAgICAgIG1ha2UgXAog\nICAgICBsaWJzc2wtZGV2IFwKICAgICAgbGliYnoyLWRldiBcCiAgICAgIGxp\nYnJlYWRsaW5lLWRldiBcCiAgICAgIGxpYnNxbGl0ZTMtZGV2IFwKICAgICAg\nbGx2bSBcCiAgICAgIGxpYm5jdXJzZXM1LWRldiBcCiAgICAgIGxpYm5jdXJz\nZXN3NS1kZXYgXAogICAgICBsaWJteXNxbGNsaWVudC1kZXYgXAogICAgICB4\nei11dGlscyBcCiAg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dXNyL2xvY2FsL2dyYWRsZSBcCiAgICAm\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" + } +} + diff --git a/docker/spec/fixtures/github/contents_docker_repo.json b/docker/spec/fixtures/github/contents_docker_repo.json index 421769e2d5..2c429ad96d 100644 --- a/docker/spec/fixtures/github/contents_docker_repo.json +++ b/docker/spec/fixtures/github/contents_docker_repo.json @@ -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",