2023-01-03 10:21:07 +00:00
|
|
|
load("@aspect_bazel_lib//lib:tar.bzl", "mtree_spec", "tar")
|
|
|
|
|
load("@aspect_bazel_lib//lib:transitions.bzl", "platform_transition_filegroup")
|
2025-06-20 13:23:06 +00:00
|
|
|
load("@bazel_skylib//rules:build_test.bzl", "build_test")
|
2023-01-03 10:21:07 +00:00
|
|
|
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_load", "oci_push")
|
2025-07-04 15:10:46 +00:00
|
|
|
load("@rules_zig//zig:defs.bzl", "zig_binary")
|
2023-01-03 10:21:07 +00:00
|
|
|
|
2025-07-04 15:10:46 +00:00
|
|
|
zig_binary(
|
2023-01-03 10:21:07 +00:00
|
|
|
name = "simple_layer",
|
|
|
|
|
main = "main.zig",
|
|
|
|
|
deps = [
|
2025-06-20 13:23:06 +00:00
|
|
|
"//async",
|
|
|
|
|
"//zml",
|
2023-01-03 10:21:07 +00:00
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Manifest created from the simple_layer binary and friends
|
|
|
|
|
mtree_spec(
|
|
|
|
|
name = "mtree",
|
|
|
|
|
srcs = [":simple_layer"],
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Create a tar archive from the above manifest
|
|
|
|
|
tar(
|
|
|
|
|
name = "archive",
|
|
|
|
|
srcs = [":simple_layer"],
|
|
|
|
|
args = [
|
|
|
|
|
"--options",
|
2025-06-20 13:23:06 +00:00
|
|
|
",".join([
|
|
|
|
|
"zstd:compression-level=9",
|
|
|
|
|
"zstd:threads=16",
|
|
|
|
|
]),
|
2023-01-03 10:21:07 +00:00
|
|
|
],
|
|
|
|
|
compress = "zstd",
|
|
|
|
|
mtree = ":mtree",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# The actual docker image, with entrypoint, created from tar archive
|
|
|
|
|
oci_image(
|
|
|
|
|
name = "image_",
|
|
|
|
|
base = "@distroless_cc_debian12",
|
2025-06-20 13:23:06 +00:00
|
|
|
entrypoint = ["/{}/simple_layer".format(package_name())],
|
2024-05-23 15:52:34 +00:00
|
|
|
target_compatible_with = [
|
|
|
|
|
"@platforms//os:linux",
|
|
|
|
|
],
|
2023-01-03 10:21:07 +00:00
|
|
|
tars = [":archive"],
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# We always want to create the image for Linux
|
|
|
|
|
platform_transition_filegroup(
|
|
|
|
|
name = "image",
|
|
|
|
|
srcs = [":image_"],
|
2025-06-20 13:23:06 +00:00
|
|
|
tags = ["manual"],
|
|
|
|
|
target_platform = "//platforms:linux_amd64",
|
2023-01-03 10:21:07 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Load will immediatly load the image (eg: docker load)
|
|
|
|
|
oci_load(
|
|
|
|
|
name = "load",
|
|
|
|
|
image = ":image",
|
|
|
|
|
repo_tags = [
|
|
|
|
|
"distroless/simple_layer:latest",
|
|
|
|
|
],
|
2025-06-20 13:23:06 +00:00
|
|
|
tags = ["manual"],
|
2023-01-03 10:21:07 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Bazel target for pushing the Linux image to the docker registry
|
|
|
|
|
oci_push(
|
|
|
|
|
name = "push",
|
|
|
|
|
image = ":image",
|
|
|
|
|
remote_tags = ["latest"],
|
|
|
|
|
# override with -- --repository foo.bar/org/image
|
2025-06-20 13:23:06 +00:00
|
|
|
repository = "index.docker.io/zmlai/simple_layer",
|
|
|
|
|
tags = ["manual"],
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
build_test(
|
|
|
|
|
name = "test",
|
|
|
|
|
targets = [":simple_layer"],
|
2023-01-03 10:21:07 +00:00
|
|
|
)
|