Skip to content

Commit 266b903

Browse files
committed
initial commit added packeto buildpacks with tests and created buildpack package
1 parent c40476a commit 266b903

File tree

10 files changed

+519
-0
lines changed

10 files changed

+519
-0
lines changed

src/packagedcode/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from packagedcode import alpine
1313
from packagedcode import bower
1414
from packagedcode import build
15+
from packagedcode import buildpack
1516
from packagedcode import build_gradle
1617
from packagedcode import cargo
1718
from packagedcode import chef
@@ -62,6 +63,8 @@
6263
build.BuckMetadataBzlHandler,
6364
build.BuckPackageHandler,
6465

66+
buildpack.BuildpackHandler,
67+
6568
cargo.CargoLockHandler,
6669
cargo.CargoTomlHandler,
6770

src/packagedcode/buildpack.py

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
import tomlkit
4+
from packagedcode import models
5+
from packageurl import PackageURL
6+
7+
class BuildpackHandler(models.DatafileHandler):
8+
"""
9+
Handle buildpack.toml manifests.
10+
See https://buildpacks.io/ for details on buildpack format.
11+
"""
12+
datasource_id = "buildpack_toml"
13+
path_patterns = ("*buildpack.toml",)
14+
default_package_type = "buildpack"
15+
description = "Cloud Native Buildpack manifest"
16+
documentation_url = "https://buildpacks.io/"
17+
18+
@classmethod
19+
def parse(cls, location, package_only=False):
20+
"""
21+
Parse the buildpack.toml file at `location` and yield PackageData.
22+
"""
23+
with open(location, "r", encoding="utf-8") as f:
24+
data = tomlkit.parse(f.read())
25+
26+
# Extract required fields
27+
api_version = data.get("api")
28+
buildpack = data.get("buildpack", {})
29+
if not buildpack:
30+
return # Skip files missing required fields
31+
32+
buildpack_id = buildpack.get("id")
33+
buildpack_version = buildpack.get("version", "unknown")
34+
buildpack_name = buildpack.get("name")
35+
36+
if not (api_version and buildpack_id and buildpack_version and buildpack_name):
37+
return # Skip incomplete data
38+
39+
# Optional fields
40+
description = buildpack.get("description")
41+
homepage_url = buildpack.get("homepage")
42+
licenses = buildpack.get("licenses", [])
43+
keywords = buildpack.get("keywords", [])
44+
sbom_formats = buildpack.get("sbom-formats", [])
45+
46+
# Parse licenses
47+
license_expressions = []
48+
for license_entry in licenses:
49+
license_type = license_entry.get("type")
50+
license_uri = license_entry.get("uri")
51+
if license_type:
52+
license_expressions.append(license_type)
53+
54+
# Parse dependencies from "metadata.dependencies"
55+
dependencies = []
56+
metadata = data.get("metadata", {})
57+
metadata_dependencies = metadata.get("dependencies", [])
58+
for dep in metadata_dependencies:
59+
dep_purl = dep.get("purl")
60+
dep_name = dep.get("name")
61+
dep_version = dep.get("version")
62+
if dep_purl:
63+
dependencies.append(
64+
models.DependentPackage(
65+
purl=dep_purl,
66+
scope="runtime",
67+
is_runtime=True,
68+
is_optional=False,
69+
)
70+
)
71+
elif dep_name and dep_version:
72+
dependencies.append(
73+
models.DependentPackage(
74+
purl=PackageURL(type="generic", name=dep_name, version=dep_version).to_string(),
75+
scope="runtime",
76+
is_runtime=True,
77+
is_optional=False,
78+
)
79+
)
80+
81+
# Parse "order" section for additional dependencies
82+
orders = data.get("order", [])
83+
for order in orders:
84+
for group in order.get("group", []):
85+
group_id = group.get("id")
86+
group_version = group.get("version")
87+
if group_id and group_version:
88+
dependencies.append(
89+
models.DependentPackage(
90+
purl=PackageURL(type="buildpack", name=group_id, version=group_version).to_string(),
91+
scope="runtime",
92+
is_runtime=True,
93+
is_optional=group.get("optional", False),
94+
)
95+
)
96+
97+
package_data = dict(
98+
datasource_id=cls.datasource_id,
99+
type=cls.default_package_type,
100+
name=buildpack_name,
101+
version=buildpack_version,
102+
description=description,
103+
homepage_url=homepage_url,
104+
keywords=keywords,
105+
sbom_formats=sbom_formats,
106+
declared_license_expression=" AND ".join(license_expressions) if license_expressions else None,
107+
dependencies=dependencies,
108+
extra_data={"id": buildpack_id}, # Store the id in extra_data
109+
)
110+
111+
yield models.PackageData.from_data(package_data, package_only)

