Skip to content

Commit

Permalink
Upgrade Common repo rules_oci to v2.0.0
Browse files Browse the repository at this point in the history
https://github.com/bazel-contrib/rules_oci/releases/tag/v2.0.0

Bug: 330312036
Change-Id: Ic626da24b301097bddcee2471051150bcf1dfdce
GitOrigin-RevId: 1f6215716e77bb267d5e6dc694daee2e361e9bc3
  • Loading branch information
Privacy Sandbox Team authored and copybara-github committed Sep 16, 2024
1 parent b7b3c75 commit 146a552
Show file tree
Hide file tree
Showing 10 changed files with 294 additions and 47 deletions.
4 changes: 2 additions & 2 deletions production/packaging/aws/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ genrule(
name = "copy_to_dist",
srcs = [
":aws_artifacts",
"//src/aws/proxy:proxy_debian_tarball",
"//src/aws/proxy:proxy_debian_tarball.tar",
],
outs = ["copy_to_dist.bin"],
cmd_bash = """cat <<EOF >'$@'
Expand All @@ -40,7 +40,7 @@ mkdir -p \\$${target_dir}
readonly file_prefix="\\$${target_dir}/proxy"
cp $(execpath :aws_artifacts) "\\$${file_prefix}-\\$$1-\\$$2.zip"
if [[ \\$$1 == debian ]]; then
cp $(execpath //src/aws/proxy:proxy_debian_tarball) "\\$${file_prefix}-image-\\$$2.tar"
cp $(execpath //src/aws/proxy:proxy_debian_tarball.tar) "\\$${file_prefix}-image-\\$$2.tar"
fi
builders/tools/normalize-dist
EOF""",
Expand Down
23 changes: 18 additions & 5 deletions src/aws/proxy/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
load("@com_google_googleapis_imports//:imports.bzl", "cc_grpc_library", "cc_proto_library")
load("@rules_buf//buf:defs.bzl", "buf_lint_test")
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_tarball")
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_load")
load("@rules_pkg//pkg:mappings.bzl", "pkg_attributes", "pkg_files")
load("@rules_pkg//pkg:pkg.bzl", "pkg_tar")
load("@rules_proto//proto:defs.bzl", "proto_library")
Expand Down Expand Up @@ -105,20 +105,26 @@ oci_image(
],
)

