Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ use_repo(busybox, "busybox_amd64", "busybox_arm", "busybox_arm64", "busybox_ppc6
### NODE ###
node = use_extension("//private/extensions:node.bzl", "node")
node.archive()
use_repo(node, "nodejs22_amd64", "nodejs22_arm", "nodejs22_arm64", "nodejs22_ppc64le", "nodejs22_s390x", "nodejs24_amd64", "nodejs24_arm64", "nodejs24_ppc64le", "nodejs24_s390x", "nodejs26_amd64", "nodejs26_arm64", "nodejs26_ppc64le", "nodejs26_s390x")
use_repo(node, "node_versions", "nodejs22_amd64", "nodejs22_arm", "nodejs22_arm64", "nodejs22_ppc64le", "nodejs22_s390x", "nodejs24_amd64", "nodejs24_arm64", "nodejs24_ppc64le", "nodejs24_s390x", "nodejs26_amd64", "nodejs26_arm64", "nodejs26_ppc64le", "nodejs26_s390x")

### DEBIAN ###
include("//private/repos/deb:deb.MODULE.bazel")
35 changes: 34 additions & 1 deletion knife.d/update_node_archives.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,24 @@ node_archive = repository_rule(
},
)

_NODE_VERSIONS_TMPL = """\\
"node versions"

# AUTO GENERATED. DO NOT EDIT.
NODEJS_VERSIONS = {versions}
"""

def _node_versions_repo_impl(rctx):
rctx.file("versions.bzl", _NODE_VERSIONS_TMPL.format(versions = str(rctx.attr.versions)))
rctx.file("BUILD.bazel", 'exports_files(["versions.bzl"])')

node_versions_repo = repository_rule(
implementation = _node_versions_repo_impl,
attrs = {
"versions": attr.string_dict(),
},
)

def _node_impl(module_ctx):
mod = module_ctx.modules[0]

Expand Down Expand Up @@ -202,8 +220,23 @@ commandTests:
}
nodeArchives += `

node_versions_repo(
name = "node_versions",
versions = {`;

for (const nodeVersion of versions) {
const major = parseInt(nodeVersion.split(".")[0]);
nodeArchives += `
"${major}": "${nodeVersion}",`;
}

nodeArchives += `
},
)

return module_ctx.extension_metadata(
root_module_direct_deps = [`;
root_module_direct_deps = [
"node_versions",`;

for (const nodeVersion of versions) {
const major = parseInt(nodeVersion.split(".")[0]);
Expand Down
12 changes: 12 additions & 0 deletions nodejs/nodejs.bzl
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
"nodejs image definitions"

load("@container_structure_test//:defs.bzl", "container_structure_test")
load("@node_versions//:versions.bzl", "NODEJS_VERSIONS")
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_image_index")
load("//common:variables.bzl", "DEBUG_MODE", "USERS")
load("//private/util:deb.bzl", "deb")
load("//private/util:tar.bzl", "tar")

_DISTROLESS_SOURCE_URL = "https://github.com/GoogleContainerTools/distroless"

def nodejs_image_index(distro, major_version, architectures):
"""nodejs image index for a distro.

Expand Down Expand Up @@ -45,6 +48,14 @@ def nodejs_image(distro, major_version, arch, packages):
packages: any deb packages to add to the image
"""

if major_version not in NODEJS_VERSIONS:
fail("No version found for Node.js major version: " + major_version)
_annotations = {
"org.opencontainers.image.source": _DISTROLESS_SOURCE_URL,
"org.opencontainers.image.url": _DISTROLESS_SOURCE_URL,
"org.opencontainers.image.version": NODEJS_VERSIONS[major_version],
}

for mode in DEBUG_MODE:
for user in USERS:
oci_image(
Expand All @@ -57,6 +68,7 @@ def nodejs_image(distro, major_version, arch, packages):
] + [
"@nodejs" + major_version + "_" + arch,
],
annotations = _annotations,
)

_check_certificates_tar()
Expand Down
28 changes: 28 additions & 0 deletions private/extensions/node.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,24 @@ node_archive = repository_rule(
},
)

_NODE_VERSIONS_TMPL = """\
"node versions"
# AUTO GENERATED. DO NOT EDIT.
NODEJS_VERSIONS = {versions}
"""

def _node_versions_repo_impl(rctx):
rctx.file("versions.bzl", _NODE_VERSIONS_TMPL.format(versions = str(rctx.attr.versions)))
rctx.file("BUILD.bazel", 'exports_files(["versions.bzl"])')

node_versions_repo = repository_rule(
implementation = _node_versions_repo_impl,
attrs = {
"versions": attr.string_dict(),
},
)

def _node_impl(module_ctx):
mod = module_ctx.modules[0]

Expand Down Expand Up @@ -229,8 +247,18 @@ def _node_impl(module_ctx):
control = "//nodejs:control",
)

node_versions_repo(
name = "node_versions",
versions = {
"22": "22.23.0",
"24": "24.17.0",
"26": "26.3.1",
},
)

return module_ctx.extension_metadata(
root_module_direct_deps = [
"node_versions",
"nodejs22_amd64",
"nodejs22_arm64",
"nodejs22_arm",
Expand Down