diff --git a/.bazelrc b/.bazelrc new file mode 100644 index 00000000..3ce91d27 --- /dev/null +++ b/.bazelrc @@ -0,0 +1 @@ +common --enable_bzlmod diff --git a/BUILD.bazel b/BUILD.bazel index 3add6f43..26a7e828 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1 +1,11 @@ -# Marker that this is the root of a Bazel package +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") + +# For stardoc to reference the file directly +exports_files(["defs.bzl"]) + +bzl_library( + name = "defs", + srcs = ["defs.bzl"], + deps = ["//bazel:container_structure_test"], + visibility = ["//visibility:public"], +) diff --git a/MODULE.bazel b/MODULE.bazel index a51dc5e6..15bb810a 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -15,3 +15,6 @@ ext = use_extension("//:repositories.bzl", "extension") use_repo(ext, "structure_test_toolchains") register_toolchains("@structure_test_toolchains//:all") + +# 0.5.4 is the first version with bzlmod support +bazel_dep(name = "stardoc", version = "0.5.4", repo_name = "io_bazel_stardoc") diff --git a/bazel/BUILD.bazel b/bazel/BUILD.bazel index 89404265..66528b57 100644 --- a/bazel/BUILD.bazel +++ b/bazel/BUILD.bazel @@ -1,4 +1,16 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") + +package(default_visibility = ["//visibility:public"]) + toolchain_type( name = "structure_test_toolchain_type", - visibility = ["//visibility:public"], -) \ No newline at end of file +) + +bzl_library( + name = "container_structure_test", + srcs = ["container_structure_test.bzl"], + deps = [ + "@aspect_bazel_lib//lib:paths", + "@aspect_bazel_lib//lib:windows_utils", + ], +) diff --git a/bazel/docs/BUILD.bazel b/bazel/docs/BUILD.bazel new file mode 100644 index 00000000..628946ef --- /dev/null +++ b/bazel/docs/BUILD.bazel @@ -0,0 +1,10 @@ +# This load statement must be in the docs/ package rather than anything users depend on +# so that the dependency on stardoc doesn't leak to them. +load("@aspect_bazel_lib//lib:docs.bzl", "stardoc_with_diff_test", "update_docs") + +stardoc_with_diff_test( + name = "defs", + bzl_library_target = "//:defs", +) + +update_docs(name = "update") diff --git a/bazel/docs/defs.md b/bazel/docs/defs.md new file mode 100644 index 00000000..2859783a --- /dev/null +++ b/bazel/docs/defs.md @@ -0,0 +1,38 @@ + + +Exposes container-structure-test as a Bazel rule + + + +## container_structure_test + +
+container_structure_test(name, configs, driver, image)
+
+ +Tests a Docker- or OCI-format image. + +By default, it relies on the container runtime already installed and running on the target. + +By default, container-structure-test uses the socket available at `/var/run/docker.sock`. +If the installation creates the socket in a different path, use +`--test_env=DOCKER_HOST='unix://<path_to_sock>'`. + +To avoid putting this into the commandline or to instruct bazel to read it from terminal environment, +simply add `test --test_env=DOCKER_HOST` into the `.bazelrc` file. + +Alternatively, use the `driver = "tar"` attribute to avoid the need for a container runtime, see +https://github.com/GoogleContainerTools/container-structure-test#running-file-tests-without-docker + + +**ATTRIBUTES** + + +| Name | Description | Type | Mandatory | Default | +| :------------- | :------------- | :------------- | :------------- | :------------- | +| name | A unique name for this target. | Name | required | | +| configs | - | List of labels | required | | +| driver | See https://github.com/GoogleContainerTools/container-structure-test#running-file-tests-without-docker | String | optional | "docker" | +| image | Label of an oci_image or oci_tarball target. | Label | optional | None | + +