From 6ea824196e6f3001f0e57b02344ffb478557da43 Mon Sep 17 00:00:00 2001 From: thesayyn Date: Fri, 13 Jun 2025 14:01:02 -0700 Subject: [PATCH] breaking: drop workspace support --- .github/workflows/ci.yaml | 4 +- WORKSPACE => WORKSPACE.bazel | 0 apt/BUILD.bazel | 1 - apt/apt.bzl | 140 ----------------------------------- apt/private/BUILD.bazel | 6 ++ apt/private/deb_postfix.bzl | 1 - distroless/BUILD.bazel | 1 - distroless/dependencies.bzl | 44 ----------- docs/BUILD.bazel | 6 -- 9 files changed, 7 insertions(+), 196 deletions(-) rename WORKSPACE => WORKSPACE.bazel (100%) delete mode 100644 apt/apt.bzl delete mode 100644 distroless/dependencies.bzl diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 83478985..c9807111 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -27,9 +27,7 @@ jobs: ] exclude: | [ - {"folder": ".", "bzlmodEnabled": false}, - {"folder": "docs", "bzlmodEnabled": false}, {"folder": "docs", "bazelVersion": "7.0.0"}, - {"folder": "e2e/smoke", "bzlmodEnabled": false}, {"os": "windows-latest"}, + {"bzlmodEnabled": false}, ] diff --git a/WORKSPACE b/WORKSPACE.bazel similarity index 100% rename from WORKSPACE rename to WORKSPACE.bazel diff --git a/apt/BUILD.bazel b/apt/BUILD.bazel index 9e3a6094..a2704a32 100644 --- a/apt/BUILD.bazel +++ b/apt/BUILD.bazel @@ -17,7 +17,6 @@ bzl_library( bzl_library( name = "apt", - srcs = ["apt.bzl"], visibility = ["//visibility:public"], deps = [ "//apt/private:deb_resolve", diff --git a/apt/apt.bzl b/apt/apt.bzl deleted file mode 100644 index 402ecf34..00000000 --- a/apt/apt.bzl +++ /dev/null @@ -1,140 +0,0 @@ -""" -`apt.install` macro - -This documentation provides an overview of the convenience `apt.install` -repository macro to create Debian repositories with packages "installed" in -them and available to use in Bazel. -""" - -load("//apt/private:deb_resolve.bzl", _deb_resolve = "deb_resolve") -load("//apt/private:deb_translate_lock.bzl", _deb_translate_lock = "deb_translate_lock") - -def _apt_install( - name, - manifest, - lock = None, - nolock = False, - package_template = None, - resolve_transitive = True): - """Repository macro to create Debian repositories. - - > [!WARNING] - > THIS IS A LEGACY MACRO. Use it only if you are still using `WORKSPACE`. - > Otherwise please use the [`apt` module extension](apt.md). - - Here's an example to create a Debian repo with `apt.install`: - - ```starlark - # WORKSPACE - - load("@rules_distroless//apt:apt.bzl", "apt") - - apt.install( - name = "bullseye", - # lock = "//examples/apt:bullseye.lock.json", - manifest = "//examples/apt:bullseye.yaml", - ) - - load("@bullseye//:packages.bzl", "bullseye_packages") - bullseye_packages() - ``` - - Note that, for the initial setup (or if we want to run without a lock) the - lockfile attribute can be omitted. All you need is a YAML - [manifest](/examples/debian_snapshot/bullseye.yaml): - ```yaml - version: 1 - - sources: - - channel: bullseye main - url: https://snapshot-cloudflare.debian.org/archive/debian/20240210T223313Z - - archs: - - amd64 - - packages: - - perl - ``` - - `apt.install` will parse the manifest and will fetch and install the - packages for the given architectures in the Bazel repo `@`. - - Each `/` has two targets that match the usual structure of a - Debian package: `data` and `control`. - - You can use the package like so: `@///:`. - - E.g. for the previous example, you could use `@bullseye//perl/amd64:data`. - - ### Lockfiles - - As mentioned, the macro can be used without a lock because the lock will be - generated internally on-demand. However, this comes with the cost of - performing a new package resolution on repository cache misses. - - The lockfile can be generated by running `bazel run @bullseye//:lock`. This - will generate a `.lock.json` file of the same name and in the same path as - the YAML `manifest` file. - - If you explicitly want to run without a lock and avoid the warning messages - set the `nolock` argument to `True`. - - ### Best Practice: use snapshot archive URLs - - While we strongly encourage users to check in the generated lockfile, it's - not always possible because Debian repositories are rolling by default. - Therefore, a lockfile generated today might not work later if the upstream - repository removes or publishes a new version of a package. - - To avoid this problems and increase the reproducibility it's recommended to - avoid using normal Debian mirrors and use snapshot archives instead. - - Snapshot archives provide a way to access Debian package mirrors at a point - in time. Basically, it's a "wayback machine" that allows access to (almost) - all past and current packages based on dates and version numbers. - - Debian has had snapshot archives for [10+ - years](https://lists.debian.org/debian-announce/2010/msg00002.html). Ubuntu - began providing a similar service recently and has packages available since - March 1st 2023. - - To use this services simply use a snapshot URL in the manifest. Here's two - examples showing how to do this for Debian and Ubuntu: - * [/examples/debian_snapshot](/examples/debian_snapshot) - * [/examples/ubuntu_snapshot](/examples/ubuntu_snapshot) - - For more infomation, please check https://snapshot.debian.org and/or - https://snapshot.ubuntu.com. - - Args: - name: name of the repository - manifest: label to a `manifest.yaml` - lock: label to a `lock.json` - nolock: bool, set to True if you explicitly want to run without a lock - and avoid the DEBUG messages. - package_template: (EXPERIMENTAL!) a template file for generated BUILD - files. Available template replacement keys are: - `{target_name}`, `{deps}`, `{urls}`, `{name}`, - `{arch}`, `{sha256}`, `{repo_name}` - resolve_transitive: whether dependencies of dependencies should be - resolved and added to the lockfile. - """ - _deb_resolve( - name = name + "_resolve", - manifest = manifest, - resolve_transitive = resolve_transitive, - ) - - if not lock and not nolock: - # buildifier: disable=print - print("\nNo lockfile was given, please run `bazel run @%s//:lock` to create the lockfile." % name) - - _deb_translate_lock( - name = name, - lock = lock if lock else "@" + name + "_resolve//:lock.json", - package_template = package_template, - ) - -apt = struct( - install = _apt_install, -) diff --git a/apt/private/BUILD.bazel b/apt/private/BUILD.bazel index 3d745bd7..fb570e35 100644 --- a/apt/private/BUILD.bazel +++ b/apt/private/BUILD.bazel @@ -95,6 +95,12 @@ bzl_library( deps = [":version"], ) +bzl_library( + name = "deb_postfix", + srcs = ["deb_postfix.bzl"], + visibility = ["//apt:__subpackages__"], +) + bzl_library( name = "starlark_codegen_utils", srcs = ["starlark_codegen_utils.bzl"], diff --git a/apt/private/deb_postfix.bzl b/apt/private/deb_postfix.bzl index 2baab000..cbf8cc60 100644 --- a/apt/private/deb_postfix.bzl +++ b/apt/private/deb_postfix.bzl @@ -12,7 +12,6 @@ def deb_postfix(name, srcs, outs, mergedusr = False, **kwargs): $(ZSTD_BIN) --compress --format=gzip "$$data_file" > "$$layer" ;; *data.tar.xz|*data.tar.zst|*data.tar.lzma) - realpath "$$data_file" $(ZSTD_BIN) --force --decompress --stdout "$$data_file" | $(ZSTD_BIN) --compress --format=gzip - > "$$layer" ;; diff --git a/distroless/BUILD.bazel b/distroless/BUILD.bazel index 940f271b..98400417 100644 --- a/distroless/BUILD.bazel +++ b/distroless/BUILD.bazel @@ -5,7 +5,6 @@ exports_files(["defs.bzl"]) bzl_library( name = "dependencies", - srcs = ["dependencies.bzl"], visibility = ["//visibility:public"], deps = [ "@bazel_tools//tools/build_defs/repo:http.bzl", diff --git a/distroless/dependencies.bzl b/distroless/dependencies.bzl deleted file mode 100644 index e2628321..00000000 --- a/distroless/dependencies.bzl +++ /dev/null @@ -1,44 +0,0 @@ -"""Declare runtime dependencies - -These are needed for local dev, and users must install them as well. -See https://docs.bazel.build/versions/main/skylark/deploying.html#dependencies -""" - -load("@bazel_tools//tools/build_defs/repo:http.bzl", _http_archive = "http_archive") -load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") - -def http_archive(name, **kwargs): - maybe(_http_archive, name = name, **kwargs) - -# WARNING: any changes in this function may be BREAKING CHANGES for users -# because we'll fetch a dependency which may be different from one that -# they were previously fetching later in their WORKSPACE setup, and now -# ours took precedence. Such breakages are challenging for users, so any -# changes in this function should be marked as BREAKING in the commit message -# and released only in semver majors. -# This is all fixed by bzlmod, so we just tolerate it for now. -def distroless_dependencies(): - # The minimal version of bazel_skylib we require - http_archive( - name = "bazel_skylib", - sha256 = "74d544d96f4a5bb630d465ca8bbcfe231e3594e5aae57e1edbf17a6eb3ca2506", - urls = [ - "https://github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz", - "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz", - ], - ) - - http_archive( - name = "aspect_bazel_lib", - sha256 = "87ab4ec479ebeb00d286266aca2068caeef1bb0b1765e8f71c7b6cfee6af4226", - strip_prefix = "bazel-lib-2.7.3", - url = "https://github.com/aspect-build/bazel-lib/releases/download/v2.7.3/bazel-lib-v2.7.3.tar.gz", - ) - - http_archive( - name = "rules_java", - urls = [ - "https://github.com/bazelbuild/rules_java/releases/download/8.3.2/rules_java-8.3.2.tar.gz", - ], - sha256 = "9b9614f8a7f7b7ed93cb7975d227ece30fe7daed2c0a76f03a5ee37f69e437de", - ) diff --git a/docs/BUILD.bazel b/docs/BUILD.bazel index 1a4e1985..74c8424e 100644 --- a/docs/BUILD.bazel +++ b/docs/BUILD.bazel @@ -19,10 +19,4 @@ stardoc_with_diff_test( renderer = "renderer", ) -stardoc_with_diff_test( - name = "apt_macro", - bzl_library_target = "@rules_distroless//apt:apt", - renderer = "renderer", -) - update_docs(name = "update")