src/packagedcode/models.py

+8
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,14 @@ class PackageData(IdentifiablePackageData):
582582
download_url = String(
583583
label='Download URL',
584584
help='A direct download URL.')
585+
586+
sbom_formats = List(
587+
item_type=str,
588+
label='SBOM Formats',
589+
help='A list of supported SBOM formats output by the buildpack. '
590+
'Supported values are the following media types: '
591+
'"application/vnd.cyclonedx+json", "application/spdx+json", and "application/vnd.syft+json".'
592+
)
585593

586594
size = Integer(
587595
default=None,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
api = "0.8"
2+
3+
[buildpack]
4+
description = "A buildpack for running the `dotnet execute` command for an app"
5+
homepage = "https://github.com/paketo-buildpacks/dotnet-execute"
6+
id = "paketo-buildpacks/dotnet-execute"
7+
keywords = ["dotnet"]
8+
name = "Paketo Buildpack for .NET Execute"
9+
sbom-formats = ["application/vnd.cyclonedx+json", "application/spdx+json", "application/vnd.syft+json"]
10+
11+
[[buildpack.licenses]]
12+
type = "Apache-2.0"
13+
uri = "https://github.com/paketo-buildpacks/dotnet-execute/blob/main/LICENSE"
14+
15+
[metadata]
16+
include-files = ["bin/build", "bin/detect", "bin/run", "bin/port-chooser", "buildpack.toml"]
17+
pre-package = "./scripts/build.sh"
18+
19+
[[stacks]]
20+
id = "*"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
api = "0.7"
2+
3+
[buildpack]
4+
homepage = "https://github.com/paketo-buildpacks/git"
5+
id = "paketo-buildpacks/git"
6+
name = "Paketo Buildpack for Git"
7+
8+
[metadata]
9+
include-files = ["bin/run", "bin/build", "bin/detect", "buildpack.toml"]
10+
pre-package = "./scripts/build.sh"
11+
12+
[[stacks]]
13+
id = "*"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Copyright 2018-2021 the original author or authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
api = "0.7"
16+
17+
[buildpack]
18+
description = "A Cloud Native Buildpack that installs the Java Memory Assistant agent"
19+
homepage = "https://github.com/paketo-buildpacks/java-memory-assistant"
20+
id = "paketo-buildpacks/java-memory-assistant"
21+
keywords = ["agent"]
22+
name = "Paketo Buildpack for Java Memory Assistant"
23+
sbom-formats = ["application/vnd.syft+json", "application/vnd.cyclonedx+json"]
24+
version = "{{.version}}"
25+
26+
[[buildpack.licenses]]
27+
type = "Apache-2.0"
28+
uri = "https://github.com/paketo-buildpacks/java-memory-assistant/blob/main/LICENSE"
29+
30+
[metadata]
31+
include-files = ["LICENSE", "NOTICE", "README.md", "linux/amd64/bin/build", "linux/amd64/bin/detect", "linux/amd64/bin/main", "linux/amd64/bin/helper", "linux/arm64/bin/build", "linux/arm64/bin/detect", "linux/arm64/bin/main", "linux/arm64/bin/helper", "buildpack.toml"]
32+
pre-package = "scripts/build.sh"
33+
34+
[[metadata.configurations]]
35+
build = true
36+
default = "false"
37+
description = "whether to contribute the JMA agent at build time"
38+
name = "BP_JMA_ENABLED"
39+
40+
[[metadata.configurations]]
41+
default = "false"
42+
description = "whether to enable the JMA agent at runtime"
43+
launch = true
44+
name = "BPL_JMA_ENABLED"
45+
46+
[[metadata.configurations]]
47+
default = "check_interval=5s,log_level=ERROR,max_frequency=1/1m,heap_dump_folder=/tmp,thresholds.heap=80%"
48+
description = "arguments to configure the JMA agent"
49+
launch = true
50+
name = "BPL_JMA_ARGS"
51+
52+
[[metadata.dependencies]]
53+
cpes = ["cpe:2.3:a:sap:java-memory-assistant:0.5.0:*:*:*:*:*:*:*"]
54+
id = "java-memory-assistant"
55+
name = "Java Memory Assistant Agent"
56+
purl = "pkg:generic/sap-java-memory-assistant@0.5.0?arch=amd64"
57+
sha256 = "9c5ffb4bdeec5ed6b4f1d734469500754a857d1452c3d253d89e2315addb04c5"
58+
source = "https://github.com/sap/java-memory-assistant/archive/refs/tags/0.5.0.tar.gz"
59+
source-sha256 = "dedf82a5c10df5b12e602c1237f00a459a38b6a55c0ff8d671fa0d3909dfe4fc"
60+
stacks = ["io.buildpacks.stacks.bionic", "io.paketo.stacks.tiny", "*"]
61+
uri = "https://github.com/SAP-archive/java-memory-assistant/releases/download/0.5.0/java-memory-assistant-0.5.0.jar"
62+
version = "0.5.0"
63+
64+
[[metadata.dependencies.licenses]]
65+
type = "Apache-2.0"
66+
uri = "https://github.com/SAP/java-memory-assistant/blob/master/LICENSE"
67+
68+
[[stacks]]
69+
id = "io.buildpacks.stacks.bionic"
70+
71+
[[stacks]]
72+
id = "io.paketo.stacks.tiny"
73+
74+
[[stacks]]
75+
id = "*"
76+
77+
[[targets]]
78+
arch = "amd64"
79+
os = "linux"
80+
81+
[[targets]]
82+
arch = "arm64"
83+
os = "linux"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Copyright 2018-2024 the original author or authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
api = "0.7"
16+
17+
[buildpack]
18+
description = "A Cloud Native Buildpack that contributes and configures the OpenTelemetry Agent"
19+
homepage = "https://github.com/paketo-buildpacks/opentelemetry"
20+
id = "paketo-buildpacks/opentelemetry"
21+
keywords = ["java", "apm", "trace", "opentelemetry"]
22+
name = "Paketo Buildpack for OpenTelemetry"
23+
sbom-formats = ["application/vnd.cyclonedx+json", "application/vnd.syft+json"]
24+
version = "{{.version}}"
25+
26+
[[buildpack.licenses]]
27+
type = "Apache-2.0"
28+
uri = "https://github.com/paketo-buildpacks/opentelemetry/blob/main/LICENSE"
29+
30+
[metadata]
31+
include-files = ["LICENSE", "NOTICE", "README.md", "linux/amd64/bin/build", "linux/amd64/bin/detect", "linux/amd64/bin/main", "linux/amd64/bin/helper", "linux/arm64/bin/build", "linux/arm64/bin/detect", "linux/arm64/bin/main", "linux/arm64/bin/helper", "buildpack.toml"]
32+
pre-package = "scripts/build.sh"
33+
34+
[[metadata.configurations]]
35+
build = true
36+
default = "false"
37+
description = "enable the OpenTelemetry Java Trace Agent"
38+
name = "BP_OPENTELEMETRY_ENABLED"
39+
40+
[[metadata.dependencies]]
41+
cpes = ["cpe:2.3:a:open-telemetry:opentelemetry-java-agent:2.10.0:*:*:*:*:*:*:*"]
42+
id = "opentelemetry-java"
43+
name = "OpenTelemetry Java Agent"
44+
purl = "pkg:generic/opentelemetry-java@2.10.0"
45+
sha256 = "d05f6e36fac8db629263a6aaec2841cc934d064d7b19bfe38425b604b8b54926"
46+
source = "https://github.com/open-telemetry/opentelemetry-java-instrumentation/archive/refs/tags/v2.10.0.tar.gz"
47+
source-sha256 = "3a921baa391e9fa3f3622bedf1770567bcfed2a13de07642a2273b8beeca934a"
48+
stacks = ["*"]
49+
uri = "https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v2.10.0/opentelemetry-javaagent.jar"
50+
version = "2.10.0"
51+
52+
[[metadata.dependencies.licenses]]
53+
type = "Apache-2.0"
54+
uri = "https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/LICENSE"
55+
56+
[[stacks]]
57+
id = "*"
58+
59+
[[targets]]
60+
arch = "amd64"
61+
os = "linux"
62+
63+
[[targets]]
64+
arch = "arm64"
65+
os = "linux"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Copyright 2018-2021 the original author or authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
api = "0.7"
16+
17+
[buildpack]
18+
description = "A Cloud Native Buildpack that provides/does nothing. For testing only."
19+
homepage = "https://github.com/paketo-buildpacks/pipeline-builder-canary"
20+
id = "paketo-buildpacks/pipeline-builder-canary"
21+
keywords = ["nothing"]
22+
name = "Paketo Buildpack for Pipeline Builder Canary"
23+
version = "{{.version}}"
24+
25+
[[buildpack.licenses]]
26+
type = "Apache-2.0"
27+
uri = "https://github.com/paketo-buildpacks/pipeline-builder-canary/blob/main/LICENSE"
28+
29+
[metadata]
30+
include-files = ["LICENSE", "NOTICE", "README.md", "linux/amd64/bin/build", "linux/amd64/bin/detect", "linux/amd64/bin/main", "linux/arm64/bin/build", "linux/arm64/bin/detect", "linux/arm64/bin/main", "buildpack.toml"]
31+
pre-package = "scripts/build.sh"
32+
33+
[[metadata.dependencies]]
34+
cpes = ["cpe:2.3:a:apache:maven:3.9.9:*:*:*:*:*:*:*"]
35+
id = "maven"
36+
name = "Apache Maven"
37+
purl = "pkg:generic/apache-maven@3.9.9"
38+
sha256 = "7a9cdf674fc1703d6382f5f330b3d110ea1b512b51f1652846d9e4e8a588d766"
39+
source = "https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-src.tar.gz"
40+
source-sha256 = "8a24c448d4ac397e6b0c019a4d7250068c02d1cdb553299e6bb71c3ccca78b2c"
41+
stacks = ["io.buildpacks.stacks.bionic", "io.paketo.stacks.tiny", "*"]
42+
uri = "https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.tar.gz"
43+
version = "3.9.9"
44+
45+
[[metadata.dependencies.licenses]]
46+
type = "Apache-2.0"
47+
uri = "https://www.apache.org/licenses/"
48+
49+
[[stacks]]
50+
id = "io.buildpacks.stacks.bionic"
51+
52+
[[stacks]]
53+
id = "io.paketo.stacks.tiny"
54+
55+
[[stacks]]
56+
id = "*"
57+
58+
[[targets]]
59+
arch = "amd64"
60+
os = "linux"
61+
62+
[[targets]]
63+
arch = "arm64"
64+
os = "linux"

0 commit comments

Comments
 (0)