Skip to main content
Version: 1.23.x

js_image_layer

Rules for creating container image layers from js_binary targets

For example, this js_image_layer target outputs node_modules.tar and app.tar with /app prefix.

load("@aspect_rules_js//js:defs.bzl", "js_image_layer")

js_image_layer(
name = "layers",
binary = "//label/to:js_binary",
root = "/app",
)

Rules

js_image_layer

Create container image layers from js_binary targets.

js_image_layer supports transitioning to specific platform for cross-compiling.

A partial example using rules_oci with transition to linux/amd64 platform.

load("@aspect_rules_js//js:defs.bzl", "js_binary", "js_image_layer")
load("@contrib_rules_oci//oci:defs.bzl", "oci_image")

js_binary(
name = "binary",
entry_point = "main.js",
)

platform(
name = "amd64_linux",
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
)

js_image_layer(
name = "layers",
binary = ":binary",
platform = ":amd64_linux",
root = "/app"
)

oci_image(
name = "image",
cmd = ["/app/main"],
entrypoint = ["bash"],
tars = [
":layers"
]
)

An example using legacy rules_docker

See e2e/js_image_rules_docker for full example.

load("@aspect_rules_js//js:defs.bzl", "js_binary", "js_image_layer")
load("@io_bazel_rules_docker//container:container.bzl", "container_image")

js_binary(
name = "main",
data = [
"//:node_modules/args-parser",
],
entry_point = "main.js",
)


js_image_layer(
name = "layers",
binary = ":main",
root = "/app",
visibility = ["//visibility:__pkg__"],
)

filegroup(
name = "app_tar",
srcs = [":layers"],
output_group = "app"
)
container_layer(
name = "app_layer",
tars = [":app_tar"],
)

filegroup(
name = "node_modules_tar",
srcs = [":layers"],
output_group = "node_modules"
)
container_layer(
name = "node_modules_layer",
tars = [":node_modules_tar"],
)

container_image(
name = "image",
cmd = ["/app/main"],
entrypoint = ["bash"],
layers = [
":app_layer",
":node_modules_layer",
],
)

name

Required name.

A unique name for this target.

binary

Required label.

Label to an js_binary target

compression

Optional string. Default: "gzip"

Compression algorithm. Can be one of gzip, none.

platform

Optional label. Default: None

Platform to transition.

root

Optional string. Default: ""

Path where the files from js_binary will reside in. eg: /apps/app1 or /app

Macros and Functions

js_image_layer_lib.implementation

Example usage (generated):

load("@aspect_rules_js//js:defs.bzl", "js_image_layer_lib")

js_image_layer_lib.implementation(
ctx = None,
)

ctx

Required.