Skip to content

Commit

Permalink
Updated and renamed dockerfileLABEL.py to dockerfile.py
Browse files Browse the repository at this point in the history
  • Loading branch information
VarshaUN authored Dec 1, 2024
1 parent 7ece43b commit 6ba5e73
Showing 1 changed file with 3 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,19 @@ class DockerfileHandler(models.DatafileHandler):
datasource_id = 'dockerfile_oci_labels'
default_package_type = 'docker-image'
path_patterns = ('Dockerfile', 'containerfile', '*.dockerfile')
description = 'Dockerfile (OCI) metadata handler'
documentation_url = 'https://docs.docker.com/engine/reference/builder/'

@classmethod
def parse(cls, location, package_only=False):
"""
Parse a Dockerfile and yield one or more PackageData objects with OCI labels and metadata.
"""
labels = cls.extract_oci_labels_from_dockerfile(location)


package_data = {
'datasource_id': cls.datasource_id,
'type': cls.default_package_type,
'name': labels.get('name', 'unknown'),
'version': labels.get('version', 'unknown'),
'license_expression': labels.get('license', 'unknown'),
'name': labels.get('name', 'None'),
'version': labels.get('version', 'None'),
'license_expression': labels.get('license', 'None'),
'labels': labels,
}

Expand All @@ -52,21 +48,3 @@ def extract_oci_labels_from_dockerfile(cls, dockerfile_path):
parser.parse(dockerfile_path)
labels = parser.labels
return labels

@classmethod
def assemble(cls, package_data, resource, codebase, package_adder):
"""
Assemble a Package from the parsed Dockerfile data.
"""
if package_data.purl:
package = models.Package.from_package_data(package_data=package_data, datafile_path=resource.path)


package.populate_license_fields()

yield package


package_adder(package.package_uid, resource, codebase)

yield resource

0 comments on commit 6ba5e73

Please sign in to comment.