Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove pkg_tar workaround from temurin archive #1582

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 39 additions & 45 deletions private/remote/temurin_archive.bzl
Original file line number Diff line number Diff line change
@@ -1,59 +1,51 @@
"temurin archive repository rule"

STATIC_MTREE = """\
./etc time=946684800.0 mode=755 gid=0 uid=0 type=dir
./etc/ssl time=946684800.0 mode=755 gid=0 uid=0 type=dir
./etc/ssl/certs time=946684800.0 mode=755 gid=0 uid=0 type=dir
./etc/ssl/certs/java time=946684800.0 mode=755 gid=0 uid=0 type=dir
./usr time=946684800.0 mode=755 gid=0 uid=0 type=dir
./usr/lib time=946684800.0 mode=755 gid=0 uid=0 type=dir
./usr/lib/jvm time=946684800.0 mode=755 gid=0 uid=0 type=dir
./usr/lib/jvm/%s/lib/security/cacerts nlink=0 time=946684800.0 mode=777 gid=0 uid=0 type=link link=/etc/ssl/certs/java/cacerts
"""

AWK = """\
{
sub("^" "output/lib/security/cacerts", "./etc/ssl/certs/java/cacerts")
sub("^" "output", "./usr/lib/jvm/%s")
sub(/time=[0-9\\.]+/, "time=946684800.0");
sub("mode=0755", "")
print
}
"""

BUILD_TMPL = """\
# GENERATED BY temurin_archive.bzl
load("@distroless//private/pkg:debian_spdx.bzl", "debian_spdx")
load("@distroless//private/util:merge_providers.bzl", "merge_providers")
load("@aspect_bazel_lib//lib:tar.bzl", "tar", "mtree_spec")
load("@rules_pkg//:pkg.bzl", "pkg_tar")
load("@rules_pkg//pkg:mappings.bzl", "pkg_filegroup", "pkg_files", "pkg_attributes", "pkg_mklink_impl")

# all files except bin and cacerts
pkg_files(
name = "_most_files",
srcs = glob(
["output/**/*"],
),
excludes = ["_executables", "_cacerts"],
strip_prefix = "output",
)

# special rules for bin files to make them executable and other executables
pkg_files(
name = "_executables",
srcs = glob(["output/bin/*"]) + ["output/lib/jexec", "output/lib/jspawnhelper"],
attributes = pkg_attributes(
mode = "0755",
user = "root",
group = "root",
),
strip_prefix = "output",
)

# everything that needs to go into the jvm install dir
pkg_filegroup(
name = "_jvm_dir",
srcs = ["_executables", "_most_files"],
prefix = "/usr/lib/jvm/{name}",
SRCS = glob(["output/**/*"])
mtree_spec(
name = "mtree",
srcs = SRCS,
)

# cacerts rules
pkg_files(
name = "_cacerts",
srcs = glob(
["output/lib/security/cacerts"],
),
renames = {{
"output/lib/security/cacerts": "/etc/ssl/certs/java/cacerts",
}},
genrule(
name = "mutate_mtree",
srcs = [":mtree"],
tools = ["static.mtree", "mutate.awk"],
outs = ["out.mtree"],
cmd = "cat $(execpath :static.mtree) >$@ && awk -f $(execpath :mutate.awk) <$< >>$@ && sort -o $@ $@"
)

pkg_mklink_impl(
name = "_cacerts_link",
link_name = "/usr/lib/jvm/{name}/lib/security/cacerts",
target = "/etc/ssl/certs/java/cacerts",
)

pkg_tar(
tar(
name = "data",
srcs = ["_jvm_dir", "_cacerts", "_cacerts_link"],
srcs = SRCS,
mtree = "out.mtree"
)

pkg_tar(
Expand Down Expand Up @@ -87,6 +79,8 @@ def _impl(rctx):
stripPrefix = rctx.attr.strip_prefix,
output = "output",
)
rctx.file("static.mtree", STATIC_MTREE % rctx.attr.name)
rctx.file("mutate.awk", AWK % rctx.attr.name)
rctx.template(
"control",
rctx.attr.control,
Expand Down
Loading