forked from GoogleContainerTools/distroless
-
Notifications
You must be signed in to change notification settings - Fork 0
/
debian_archive.bzl
107 lines (95 loc) · 2.49 KB
/
debian_archive.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
BUILD_TMPL = """\
# GENERATED BY debian_archive.bzl
load("@distroless//private/pkg:dpkg_status.bzl", "dpkg_status")
load("@distroless//private/pkg:debian_spdx.bzl", "debian_spdx")
load("@distroless//private/util:merge_providers.bzl", "merge_providers")
load("@rules_pkg//:pkg.bzl", "pkg_tar")
alias(
name = "control",
actual = "@{name}_sources//:control",
visibility = ["//visibility:public"]
)
alias(
name = "data",
actual = "@{name}_sources//:data",
visibility = ["//visibility:public"]
)
dpkg_status(
name = "dpkg",
control = ":control",
package_name = "{package_name}"
)
pkg_tar(
name = "data_with_dpkg_status",
# workaround for https://github.com/bazelbuild/rules_pkg/issues/652
package_dir = "./",
deps = [
":data",
":dpkg"
]
)
debian_spdx(
name = "spdx",
control = ":control",
data = ":data",
package_name = "{package_name}",
spdx_id = "{spdx_id}",
sha256 = "{sha256}",
urls = [{urls}]
)
merge_providers(
name = "{name}",
srcs = [":data_with_dpkg_status", ":spdx"],
visibility = ["//visibility:public"],
)
"""
_attrs = {
"package_name": attr.string(mandatory = True),
"urls": attr.string_list(mandatory = True),
"sha256": attr.string(mandatory = True),
}
SOURCE_BUILD_TMPL = """\
filegroup(
name = "control",
srcs = glob(["control.tar.*"]),
visibility = ["//visibility:public"]
)
filegroup(
name = "data",
srcs = glob(["data.tar.*"]),
visibility = ["//visibility:public"]
)
"""
def _debian_source_impl(rctx):
rctx.report_progress("Fetching {}".format(rctx.attr.package_name))
rctx.download_and_extract(
url = rctx.attr.urls,
sha256 = rctx.attr.sha256,
type = "deb",
)
rctx.file(
"BUILD.bazel",
content = SOURCE_BUILD_TMPL,
)
_debian_sources = repository_rule(
implementation = _debian_source_impl,
attrs = _attrs,
)
def _debian_archive_impl(rctx):
rctx.file(
"BUILD.bazel",
content = BUILD_TMPL.format(
name = rctx.attr.name,
package_name = rctx.attr.package_name,
spdx_id = rctx.attr.name,
urls = ",".join(['"%s"' % url for url in rctx.attr.urls]),
sha256 = rctx.attr.sha256,
),
)
_debian_archive = repository_rule(
implementation = _debian_archive_impl,
attrs = _attrs,
)
def debian_archive(name, **kwargs):
_debian_sources(name = "{}_sources".format(name), **kwargs)
_debian_archive(name = name, **kwargs)