Skip to content

Commit

Permalink
Changes for docker package manager (#11217)
Browse files Browse the repository at this point in the history
Changes for docker package manager metric collection(#11217)
  • Loading branch information
sachin-sandhu authored Jan 3, 2025
1 parent 74c174a commit c9d550b
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docker/lib/dependabot/docker/file_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
require "dependabot/file_parsers/base"
require "dependabot/errors"
require "sorbet-runtime"
require "dependabot/docker/package_manager"

module Dependabot
module Docker
Expand Down Expand Up @@ -42,6 +43,17 @@ class FileParser < Dependabot::FileParsers::Base

IMAGE_SPEC = %r{^(#{REGISTRY}/)?#{IMAGE}#{TAG}?(?:@sha256:#{DIGEST})?#{NAME}?}x

sig { returns(Ecosystem) }
def ecosystem
@ecosystem ||= T.let(
Ecosystem.new(
name: ECOSYSTEM,
package_manager: DockerPackageManager.new
),
T.nilable(Ecosystem)
)
end

# rubocop:disable Metrics/AbcSize
sig { override.returns(T::Array[Dependabot::Dependency]) }
def parse
Expand Down
53 changes: 53 additions & 0 deletions docker/lib/dependabot/docker/package_manager.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# typed: strong
# frozen_string_literal: true

require "sorbet-runtime"
require "dependabot/docker/version"
require "dependabot/ecosystem"
require "dependabot/docker/requirement"

module Dependabot
module Docker
ECOSYSTEM = "docker"

SUPPORTED_VERSIONS = T.let([].freeze, T::Array[Dependabot::Version])

DEPRECATED_VERSIONS = T.let([].freeze, T::Array[Dependabot::Version])

class DockerPackageManager < Dependabot::Ecosystem::VersionManager
extend T::Sig

NAME = "docker"

# As dockerfile updater is a inhouse custom utility, We use a placeholder
# version number for dockerfile updater
VERSION = "1.0.0"

SUPPORTED_VERSIONS = T.let([].freeze, T::Array[Dependabot::Version])

DEPRECATED_VERSIONS = T.let([].freeze, T::Array[Dependabot::Version])

sig do
void
end
def initialize
super(
name: NAME,
version: Version.new(VERSION),
deprecated_versions: DEPRECATED_VERSIONS,
supported_versions: SUPPORTED_VERSIONS
)
end

sig { override.returns(T::Boolean) }
def deprecated?
false
end

sig { override.returns(T::Boolean) }
def unsupported?
false
end
end
end
end
33 changes: 33 additions & 0 deletions docker/spec/dependabot/docker/docker_package_manager_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# typed: false
# frozen_string_literal: true

require "dependabot/docker/package_manager"
require "dependabot/ecosystem"
require "spec_helper"

RSpec.describe Dependabot::Docker::DockerPackageManager do
let(:package_manager) do
described_class.new
end

describe "#initialize" do
context "when docker package manager is initialised" do
it "sets the name and version correctly" do
expect(package_manager.name).to eq(Dependabot::Docker::DockerPackageManager::NAME)
expect(package_manager.version.to_s).to eq("1.0.0")
end
end

describe "#deprecated?" do
it "returns always false" do
expect(package_manager.deprecated?).to be false
end
end

describe "#unsupported?" do
it "returns always false" do
expect(package_manager.unsupported?).to be false
end
end
end
end
8 changes: 8 additions & 0 deletions docker/spec/dependabot/docker/file_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,14 @@
expect(dependency.name).to eq("ubuntu")
expect(dependency.version).to eq("artful")
expect(dependency.requirements).to eq(expected_requirements)

ecosystem = parser.ecosystem

expect(ecosystem.name).to eq("docker")
expect(ecosystem.package_manager.name).to eq("docker")

expect(ecosystem.package_manager.deprecated?).to be false
expect(ecosystem.package_manager.unsupported?).to be false
end
end
end
Expand Down

0 comments on commit c9d550b

Please sign in to comment.