-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
1,920 additions
and
559 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
"EXPERIMENTAL! Public API" | ||
|
||
load("//apt/private:dpkg_status.bzl", _dpkg_status = "dpkg_status") | ||
load("//apt/private:dpkg_statusd.bzl", _dpkg_statusd = "dpkg_statusd") | ||
|
||
dpkg_status = _dpkg_status | ||
dpkg_statusd = _dpkg_statusd |
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 |
---|---|---|
@@ -1,5 +1,26 @@ | ||
"apt-get" | ||
|
||
load("//apt/private:index.bzl", _deb_package_index = "deb_package_index") | ||
load("//apt/private:resolve.bzl", _deb_resolve = "deb_resolve") | ||
|
||
deb_package_index = _deb_package_index | ||
def deb_package_index( | ||
name, | ||
manifest, | ||
lock = None, | ||
package_template = None, | ||
resolve_transitive = True): | ||
_deb_resolve( | ||
name = name + "_resolution", | ||
manifest = manifest, | ||
resolve_transitive = resolve_transitive, | ||
) | ||
|
||
if not lock: | ||
# buildifier: disable=print | ||
print("\nNo lockfile was given, please run `bazel run @%s//:lock` to create the lockfile." % name) | ||
|
||
_deb_package_index( | ||
name = name, | ||
lock = lock if lock else "@" + name + "_resolution//:lock.json", | ||
package_template = package_template, | ||
) |
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,4 @@ | ||
exports_files([ | ||
"dpkg_statusd.sh", | ||
"dpkg_status.sh", | ||
]) |
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,46 @@ | ||
"dpkg_status" | ||
|
||
# buildifier: disable=bzl-visibility | ||
load("//distroless/private:tar.bzl", "tar_lib") | ||
|
||
_DOC = """TODO: docs""" | ||
|
||
def _dpkg_status_impl(ctx): | ||
bsdtar = ctx.toolchains[tar_lib.TOOLCHAIN_TYPE] | ||
|
||
output = ctx.actions.declare_file(ctx.attr.name + ".tar") | ||
|
||
args = ctx.actions.args() | ||
args.add(bsdtar.tarinfo.binary) | ||
args.add(output) | ||
args.add_all(ctx.files.controls) | ||
|
||
ctx.actions.run( | ||
executable = ctx.executable._dpkg_status_sh, | ||
inputs = ctx.files.controls, | ||
outputs = [output], | ||
tools = bsdtar.default.files, | ||
arguments = [args], | ||
) | ||
|
||
return [ | ||
DefaultInfo(files = depset([output])), | ||
] | ||
|
||
dpkg_status = rule( | ||
doc = _DOC, | ||
attrs = { | ||
"_dpkg_status_sh": attr.label( | ||
allow_single_file = True, | ||
executable = True, | ||
cfg = "exec", | ||
default = ":dpkg_status.sh", | ||
), | ||
"controls": attr.label_list( | ||
allow_files = [".tar.xz", ".tar.gz", ".tar"], | ||
mandatory = True, | ||
), | ||
}, | ||
implementation = _dpkg_status_impl, | ||
toolchains = [tar_lib.TOOLCHAIN_TYPE], | ||
) |
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 @@ | ||
#!/usr/bin/env bash | ||
set -o pipefail -o errexit -o nounset | ||
|
||
readonly bsdtar="$1" | ||
readonly out="$2" | ||
shift 2 | ||
|
||
tmp_out=$(mktemp) | ||
|
||
while (( $# > 0 )); do | ||
control="$($bsdtar -xf "$1" --to-stdout ./control)" | ||
echo "$control" | head -n 1 >> $tmp_out | ||
echo "Status: install ok installed" >> $tmp_out | ||
echo "$control" | tail -n +2 >> $tmp_out | ||
echo "" >> $tmp_out | ||
shift | ||
done | ||
|
||
echo "#mtree | ||
./var/lib/dpkg/status type=file uid=0 gid=0 mode=0644 contents=$tmp_out | ||
" | "$bsdtar" $@ -cf "$out" @- | ||
|
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,54 @@ | ||
"dpkg_statusd" | ||
|
||
# buildifier: disable=bzl-visibility | ||
load("//distroless/private:tar.bzl", "tar_lib") | ||
|
||
_DOC = """TODO: docs""" | ||
|
||
def _dpkg_statusd_impl(ctx): | ||
bsdtar = ctx.toolchains[tar_lib.TOOLCHAIN_TYPE] | ||
|
||
ext = tar_lib.common.compression_to_extension[ctx.attr.compression] if ctx.attr.compression else ".tar" | ||
output = ctx.actions.declare_file(ctx.attr.name + ext) | ||
|
||
args = ctx.actions.args() | ||
args.add(bsdtar.tarinfo.binary) | ||
args.add(output) | ||
args.add(ctx.file.control) | ||
args.add(ctx.attr.package_name) | ||
tar_lib.common.add_compression_args(ctx.attr.compression, args) | ||
|
||
ctx.actions.run( | ||
executable = ctx.executable._dpkg_statusd_sh, | ||
inputs = [ctx.file.control], | ||
outputs = [output], | ||
tools = bsdtar.default.files, | ||
arguments = [args], | ||
) | ||
|
||
return [ | ||
DefaultInfo(files = depset([output])), | ||
] | ||
|
||
dpkg_statusd = rule( | ||
doc = _DOC, | ||
attrs = { | ||
"_dpkg_statusd_sh": attr.label( | ||
allow_single_file = True, | ||
executable = True, | ||
cfg = "exec", | ||
default = ":dpkg_statusd.sh", | ||
), | ||
"package_name": attr.string(mandatory = True), | ||
"control": attr.label( | ||
allow_single_file = [".tar.xz", ".tar.gz", ".tar"], | ||
mandatory = True, | ||
), | ||
"compression": attr.string( | ||
doc = "Compress the archive file with a supported algorithm.", | ||
values = tar_lib.common.accepted_compression_types, | ||
), | ||
}, | ||
implementation = _dpkg_statusd_impl, | ||
toolchains = [tar_lib.TOOLCHAIN_TYPE], | ||
) |
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,23 @@ | ||
#!/usr/bin/env bash | ||
set -o pipefail -o errexit -o nounset | ||
|
||
readonly bsdtar="$1" | ||
readonly out="$2" | ||
readonly control_path="$3" | ||
readonly package_name="$4" | ||
shift 4 | ||
|
||
include=(--include "^./control$" --include "^./md5sums$") | ||
|
||
tmp=$(mktemp -d) | ||
"$bsdtar" -xf "$control_path" "${include[@]}" -C "$tmp" | ||
|
||
"$bsdtar" -cf - $@ --format=mtree "${include[@]}" --options '!gname,!uname,!sha1,!nlink,!time' "@$control_path" | \ | ||
awk -v pkg="$package_name" '{ | ||
if ($1=="#mtree") { | ||
print $1; next | ||
}; | ||
sub(/^\.?\//, "", $1); | ||
$1 = "./var/lib/dpkg/status.d/" pkg "/" $1 " contents=./" $1; | ||
print $0 | ||
}' | "$bsdtar" $@ -cf "$out" -C "$tmp/" @- |
Oops, something went wrong.