Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the correct Docker digest when checking for updates #3060

Merged
merged 1 commit into from
Feb 4, 2021
Merged
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
26 changes: 25 additions & 1 deletion docker/lib/dependabot/docker/update_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,29 @@
require "dependabot/docker/requirement"
require "dependabot/docker/utils/credentials_finder"

module DockerRegistry2
jurre marked this conversation as resolved.
Show resolved Hide resolved
class Registry
private

# By default the Docker Registry client sets the Accept header to
# `application/vnd.docker.distribution.manifest.v2+json`
# This results in the digest of a specific platform to be returned, we
# want to override this header so we can fetch the generic digest
# associated with the given repo/tag.
def headers(payload: nil, bearer_token: nil)
headers = {}
headers["Authorization"] = "Bearer #{bearer_token}" unless bearer_token.nil?
if payload.nil?
headers["Accept"] =
"application/vnd.docker.distribution.manifest.list.v2+json, application/json"
end
headers["Content-Type"] = "application/vnd.docker.distribution.manifest.v2+json" unless payload.nil?

headers
end
end
end

module Dependabot
module Docker
class UpdateChecker < Dependabot::UpdateCheckers::Base
Expand All @@ -24,7 +47,7 @@ class UpdateChecker < Dependabot::UpdateCheckers::Base
#{VERSION_WITH_PFX}|
#{VERSION_WITH_SFX}|
#{VERSION_WITH_PFX_AND_SFX}
/x.freeze
/x.freeze

def latest_version
@latest_version ||= fetch_latest_version
Expand Down Expand Up @@ -188,6 +211,7 @@ def tags_from_registry
@tags_from_registry ||=
begin
client = docker_registry_client

client.tags(docker_repo_name, auto_paginate: true).fetch("tags")
rescue *transient_docker_errors
attempt ||= 1
Expand Down