oci_tarball(
oci_load(
name = "resolv_conf_getter_server_debian_tarball",
image = ":resolv_conf_getter_server_debian_image",
repo_tags = ["src/aws/proxy:resolv_conf_getter_server_debian"],
)

filegroup(
name = "resolv_conf_getter_server_debian_tarball.tar",
srcs = [":resolv_conf_getter_server_debian_tarball"],
output_group = "tarball",
)

genrule(
name = "copy_to_dist",
srcs = [":resolv_conf_getter_server_debian_tarball"],
srcs = [":resolv_conf_getter_server_debian_tarball.tar"],
outs = ["copy_to_dist.bin"],
cmd_bash = """cat << EOF > '$@'
readonly target_dir=dist/aws
mkdir -p \\$${target_dir}
cp $(execpath :resolv_conf_getter_server_debian_tarball) "\\$${target_dir}"
cp $(execpath :resolv_conf_getter_server_debian_tarball.tar) "\\$${target_dir}"
EOF""",
executable = True,
local = True,
Expand Down Expand Up @@ -347,13 +353,20 @@ oci_image(
],
)

oci_tarball(
oci_load(
name = "proxy_debian_tarball",
image = ":proxy_debian_image",
repo_tags = ["src/aws/proxy:proxy_debian"],
visibility = ["//visibility:public"],
)

filegroup(
name = "proxy_debian_tarball.tar",
srcs = [":proxy_debian_tarball"],
output_group = "tarball",
visibility = ["//visibility:public"],
)

pkg_files(
name = "proxify_executables",
srcs = [
Expand Down
16 changes: 11 additions & 5 deletions src/public/cpio/validator/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("@container_structure_test//:defs.bzl", "container_structure_test")
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_tarball")
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_load")
load("@rules_pkg//pkg:mappings.bzl", "pkg_attributes", "pkg_files")
load("@rules_pkg//pkg:tar.bzl", "pkg_tar")
load("@rules_proto//proto:defs.bzl", "proto_descriptor_set")
Expand Down Expand Up @@ -328,23 +328,29 @@ oci_image(
],
)

oci_tarball(
oci_load(
name = "aws_nitro_enclaves_validator_tarball",
image = ":aws_nitro_enclaves_validator_image",
repo_tags = ["bazel/src/public/cpio/validator:aws_nitro_enclaves_validator"],
)

filegroup(
name = "aws_nitro_enclaves_validator_tarball.tar",
srcs = [":aws_nitro_enclaves_validator_tarball"],
output_group = "tarball",
)

genrule(
name = "copy_to_dist",
srcs = [
":aws_nitro_enclaves_validator_tarball",
":aws_nitro_enclaves_validator_tarball.tar",
],
outs = ["copy_to_dist.bin"],
cmd_bash = """cat << EOF > '$@'
readonly target_dir=dist/aws
mkdir -p \\$${target_dir}
readonly enclaves_image="\\$${target_dir}/aws_nitro_enclaves_validator.tar"
cp $(execpath :aws_nitro_enclaves_validator_tarball) "\\$${enclaves_image}"
readonly enclaves_image="\\$${target_dir}/aws_nitro_enclaves_validator_tarball.tar"
cp $(execpath :aws_nitro_enclaves_validator_tarball.tar) "\\$${enclaves_image}"
builders/tools/normalize-dist
EOF""",
executable = True,
Expand Down
11 changes: 8 additions & 3 deletions src/roma/byob/byob.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

load("@container_structure_test//:defs.bzl", "container_structure_test")
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_tarball")
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_load")
load("@rules_pkg//pkg:mappings.bzl", "pkg_attributes", "pkg_files")
load("@rules_pkg//pkg:tar.bzl", "pkg_tar")
load("//third_party:container_deps.bzl", "DISTROLESS_USERS")
Expand Down Expand Up @@ -63,11 +63,16 @@ def _byob_image(
tags = ["noasan"],
)
if repo_tags:
oci_tarball(
oci_load(
name = "{}_tarball".format(name),
image = ":{}".format(name),
repo_tags = repo_tags,
)
native.filegroup(
name = "{}_tarball.tar".format(name),
srcs = [":{}_tarball".format(name)],
output_group = "tarball",
)

def byob_image(
name,
Expand All @@ -81,7 +86,7 @@ def byob_image(
Generates a BYOB OCI container image:
* {name}
Each image has a corresponding OCI tarball:
* {name}_tarball
* {name}_tarball.tar
udf_binary_labels: Target labels of the udf binaries.
repo_tags: Tags for the resulting image.
Expand Down
17 changes: 13 additions & 4 deletions src/roma/byob/container/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

load("@rules_cc//cc:defs.bzl", "cc_binary")
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_tarball")
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_load")
load("@rules_pkg//pkg:mappings.bzl", "pkg_attributes", "pkg_files", "pkg_mkdirs")
load("@rules_pkg//pkg:tar.bzl", "pkg_tar")
load("//src/roma/byob/config:container.bzl", "roma_container_dir", "roma_container_root_dir")
Expand Down Expand Up @@ -132,25 +132,34 @@ alias(
_server_image = "byob_server:v1"

[
oci_tarball(
oci_load(
name = "byob_server_image_tarball_{}".format(user.flavor),
image = ":byob_server_image_{}".format(user.flavor),
repo_tags = [_server_image],
)
for user in DISTROLESS_USERS
]

[
filegroup(
name = "byob_server_image_tarball_{}.tar".format(user.flavor),
srcs = ["byob_server_image_tarball_{}".format(user.flavor)],
output_group = "tarball",
)
for user in DISTROLESS_USERS
]

# warning: this is not hermetic, it uses the local docker client to load an
# image, create a container then export that image using a static container name
[
genrule(
name = "gen_byob_server_container_tar_{}".format(user.flavor),
srcs = [
":byob_server_image_tarball_{}".format(user.flavor),
":byob_server_image_tarball_{}.tar".format(user.flavor),
],
outs = ["byob_server_container_{}.tar".format(user.flavor)],
cmd_bash = """
docker load -i "$(location :byob_server_image_tarball_{flavor})"
docker load -i "$(location :byob_server_image_tarball_{flavor}.tar)"
CID=$$(docker create --privileged "{image_uri}")
docker export $$CID -o $@
docker rm $$CID
Expand Down
16 changes: 8 additions & 8 deletions src/roma/byob/test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,18 @@ pkg_files(
genrule(
name = "copy_to_dist",
srcs = [
":example_test_nonroot_image_tarball",
":example_test_root_image_tarball",
":sample_test_nonroot_image_tarball",
":sample_test_root_image_tarball",
":example_test_nonroot_image_tarball.tar",
":example_test_root_image_tarball.tar",
":sample_test_nonroot_image_tarball.tar",
":sample_test_root_image_tarball.tar",
],
outs = ["copy_to_dist.bin"],
cmd_bash = """cat <<EOF >'$@'
mkdir -p {dir}
cp $(execpath :example_test_nonroot_image_tarball) {dir}/example_test_nonroot_image.tar
cp $(execpath :example_test_root_image_tarball) {dir}/example_test_root_image.tar
cp $(execpath :sample_test_nonroot_image_tarball) {dir}/sample_test_nonroot_image.tar
cp $(execpath :sample_test_root_image_tarball) {dir}/sample_test_root_image.tar
cp $(execpath :example_test_nonroot_image_tarball.tar) {dir}/example_test_nonroot_image.tar
cp $(execpath :example_test_root_image_tarball.tar) {dir}/example_test_root_image.tar
cp $(execpath :sample_test_nonroot_image_tarball.tar) {dir}/sample_test_nonroot_image.tar
cp $(execpath :sample_test_root_image_tarball.tar) {dir}/sample_test_root_image.tar
builders/tools/normalize-dist
EOF""".format(dir = "dist/roma_byob"),
executable = True,
Expand Down
31 changes: 16 additions & 15 deletions src/roma/tools/api_plugin/roma_api.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

load("@io_bazel_rules_closure//closure:defs.bzl", "closure_js_library")
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_tarball")
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_load")
load("@rules_pkg//pkg:mappings.bzl", "pkg_attributes", "pkg_files")
load("@rules_pkg//pkg:tar.bzl", "pkg_tar")
load("@rules_pkg//pkg:zip.bzl", "pkg_zip")
Expand Down Expand Up @@ -508,22 +508,15 @@ def _roma_image(*, name, cc_binary, version, type):
":{}_{}_cli_tar".format(name, type_str),
],
)
oci_tarball(
oci_load(
name = "{}_tarball".format(name),
image = ":{}_image".format(name),
repo_tags = ["privacy_sandbox/udf_sdk/{}:{}".format(name, version)],
)
native.genrule(
name = name,
srcs = [
"{}_tarball".format(name),
],
outs = ["{}_tarball.tar".format(name)],
cmd_bash = """
cp $(execpath :{name}_tarball) $@
""".format(name = name),
executable = True,
local = True,
native.filegroup(
name = "{}_tarball.tar".format(name),
srcs = [":{}_tarball".format(name)],
output_group = "tarball",
)

def roma_integrator_docs(*, name, app_api_cc_library, host_api_cc_libraries = [], **kwargs):
Expand Down Expand Up @@ -604,12 +597,20 @@ def roma_v8_sdk(*, name, srcs, roma_app_api, app_api_cc_library, js_library, ver
cc_binary = "//src/roma/tools/v8_cli:roma_benchmark",
version = version,
)

pkg_files(
name = name + "_tools_artifacts",
srcs = [
":{}_roma_shell".format(name),
":{}_roma_benchmark".format(name),
":{}_roma_shell_tarball.tar".format(name),
":{}_roma_benchmark_tarball.tar".format(name),
],
# oci 2.0 rules generate all tarballs the same name "tarball.tar", and we need to rename them.
# Without this rename, we'll get the following error:
# "After renames, multiple sources (at least {0}, {1}) map to the same destination. Consider adjusting strip_prefix and/or renames error".
renames = {
":{}_roma_shell_tarball.tar".format(name): "{}_roma_shell_tarball.tar".format(name),
":{}_roma_benchmark_tarball.tar".format(name): "{}_roma_benchmark_tarball.tar".format(name),
},
prefix = "tools",
)

Expand Down
9 changes: 6 additions & 3 deletions third_party/cpp_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,12 @@ def _container_deps():
maybe(
http_archive,
name = "rules_oci",
sha256 = "46ce9edcff4d3d7b3a550774b82396c0fa619cc9ce9da00c1b09a08b45ea5a14",
strip_prefix = "rules_oci-1.8.0",
url = "https://github.com/bazel-contrib/rules_oci/releases/download/v1.8.0/rules_oci-v1.8.0.tar.gz",
patches = [
Label("//third_party:rules_oci.patch"),
],
sha256 = "d007e6c96eb62c88397b68f329e4ca56e0cfe31204a2c54b0cb17819f89f83c8",
strip_prefix = "rules_oci-2.0.0",
url = "https://github.com/bazel-contrib/rules_oci/releases/download/v2.0.0/rules_oci-v2.0.0.tar.gz",
)
maybe(
http_archive,
Expand Down
3 changes: 1 addition & 2 deletions third_party/deps2.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_depe
load("@rules_fuzzing//fuzzing:repositories.bzl", "rules_fuzzing_dependencies")
load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")
load("@rules_oci//oci:dependencies.bzl", "rules_oci_dependencies")
load("@rules_oci//oci:repositories.bzl", "LATEST_CRANE_VERSION", "oci_register_toolchains")
load("@rules_oci//oci:repositories.bzl", "oci_register_toolchains")
load("@rules_pkg//pkg:deps.bzl", "rules_pkg_dependencies")
load("@rules_rust//crate_universe:repositories.bzl", "crate_universe_dependencies")
load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains")
Expand Down Expand Up @@ -148,7 +148,6 @@ def deps2(
rules_oci_dependencies()
oci_register_toolchains(
name = "oci",
crane_version = LATEST_CRANE_VERSION,
)
container_structure_test_register_toolchain(name = "cst")
dwyu_setup_step_1()
Loading

0 comments on commit 146a552

Please sign in to comment.