Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions docker/lib/dependabot/docker/update_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ module Dependabot
module Docker
class UpdateChecker < Dependabot::UpdateCheckers::Base
VERSION_REGEX =
/v?(?<version>[0-9]+(?:(?:\.[a-z0-9]+)|(?:-(?:kb)?[0-9]+))*)/i.freeze
VERSION_WITH_SFX = /^#{VERSION_REGEX}(?<suffix>-[a-z0-9.\-]+)?$/i.freeze
VERSION_WITH_PFX = /^(?<prefix>[a-z0-9.\-]+-)?#{VERSION_REGEX}$/i.freeze
VERSION_WITH_PFX_AND_SFX =
/^(?<prefix>[a-z\-]+-)?#{VERSION_REGEX}(?<suffix>-[a-z\-]+)?$/i.
freeze
/v?(?<version>[0-9]+(?:(?:\.[a-z0-9]+)|(?:-(?:kb)?[0-9]+)|(?:_[0-9]+))*)/i.freeze
PREFIX = /^(?<prefix>[a-z0-9.\-_]+(?:-|_))?/i.freeze
SUFFIX = /(?<suffix>(?:-|_)[a-z0-9.\-_]+)?$/i.freeze
VERSION_WITH_PFX = /#{PREFIX}#{VERSION_REGEX}$/i.freeze
VERSION_WITH_SFX = /^#{VERSION_REGEX}#{SUFFIX}/i.freeze
VERSION_WITH_PFX_AND_SFX = /#{PREFIX}#{VERSION_REGEX}#{SUFFIX}/i.freeze
NAME_WITH_VERSION =
/
#{VERSION_WITH_PFX}|
Expand Down Expand Up @@ -316,7 +316,7 @@ def prerelease?(tag)
def numeric_version_from(tag)
return unless tag.match?(NAME_WITH_VERSION)

tag.match(NAME_WITH_VERSION).named_captures.fetch("version").downcase
tag.match(NAME_WITH_VERSION).named_captures.fetch("version").downcase.gsub(/_/i, ".")
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a better place to handle this change would be in the version.rb file, as has been done for other languages like Gradle, but I wouldn't know how to do that.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @RodrigoPetter! I didn't see your PR in time and created a separate one at #5734. Coincidentally, I used the approach you mentioned here used for other ecosystems 👍.

Anyways, this PR was very useful and I reused part of the specs and added attribution to you in the commit ❤️.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow @deivid-rodriguez, thank you! I'm glad I could help.

Probably your PR fixes the original problem that I was facing. My PR doesn't seems necessary anymore.

I would prefer that, for more complex cases of non semver, it would be taken into consideration the cases in the issues #2692 and #4329.

With that in mind, I'm closing my PR.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! We'll try to keep improving things and you're welcome to keep sending us patches. We'll try to be more responsive next time!

end

def registry_hostname
Expand Down
53 changes: 53 additions & 0 deletions docker/spec/dependabot/docker/update_checker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,59 @@
it { is_expected.to eq("jdk-11.0.2.9-alpine-slim") }
end

context "when the dependencies have a underscore" do
let(:dependency_name) { "eclipse-temurin" }
let(:tags_fixture_name) { "eclipse-temurin.json" }
let(:repo_url) do
"https://registry.hub.docker.com/v2/library/eclipse-temurin/"
end
let(:headers_response) do
fixture("docker", "registry_manifest_headers", "ubuntu_17.10.json")
end
before do
stub_request(:get, repo_url + "tags/list").
and_return(status: 200, body: registry_tags)

stub_request(:head, repo_url + "manifests/#{version}").
and_return(
status: 200,
body: "",
headers: JSON.parse(headers_response)
)

# Stub the latest version to return a different digest
["17.0.2_8-jre-alpine", "latest", "prefix1_jre_11.0.16",
"11.0.16_suffix1_jre", "prefix2_jre_11.0.16_suffix2_jre"].each do |version|
stub_request(:head, repo_url + "manifests/#{version}").
and_return(
status: 200,
body: "",
headers: JSON.parse(headers_response.gsub("3ea1ca1", "4da71a2"))
)
end
end

context "followed by numbers" do
let(:version) { "17.0.1_12-jre-alpine" }
it { is_expected.to eq("17.0.2_8-jre-alpine") }
end

context "in the prefix" do
let(:version) { "prefix1_jre_11.0.14" }
it { is_expected.to eq("prefix1_jre_11.0.16") }
end

context "followed by letters (suffix)" do
let(:version) { "11.0.14_suffix1_jre" }
it { is_expected.to eq("11.0.16_suffix1_jre") }
end

context "in the prefix and suffix" do
let(:version) { "prefix2_jre_11.0.14_suffix2_jre" }
it { is_expected.to eq("prefix2_jre_11.0.16_suffix2_jre") }
end
end

context "when the dependency has a namespace" do
let(:dependency_name) { "moj/ruby" }
let(:tags_fixture_name) { "ruby.json" }
Expand Down
17 changes: 17 additions & 0 deletions docker/spec/fixtures/docker/registry_tags/eclipse-temurin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "library/eclipse-temurin",
"tags": [
"17.0.1_12-jre-windowsservercore-ltsc2022",
"17.0.2_8-jre-alpine",
"17.0.1_12-jre-alpine",
"17-jre-alpine",
"11.0.14_9-jre-alpine",
"11-jre-alpine",
"prefix1_jre_11.0.16",
"prefix1_jre_11.0.14",
"11.0.16_suffix1_jre",
"11.0.14_suffix1_jre",
"prefix2_jre_11.0.16_suffix2_jre",
"prefix2_jre_11.0.14_suffix2_jre"
]
}