diff --git a/docs/js_image_layer.md b/docs/js_image_layer.md
index 8ee585ad44..516568bf12 100644
--- a/docs/js_image_layer.md
+++ b/docs/js_image_layer.md
@@ -19,7 +19,7 @@ js_image_layer(
## js_image_layer
-js_image_layer(name, binary, compression, owner, platform, root)
+js_image_layer(name, binary, compression, generate_empty_layers, owner, platform, root)
Create container image layers from js_binary targets.
@@ -269,6 +269,7 @@ container_image(
| name | A unique name for this target. | Name | required | |
| binary | Label to an js_binary target | Label | required | |
| compression | Compression algorithm. Can be one of `gzip`, `none`. | String | optional | `"gzip"` |
+| generate_empty_layers | Generate layers even if they are empty.
Helpful when using js_image_layer with rules_docker. See https://github.com/aspect-build/rules_js/pull/1714 for more info | Boolean | optional | `False` |
| owner | Owner of the entries, in `GID:UID` format. By default `0:0` (root, root) is used. | String | optional | `"0:0"` |
| platform | Platform to transition. | Label | optional | `None` |
| root | Path where the files from js_binary will reside in. eg: /apps/app1 or /app | String | optional | `""` |
diff --git a/e2e/js_image_docker/BUILD.bazel b/e2e/js_image_docker/BUILD.bazel
index fafc5d8f42..ee6542ba94 100644
--- a/e2e/js_image_docker/BUILD.bazel
+++ b/e2e/js_image_docker/BUILD.bazel
@@ -42,6 +42,7 @@ js_binary(
js_image_layer(
name = "layers",
binary = ":bin",
+ generate_empty_layers = True,
root = "/app",
visibility = ["//visibility:__pkg__"],
)
@@ -68,6 +69,17 @@ container_layer(
tars = [":package_store_3p_tar"],
)
+filegroup(
+ name = "package_store_1p_tar",
+ srcs = [":layers"],
+ output_group = "package_store_1p",
+)
+
+container_layer(
+ name = "package_store_1p_layer",
+ tars = [":package_store_1p_tar"],
+)
+
filegroup(
name = "node_modules_tar",
srcs = [":layers"],
@@ -101,6 +113,7 @@ container_image(
layers = [
":node_layer",
":package_store_3p_layer",
+ ":package_store_1p_layer",
":node_modules_layer",
":app_layer",
],
diff --git a/js/private/js_image_layer.bzl b/js/private/js_image_layer.bzl
index 8a3e11f16e..cc45179415 100644
--- a/js/private/js_image_layer.bzl
+++ b/js/private/js_image_layer.bzl
@@ -279,7 +279,7 @@ def _runfile_path(ctx, file, runfiles_dir):
return paths.join(runfiles_dir, to_rlocation_path(ctx, file))
def _build_layer(ctx, type, all_entries_json, entries, inputs):
- if not entries:
+ if not entries and not ctx.attr.generate_empty_layers:
return None
entries_json = ctx.actions.declare_file("{}_{}_entries.json".format(ctx.label.name, type))
@@ -490,6 +490,12 @@ js_image_layer_lib = struct(
"platform": attr.label(
doc = "Platform to transition.",
),
+ "generate_empty_layers": attr.bool(
+ doc = """Generate layers even if they are empty.
+
+Helpful when using js_image_layer with rules_docker.
+See https://github.com/aspect-build/rules_js/pull/1714 for more info""",
+ ),
},
)