Skip to content

Commit 17adb2a

Browse files
Only pass in --bazel-version-file if stamping is enabled (#84)
1 parent c83ca13 commit 17adb2a

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

docs/docs.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public API
77
## oci_image
88

99
<pre>
10-
oci_image(<a href="#oci_image-name">name</a>, <a href="#oci_image-annotations">annotations</a>, <a href="#oci_image-arch">arch</a>, <a href="#oci_image-base">base</a>, <a href="#oci_image-entrypoint">entrypoint</a>, <a href="#oci_image-env">env</a>, <a href="#oci_image-labels">labels</a>, <a href="#oci_image-layers">layers</a>, <a href="#oci_image-os">os</a>)
10+
oci_image(<a href="#oci_image-name">name</a>, <a href="#oci_image-annotations">annotations</a>, <a href="#oci_image-arch">arch</a>, <a href="#oci_image-base">base</a>, <a href="#oci_image-entrypoint">entrypoint</a>, <a href="#oci_image-env">env</a>, <a href="#oci_image-labels">labels</a>, <a href="#oci_image-layers">layers</a>, <a href="#oci_image-os">os</a>, <a href="#oci_image-stamp">stamp</a>)
1111
</pre>
1212

1313
Creates a new image manifest and config by appending the `layers` to an existing image
@@ -28,6 +28,7 @@ be used to extract the image manifest.
2828
| <a id="oci_image-labels"></a>labels | labels that will be applied to the image configuration, as defined in [the OCI config](https://github.com/opencontainers/image-spec/blob/main/config.md#properties). These behave the same way as [docker LABEL](https://docs.docker.com/engine/reference/builder/#label); in particular, labels from the base image are inherited. An empty value for a label will cause that label to be deleted. For backwards compatibility, if this is not set, then the value of annotations will be used instead. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{}` |
2929
| <a id="oci_image-layers"></a>layers | A list of layers defined by oci_image_layer | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
3030
| <a id="oci_image-os"></a>os | Used to extract a manifest from base if base is an index | String | optional | `""` |
31+
| <a id="oci_image-stamp"></a>stamp | Whether to encode build information into the output. Possible values:<br><br>- `stamp = 1`: Always stamp the build information into the output, even in [--nostamp](https://docs.bazel.build/versions/main/user-manual.html#flag--stamp) builds. This setting should be avoided, since it is non-deterministic. It potentially causes remote cache misses for the target and any downstream actions that depend on the result. - `stamp = 0`: Never stamp, instead replace build information by constant values. This gives good build result caching. - `stamp = -1`: Embedding of build information is controlled by the [--[no]stamp](https://docs.bazel.build/versions/main/user-manual.html#flag--stamp) flag. Stamped targets are not rebuilt unless their dependencies change. | Integer | optional | `-1` |
3132

3233

3334
<a id="oci_image_config"></a>

oci/image.bzl

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
""" image """
22

3+
load("@aspect_bazel_lib//lib:stamping.bzl", "STAMP_ATTRS", "maybe_stamp")
34
load("@com_github_datadog_rules_oci//oci:providers.bzl", "OCIDescriptor", "OCILayout")
45

56
# buildifier: disable=function-docstring
@@ -118,12 +119,15 @@ def _oci_image_impl(ctx):
118119
[f.path for f in layer_descriptor_files],
119120
)
120121

122+
stamp_args = []
123+
if maybe_stamp(ctx):
124+
stamp_args.append("--bazel-version-file={}".format(ctx.version_file.path))
125+
121126
ctx.actions.run(
122127
executable = toolchain.sdk.ocitool,
123128
arguments = [
124129
"--layout={}".format(base_layout.blob_index.path),
125130
"append-layers",
126-
"--bazel-version-file={}".format(ctx.version_file.path),
127131
"--base={}".format(base_desc.path),
128132
"--os={}".format(ctx.attr.os),
129133
"--arch={}".format(ctx.attr.arch),
@@ -139,7 +143,8 @@ def _oci_image_impl(ctx):
139143
] +
140144
["--annotations={}={}".format(k, v) for k, v in annotations.items()] +
141145
["--labels={}={}".format(k, v) for k, v in labels.items()] +
142-
["--env={}".format(env) for env in ctx.attr.env],
146+
["--env={}".format(env) for env in ctx.attr.env] +
147+
stamp_args,
143148
inputs = [
144149
ctx.version_file,
145150
base_desc,
@@ -183,7 +188,7 @@ oci_image = rule(
183188
doc = """Creates a new image manifest and config by appending the `layers` to an existing image
184189
manifest and config defined by `base`. If `base` is an image index, then `os` and `arch` will
185190
be used to extract the image manifest.""",
186-
attrs = {
191+
attrs = dict({
187192
"base": attr.label(
188193
doc = """A base image, as defined by oci_pull or oci_image""",
189194
mandatory = True,
@@ -225,7 +230,7 @@ oci_image = rule(
225230
will cause that label to be deleted. For backwards compatibility, if this is not set,
226231
then the value of annotations will be used instead.""",
227232
),
228-
},
233+
}, **STAMP_ATTRS),
229234
toolchains = ["@com_github_datadog_rules_oci//oci:toolchain"],
230235
provides = [OCIDescriptor, OCILayout],
231236
)

0 commit comments

Comments
 (0)