forked from GoogleContainerTools/distroless
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add two package manager rules for debian
Adds two rules: dpkg_src Resolves a debian package mirror and parses the package list into a json file dpkg With a reference to the parsed package json file, find a package and download the .deb Use dpkg rules instead of http_files Use deb.debian.org, run buildifier Upload to distroless bucket
- Loading branch information
Showing
15 changed files
with
500 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
load("@subpar//:subpar.bzl", "par_binary") | ||
|
||
par_binary( | ||
name = "dpkg_parser", | ||
srcs = glob(["**/*.py"]), | ||
main = "dpkg_parser.py", | ||
visibility = ["//visibility:public"], | ||
deps = [":parse_metadata"], | ||
) | ||
|
||
py_library( | ||
name = "parse_metadata", | ||
srcs = ["parse_metadata.py"], | ||
) | ||
|
||
py_test( | ||
name = "parse_metadata_test", | ||
size = "small", | ||
srcs = ["parse_metadata_test.py"], | ||
data = ["testdata/Packages.txt"], | ||
deps = [":parse_metadata"], | ||
) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# A cloud build config to release a PAR binary of | ||
# the dpkg_parser.par used for the package manager bazel rules | ||
|
||
# A cloudbuild is triggered by every commit and $COMMIT_SHA is a built-in | ||
# substitution | ||
|
||
steps: | ||
# Build the dpkg_parser PAR file | ||
# this binary is used by the package manager rules | ||
# to download debian package lists and debian packages | ||
- name: gcr.io/cloud-builders/bazel | ||
args: [ | ||
'--output_base', '/workspace', | ||
'build', '//package_manager:dpkg_parser.par', | ||
# TODO(r2d4): Remove once PAR compilation runs properly inside | ||
# the Bazel sandbox on cloudbuild. | ||
'--strategy', 'PythonCompile=standalone' | ||
] | ||
|
||
# Upload the dpkg_parser PAR file to a GCS bucket | ||
- name: gcr.io/cloud-builders/gsutil | ||
args: [ | ||
'cp', | ||
'bazel-bin/package_manager/dpkg_parser.par', | ||
'gs://distroless/package_manager_tools/$COMMIT_SHA/dpkg_parser.par' | ||
] | ||
|
||
# We produce no Docker images. | ||
images: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
def _dpkg_impl(repository_ctx): | ||
repository_ctx.file("file/BUILD", """ | ||
package(default_visibility = ["//visibility:public"]) | ||
exports_files(["pkg.deb"]) | ||
""") | ||
|
||
args = [ | ||
repository_ctx.path(repository_ctx.attr._dpkg_parser), | ||
"--packages-file", repository_ctx.path(repository_ctx.attr.source), | ||
"--package-name", repository_ctx.name | ||
] | ||
|
||
result = repository_ctx.execute(args) | ||
if result.return_code: | ||
fail("dpkg_parser command failed: %s (%s)" % (result.stderr, " ".join(args))) | ||
|
||
_dpkg = repository_rule( | ||
_dpkg_impl, | ||
attrs = { | ||
"source": attr.label( | ||
allow_single_file = True, | ||
), | ||
"_dpkg_parser": attr.label( | ||
executable = True, | ||
default = Label("@dpkg_parser//file:dpkg_parser.par"), | ||
cfg = "host", | ||
), | ||
}, | ||
) | ||
|
||
def _dpkg_src_impl(repository_ctx): | ||
repository_ctx.file("file/BUILD", """ | ||
package(default_visibility = ["//visibility:public"]) | ||
exports_files(["Packages.json"]) | ||
""") | ||
args = [ | ||
repository_ctx.path(repository_ctx.attr._dpkg_parser), | ||
"--download-and-extract-only=True", | ||
"--mirror-url=" + repository_ctx.attr.url, | ||
"--arch=" + repository_ctx.attr.arch, | ||
"--distro=" + repository_ctx.attr.distro | ||
] | ||
result = repository_ctx.execute(args) | ||
if result.return_code: | ||
fail("dpkg_parser command failed: %s (%s)" % (result.stderr, " ".join(args))) | ||
|
||
_dpkg_src = repository_rule( | ||
_dpkg_src_impl, | ||
attrs = { | ||
"url": attr.string(), | ||
"arch": attr.string(), | ||
"distro": attr.string(), | ||
"_dpkg_parser": attr.label( | ||
executable = True, | ||
default = Label("@dpkg_parser//file:dpkg_parser.par"), | ||
cfg = "host", | ||
), | ||
}, | ||
) | ||
|
||
def dpkg(**kwargs): | ||
_dpkg(**kwargs) | ||
|
||
def dpkg_src(**kwargs): | ||
_dpkg_src(**kwargs) |
Oops, something went wrong.