diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel index ac68fbb..25994f8 100644 --- a/WORKSPACE.bazel +++ b/WORKSPACE.bazel @@ -36,11 +36,10 @@ load("@bullseye//:packages.bzl", "bullseye_packages") bullseye_packages() -# bazel run @apt_security//:lock deb_index( name = "apt_security", - # lock = "//examples/debian_snapshot_security:security.lock.json", manifest = "//examples/debian_snapshot_security:security.yaml", + nolock = True, ) load("@apt_security//:packages.bzl", "apt_security_packages") diff --git a/apt/extensions.bzl b/apt/extensions.bzl index 1352129..8cef957 100644 --- a/apt/extensions.bzl +++ b/apt/extensions.bzl @@ -20,8 +20,9 @@ def _distroless_extension(module_ctx): install.resolve_transitive, ) - # buildifier: disable=print - print("\nNo lockfile was given, please run `bazel run @%s//:lock` to create the lockfile." % install.name) + if not install.nolock: + # buildifier: disable=print + print("\nNo lockfile was given, please run `bazel run @%s//:lock` to create the lockfile." % install.name) else: lockf = lockfile.from_json(module_ctx, module_ctx.read(install.lock)) @@ -65,6 +66,10 @@ def _distroless_extension(module_ctx): install = tag_class(attrs = { "name": attr.string(doc = "Name of the generated repository"), "lock": attr.label(doc = """The lock file to use for the index."""), + "nolock": attr.bool( + doc = """If you explicitly want to run without a lock, set it to True to avoid the DEBUG messages.""", + default = False, + ), "manifest": attr.label(doc = """The file used to generate the lock file"""), "resolve_transitive": attr.bool( doc = """Whether dependencies of dependencies should be resolved and added to the lockfile.""", diff --git a/apt/index.bzl b/apt/index.bzl index 8cb0139..b23c31b 100644 --- a/apt/index.bzl +++ b/apt/index.bzl @@ -7,6 +7,7 @@ def deb_index( name, manifest, lock = None, + nolock = False, package_template = None, resolve_transitive = True): """A convience repository macro for apt rules. @@ -20,9 +21,13 @@ def deb_index( deb_index( name = "bullseye", - # For the initial setup, the lockfile attribute can be omitted and generated by running + # For the initial setup, the lockfile attribute can be omitted and + # generated by running # bazel run @bullseye//:lock - # This will generate the lock.json file next to the manifest file by replacing `.yaml` with `.lock.json` + # This will generate the lock.json file next to the manifest file by + # replacing `.yaml` with `.lock.json`. + # If you explicitly want to run without a lock, set nolock to True to + # avoid the DEBUG messages lock = "//examples/apt:bullseye.lock.json", manifest = "//examples/apt:bullseye.yaml", ) @@ -57,6 +62,8 @@ def deb_index( 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. + If you explicitly want to run without a lock, set the `nolock` attribute to True to avoid the DEBUG messages. + #### Snapshot repositories ##### Debian @@ -73,6 +80,7 @@ def deb_index( 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. @@ -83,7 +91,7 @@ def deb_index( resolve_transitive = resolve_transitive, ) - if not lock: + 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) diff --git a/docs/apt.md b/docs/apt.md index c2e7799..c879469 100644 --- a/docs/apt.md +++ b/docs/apt.md @@ -7,7 +7,7 @@ apt-get ## deb_index
-deb_index(name, manifest, lock, package_template, resolve_transitive)
+deb_index(name, manifest, lock, nolock, package_template, resolve_transitive)
 
A convience repository macro for apt rules. @@ -21,9 +21,13 @@ load("@rules_distroless//apt:index.bzl", "deb_index") deb_index( name = "bullseye", - # For the initial setup, the lockfile attribute can be omitted and generated by running + # For the initial setup, the lockfile attribute can be omitted and + # generated by running # bazel run @bullseye//:lock - # This will generate the lock.json file next to the manifest file by replacing `.yaml` with `.lock.json` + # This will generate the lock.json file next to the manifest file by + # replacing `.yaml` with `.lock.json`. + # If you explicitly want to run without a lock, set nolock to True to + # avoid the DEBUG messages lock = "//examples/apt:bullseye.lock.json", manifest = "//examples/apt:bullseye.yaml", ) @@ -58,6 +62,8 @@ The lockfile generation can be on-demand by omitting the `lock` attribute. Howev 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. +If you explicitly want to run without a lock, set the `nolock` attribute to True to avoid the DEBUG messages. + #### Snapshot repositories ##### Debian @@ -79,6 +85,7 @@ An example of this can be found at [/examples/ubuntu_snapshot](/examples/ubuntu_ | name | name of the repository | none | | manifest | label to a manifest.yaml | none | | lock | label to a lock.json | None | +| nolock | bool, set to True if you explicitly want to run without a lock and avoid the DEBUG messages. | False | | package_template | (EXPERIMENTAL!) a template file for generated BUILD files. Available template replacement keys are: {target_name}, {deps}, {urls}, {name}, {arch}, {sha256}, {repo_name} | None | | resolve_transitive | whether dependencies of dependencies should be resolved and added to the lockfile. | True | diff --git a/e2e/smoke/MODULE.bazel b/e2e/smoke/MODULE.bazel index 36afa19..74b5455 100644 --- a/e2e/smoke/MODULE.bazel +++ b/e2e/smoke/MODULE.bazel @@ -18,8 +18,8 @@ apt.install( ) apt.install( name = "bullseye_nolock", - # lock = ":bullseye.lock.json", manifest = ":bullseye.yaml", + nolock = True, ) # bazel run @bullseye//:lock