rules_helm
Bazel rules for producing helm charts
Setup MODULE.bazel
rules_helm is published to the
Bazel Central Registry:
bazel_dep(name = "rules_helm", version = "{version}")
Charts that bundle container images use one of the companion modules instead. See Container images.
Run as a tool
bazel run @helm//:helm -- ...
A matching kubectl is available for inspecting the cluster after a deploy. See
Kubernetes tools for setup.
bazel run @kubectl//:kubectl -- ...
Use in a genrule
genrule(
name = "genrule",
srcs = [":chart"],
outs = ["template.yaml"],
cmd = "$(HELM_BIN) template my-chart $(execpath :chart) > $@",
toolchains = ["@rules_helm//helm:current_toolchain"],
)
Environment variables
RULES_HELM_IMAGE_PUSH_CONCURRENCY
How many of a chart's bundled image pushers run at once. Defaults to 4, and applies to
helm_push,
helm_push_images,
helm_install and
helm_upgrade.
Each image is pushed by its own process, which authenticates with the registry before it looks at anything, so a chart with many images spends most of the push waiting rather than transferring. Running the pushers concurrently keeps that cost from scaling with the image count.
Set it to 1 to push one image at a time. A serial run also streams each pusher's output live on
its own streams, instead of capturing it and replaying it as a block once the pusher exits, which
makes a single failing push easier to follow.
Values that are not a positive integer are ignored with a warning.
Helm Rules
- chart_content
- chart_file
- helm_chart
- helm_command
- helm_image
- helm_import
- helm_install
- helm_lint_aspect
- helm_lint_test
- helm_oci_digest
- helm_package
- helm_plugin
- helm_push_images
- helm_push_registry
- helm_push
- helm_template_test
- helm_template
- helm_toolchain
- helm_uninstall
- helm_upgrade
- HelmImageInfo
- HelmPackageInfo
helm_chart rule.
Functions
helm_chart
load("@rules_helm//helm:helm_chart.bzl", "helm_chart")
helm_chart(*, name, chart, chart_json, crds, values, values_json, substitutions, templates, schema,
files, images, deps, install_name, registry_url, registry_url_file, login_url, push_cmd,
helm_opts, install_opts, package_opts, push_opts, upgrade_opts, uninstall_opts, data,
stamp, **kwargs)
Rules for producing a helm package and some convenience targets.
| target | rule | condition |
|---|---|---|
{name} | helm_package | None |
{name}.push_images | helm_push_images | None |
{name}.oci_digest | helm_oci_digest | None |
{name}.push_registry | helm_push (include_images = False) | registry_url or registry_url_file is defined. |
{name}.push | helm_push (include_images = True) | registry_url or registry_url_file is defined. |
{name}.install | helm_install | None |
{name}.uninstall | helm_uninstall | None |
{name}.upgrade | helm_upgrade | None |
PARAMETERS
| Name | Description | Default Value |
|---|---|---|
| name | The name of the helm_package target. | none |
| chart | The path to the chart directory. Defaults to Chart.yaml. | None |
| chart_json | The json encoded contents of Chart.yaml. | None |
| crds | A list of crd files to include in the package. | None |
| values | The path to the values file. Defaults to values.yaml. | None |
| values_json | The json encoded contents of values.yaml. | None |
| substitutions | A dictionary of substitutions to apply to values.yaml. | {} |
| templates | A list of template files to include in the package. | None |
| schema | A JSON Schema file for values. Defaults to values.schema.json. | None |
| files | Files accessed in templates via the .Files api. | [] |
| images | The container images the chart refers to. See helm_package.images. | [] |
| deps | A list of helm package dependencies. | None |
| install_name | The helm install name to use. name will be used if unset. | None |
| registry_url | The registry url for the helm chart. {name}.push_registry is only defined when a value is passed here. Mutually exclusive with registry_url_file. | None |
| registry_url_file | A file containing the registry url for the helm chart. {name}.push_registry is only defined when a value is passed here. Mutually exclusive with registry_url. | None |
| login_url | The registry url to log into for publishing helm charts. | None |
| push_cmd | An alternative command to push for publishing helm charts. | None |
| helm_opts | Additional options to pass to helm. | [] |
| install_opts | Additional options to pass to helm install. | [] |
| package_opts | Additional options to pass to helm package. | [] |
| push_opts | Additional options to pass to helm push. | [] |
| upgrade_opts | Additional options to pass to helm upgrade. | [] |
| uninstall_opts | Additional options to pass to helm uninstall. | [] |
| data | Additional runtime data to pass to the helm install, upgrade, and uninstall targets. | [] |
| stamp | Whether to encode build information into the helm chart. | None |
| kwargs | Additional keyword arguments for helm_package. | none |
helm_command rules.
Rules
helm_command
load("@rules_helm//helm:helm_command.bzl", "helm_command")
helm_command(name, data, command, helm_opts, install_name, opts, package, values)
Produce an executable that invokes helm with an arbitrary subcommand. Useful for wrapping helm plugins (e.g. helm-diff) without requiring a dedicated rule for each plugin.
Example:
load("@rules_helm//helm:defs.bzl", "helm_command")
helm_command(
name = "my_chart.diff",
command = ["diff", "upgrade"],
install_name = "my-chart",
package = ":my_chart",
)
Any helm plugin referenced by command must be registered in the active helm toolchain (see helm_plugin / helm_toolchain).
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| data | Additional data to pass to the helm invocation. | List of labels | optional | [] |
| command | Subcommand tokens placed between helm_opts and opts (e.g. ["diff", "upgrade"]). | List of strings | required | |
| helm_opts | Additional arguments to pass to helm before the subcommand. | List of strings | optional | [] |
| install_name | Release name appended as a positional after opts. Omitted when unset. | String | optional | "" |
| opts | Additional arguments to pass after the subcommand. | List of strings | optional | [] |
| package | Optional helm package. When set, its chart path is appended as the final positional argument. | Label | optional | None |
| values | Values files to pass to the subcommand via --values. | List of labels | optional | [] |
Helm images
HelmImageInfo is the contract between rules_helm and the rules that build
container images. helm_package.images accepts any target that provides it.
rules_helm provides it itself for oci_push, image_push and image_import
targets by recognising them by shape. The companion modules provide it from
the image rules' own providers instead:
rules_helm_img:helm_img_imagerules_helm_oci:helm_oci_image
helm_image is the reference implementation for anything else.
Rules
Providers
helm_image
load("@rules_helm//helm:helm_image.bzl", "helm_image")
helm_image(name, manifest, pusher, remote_tags, repository)
Describe a container image to rules_helm from plain files.
This is the reference implementation of HelmImageInfo, for images that are
built or pushed by something rules_helm does not know about. Values refer to
it by this target's label, e.g. {@//app:image}.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| manifest | The raw OCI manifest or index exactly as it is pushed. Its sha256 is the digest stamped into the chart. | Label | required | |
| pusher | An executable that pushes the image. Run before the chart is installed or pushed. Leave unset for images that are only referenced. | Label | optional | None |
| remote_tags | A file containing the remote tags, one per line. With exactly one tag, values may stamp {@label.tag}. | Label | optional | None |
| repository | A file containing <registry>/<repository> on a single line, with no scheme. | Label | required |
HelmImageInfo
load("@rules_helm//helm:helm_image.bzl", "HelmImageInfo")
HelmImageInfo(aliases, label, manifest, pusher, repository, runfiles, tags)
A container image a helm chart refers to.
This is the contract between rules_helm and the rules that build images.
rules_helm only reads it: the chart's values.yaml has {@label} style
references replaced with repository@digest, and pusher is run before the
chart is installed or pushed. Any rule may provide it. rules_helm adapts
oci_push, image_push and image_import targets itself and the companion
modules (rules_helm_img, rules_helm_oci) provide it from their image
rules' own providers.
FIELDS
helm_import rules.
Rules
Repository Rules
helm_import
load("@rules_helm//helm:helm_import.bzl", "helm_import")
helm_import(name, chart, version)
A rule that allows pre-packaged Helm charts to be used within Bazel.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| chart | A Helm chart's .tgz file. | Label | optional | None |
| version | The version fo the helm chart | String | optional | "" |
helm_import_repository
load("@rules_helm//helm:helm_import.bzl", "helm_import_repository")
helm_import_repository(name, chart_name, repository, sha256, url, version)
A rule for fetching external Helm charts from an arbitrary URL or repository.
With bzlmod, the helm_charts extension in @rules_helm//helm:extensions.bzl fetches
oci:// charts with this rule and stores the digest it looks up in MODULE.bazel.lock.
The repository exposes the chart as a helm_import target. The target takes its name and
version from the Chart.yaml of the chart, not from the file name or the tag of the url.
A chart fetched from oci://.../cert-manager:1.19.4 has the version v1.19.4 if its
Chart.yaml says so, and helm push uses that version as the tag. The name can use
letters, digits, -, . and _, and the version the same characters and +. Neither the
chart name nor the repository name can be license or package_metadata. The target is
aliased to the repository name, so @<name> resolves to it, unless the chart has the same
name as the repository. The repository also describes the chart for supply-chain tooling built on
package_metadata:
//:package_metadataidentifies the chart by purl,pkg:oci/...for a chart from an OCI registry andpkg:generic/...with thedownload_urland sha256checksumotherwise. It is thedefault_package_metadataof the repository.//:licensedeclares the chart's license, the SPDX identifier named by thelicensesorartifacthub.io/licenseannotation ofChart.yamlor recognized in theLICENSEfile shipped with the chart. It isNOASSERTIONwhen neither is available. The license file, if any, is kept next to the chart as the license text.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this repository. | Name | required | |
| chart_name | Chart name to import. Must be set if repository is specified | String | optional | "" |
| repository | Chart repository url where to locate the requested chart. Mutually exclusive with url. | String | optional | "" |
| sha256 | The expected SHA-256 hash of the chart imported. For an oci:// url, a chart already in the repository cache is then fetched without any request to the registry. | String | optional | "" |
| url | The url where a chart can be directly downloaded. Mutually exclusive with chart_name, repository, and version | String | optional | "" |
| version | Specify a version constraint for the chart version to use. Must be set if repository is specified. | String | optional | "" |
helm_install rules.
Rules
helm_install
load("@rules_helm//helm:helm_install.bzl", "helm_install")
helm_install(name, data, helm_opts, install_name, opts, package, values)
Produce an executable for performing a helm install operation.
Any images bundled into package are pushed first, at most RULES_HELM_IMAGE_PUSH_CONCURRENCY
(default 4) at a time.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| data | Additional data to pass to helm install. | List of labels | optional | [] |
| helm_opts | Additional arguments to pass to helm during install. | List of strings | optional | [] |
| install_name | The name to use for the helm install command. The target name will be used if unset. | String | optional | "" |
| opts | Additional arguments to pass to helm install. | List of strings | optional | [] |
| package | The helm package to install. | Label | required | |
| values | Values files to pass to helm install --values. | List of labels | optional | [] |
helm_uninstall
load("@rules_helm//helm:helm_install.bzl", "helm_uninstall")
helm_uninstall(name, data, helm_opts, install_name, opts)
Produce an executable for performing a helm uninstall operation.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| data | Additional data to pass to helm uninstall. | List of labels | optional | [] |
| helm_opts | Additional arguments to pass to helm during install. | List of strings | optional | [] |
| install_name | The name to use for the helm install command. The target name will be used if unset. | String | optional | "" |
| opts | Additional arguments to pass to helm uninstall. | List of strings | optional | [] |
helm_upgrade
load("@rules_helm//helm:helm_install.bzl", "helm_upgrade")
helm_upgrade(name, data, helm_opts, install_name, opts, package, values)
Produce an executable for performing a helm upgrade operation.
Any images bundled into package are pushed first, at most RULES_HELM_IMAGE_PUSH_CONCURRENCY
(default 4) at a time.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| data | Additional data to pass to helm upgrade. | List of labels | optional | [] |
| helm_opts | Additional arguments to pass to helm during upgrade. | List of strings | optional | [] |
| install_name | The name to use for the helm upgrade command. The target name will be used if unset. | String | optional | "" |
| opts | Additional arguments to pass to helm upgrade. | List of strings | optional | [] |
| package | The helm package to upgrade. | Label | required | |
| values | Values files to pass to helm upgrade --values. | List of labels | optional | [] |
helm_lint rules.
Rules
Aspects
helm_lint_test
load("@rules_helm//helm:helm_lint.bzl", "helm_lint_test")
helm_lint_test(name, chart, opts, substitutions, values)
A rule for performing helm lint on a helm package
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| chart | The helm package to run linting on. | Label | required | |
| opts | Additional arguments to pass to helm lint. | List of strings | optional | [] |
| substitutions | A dictionary of substitutions passed to `helm lint --set flag. | Dictionary: String -> String | optional | {} |
| values | A list of files passed to `helm lint --values flag. | List of labels | optional | [] |
helm_lint_aspect
load("@rules_helm//helm:helm_lint.bzl", "helm_lint_aspect")
helm_lint_aspect()
An aspect for running helm lint on helm package targets
ASPECT ATTRIBUTES
ATTRIBUTES
helm_oci_digest rules.
Rules
Providers
helm_oci_digest
load("@rules_helm//helm:helm_oci_digest.bzl", "helm_oci_digest")
helm_oci_digest(name, chart, registry_url, registry_url_file)
Compute the OCI manifest digest for a Helm chart at build time.
This rule constructs the OCI manifest that helm push (Helm v4) would
create and computes its sha256 digest. The creation annotation comes from
the chart's own org.opencontainers.image.created annotation, resolved by
the stamping pass, and is formatted in UTC to match the push side.
The digest file contains a single line: sha256:<hex>.
The manifest and config blobs are also emitted, so a pusher that uploads
them itself can PUT the exact bytes this digest was computed over. The
manifest annotations and the tag are emitted for a pusher that builds the
manifest itself. With registry_url or registry_url_file, so is the
repository helm push would push to. None of these are in the default
outputs; read them off HelmOCIDigestInfo or its output groups.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| chart | A helm_chart target providing HelmPackageInfo. | Label | required | |
| registry_url | The registry URL given to helm push, for example oci://registry.example.com/charts. Sets HelmOCIDigestInfo.repository. Only oci:// URLs are accepted; any other scheme fails the target, digest included. Mutually exclusive with registry_url_file. | String | optional | "" |
| registry_url_file | A file containing the registry URL given to helm push. Sets HelmOCIDigestInfo.repository. As with registry_url, only oci:// URLs are accepted. Mutually exclusive with registry_url. | Label | optional | None |
HelmOCIDigestInfo
load("@rules_helm//helm:helm_oci_digest.bzl", "HelmOCIDigestInfo")
HelmOCIDigestInfo(annotations, config, digest, manifest, repository, tag)
OCI manifest digest for a Helm chart, computed at build time.
FIELDS
helm_package rule.
Rules
helm_package
load("@rules_helm//helm:helm_package.bzl", "helm_package")
helm_package(name, deps, chart, chart_json, crds, files, images, opts, schema, stamp, substitutions,
templates, values, values_json)
Rules for creating Helm chart packages.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| deps | Other helm packages this package depends on. | List of labels | optional | [] |
| chart | The Chart.yaml file of the helm chart | Label | optional | None |
| chart_json | The Chart.yaml file of the helm chart as a json object | String | optional | "" |
| crds | All Custom Resource Definitions associated with the current helm chart. E.g., the ./crds directory | List of labels | optional | [] |
| files | Files accessed in templates via the .Files api | List of labels | optional | [] |
| images | The container images the chart refers to. Each is a target providing HelmImageInfo, or an oci_push, image_push or image_import (as generated by img_pull) target, which rules_helm describes itself. Pulled images are referenced by their source registry and are never pushed. | List of labels | optional | [] |
| opts | Additional arguments to pass to helm package commands. | List of strings | optional | [] |
| schema | The values.schema.json file for the current package. | Label | optional | None |
| stamp | Whether to encode build information into the helm actions. Possible values: - stamp = 1: Always stamp the build information into the helm actions, even in --nostamp builds. This setting should be avoided, since it potentially kills remote caching for the target and any downstream actions that depend on it.- stamp = 0: Always replace build information by constant values. This gives good build result caching.- stamp = -1: Embedding of build information is controlled by the --[no]stamp flag.Stamped targets are not rebuilt unless their dependencies change. | Integer | optional | -1 |
| substitutions | A dictionary of substitutions to apply to the values.yaml file. | Dictionary: String -> String | optional | {} |
| templates | All templates associated with the current helm chart. E.g., the ./templates directory | List of labels | optional | [] |
| values | The values.yaml file for the current package. | Label | optional | None |
| values_json | The values.yaml file for the current package as a json object. | String | optional | "" |
HelmPackageInfo provider
Providers
HelmPackageInfo
load("@rules_helm//helm:helm_package_info.bzl", "HelmPackageInfo")
HelmPackageInfo(chart, images, metadata)
A provider for helm packages
FIELDS
| Name | Description |
|---|---|
| chart | File: The result of helm package |
| images | list[HelmImageInfo]: The images bundled into the chart |
| metadata | File: A json encoded file containing metadata about the helm chart |
helm_plugin rule.
Rules
helm_plugin
load("@rules_helm//helm:helm_plugin.bzl", "helm_plugin")
helm_plugin(name, data, plugin_name, yaml)
Define a helm plugin.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| data | Additional files associated with the plugin. | List of labels | optional | [] |
| plugin_name | An explicit name for the plugin. If unset, name will be used. | String | optional | "" |
| yaml | The yaml file representing the plugin | Label | required |
helm_push rules.
Rules
helm_push
load("@rules_helm//helm:helm_push.bzl", "helm_push")
helm_push(name, env, include_images, login_url, opts, package, push_cmd, registry_url,
registry_url_file)
Produce an executable for performing a helm push to a registry.
Before performing helm push the executable produced will conditionally perform helm registry login
if the following environment variables are defined:
HELM_REGISTRY_USERNAME: The value of--username.HELM_REGISTRY_PASSWORD/HELM_REGISTRY_PASSWORD_FILE: The value of--passwordor a file containing the--passwordvalue.
When include_images is True, the chart's images are pushed concurrently, at most
RULES_HELM_IMAGE_PUSH_CONCURRENCY (default 4) at a time. Set it to 1 to push them one at a
time and stream each pusher's output live.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| env | Environment variables to set when running this target. | Dictionary: String -> String | optional | {} |
| include_images | If True, images depended on by package will be pushed as well. | Boolean | optional | False |
| login_url | The URL of the registry to use for helm login. E.g. my.registry.io | String | optional | "" |
| opts | Additional arguments to pass to helm commands. | List of strings | optional | [] |
| package | The helm package to push to the registry. | Label | required | |
| push_cmd | An alternative command to push for publishing the helm chart. E.g. cm-push | String | optional | "" |
| registry_url | The registry URL at which to push the helm chart to. E.g. oci://my.registry.io/chart-name. Mutually exclusive with registry_url_file. | String | optional | "" |
| registry_url_file | A file containing the registry URL at which to push the helm chart to. Mutually exclusive with registry_url. | Label | optional | None |
helm_push_images
load("@rules_helm//helm:helm_push.bzl", "helm_push_images")
helm_push_images(name, env, package)
Produce an executable for pushing all oci images used by a helm chart.
The images are pushed concurrently, at most RULES_HELM_IMAGE_PUSH_CONCURRENCY (default 4) at a
time. Set it to 1 to push them one at a time and stream each pusher's output live.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| env | Environment variables to set when running this target. | Dictionary: String -> String | optional | {} |
| package | The helm package to upload images from. | Label | required |
helm_push_registry
load("@rules_helm//helm:helm_push.bzl", "helm_push_registry")
helm_push_registry(name, env, include_images, login_url, opts, package, push_cmd, registry_url,
registry_url_file)
Produce an executable for performing a helm push to a registry.
Before performing helm push the executable produced will conditionally perform helm registry login
if the following environment variables are defined:
HELM_REGISTRY_USERNAME: The value of--username.HELM_REGISTRY_PASSWORD/HELM_REGISTRY_PASSWORD_FILE: The value of--passwordor a file containing the--passwordvalue.
When include_images is True, the chart's images are pushed concurrently, at most
RULES_HELM_IMAGE_PUSH_CONCURRENCY (default 4) at a time. Set it to 1 to push them one at a
time and stream each pusher's output live.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| env | Environment variables to set when running this target. | Dictionary: String -> String | optional | {} |
| include_images | If True, images depended on by package will be pushed as well. | Boolean | optional | False |
| login_url | The URL of the registry to use for helm login. E.g. my.registry.io | String | optional | "" |
| opts | Additional arguments to pass to helm commands. | List of strings | optional | [] |
| package | The helm package to push to the registry. | Label | required | |
| push_cmd | An alternative command to push for publishing the helm chart. E.g. cm-push | String | optional | "" |
| registry_url | The registry URL at which to push the helm chart to. E.g. oci://my.registry.io/chart-name. Mutually exclusive with registry_url_file. | String | optional | "" |
| registry_url_file | A file containing the registry URL at which to push the helm chart to. Mutually exclusive with registry_url. | Label | optional | None |
helm_template rules.
Rules
helm_template
load("@rules_helm//helm:helm_template.bzl", "helm_template")
helm_template(name, out, chart, opts, values)
A rule for rendering helm chart templates to a file.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| out | The output file to write the output from helm template. | Label; nonconfigurable | optional | None |
| chart | The helm package to resolve charts for. | Label | required | |
| opts | Additional arguments to pass to helm template. | List of strings | optional | [] |
| values | Values files to pass to helm template --values. | List of labels | optional | [] |
helm_template_test
load("@rules_helm//helm:helm_template.bzl", "helm_template_test")
helm_template_test(name, chart, installer, opts, template_patterns, values)
A test rule for rendering helm chart templates.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| chart | The helm package to resolve templates for. Mutually exclusive with installer. | Label | required | |
| installer | The helm_install/helm_upgrade target to resolve templates for. Mutually exclusive with chart. | Label | optional | None |
| opts | Additional arguments to pass to helm template. | List of strings | optional | [] |
| template_patterns | A mapping of template paths to regex patterns required to match. | Dictionary: String -> List of strings | optional | {} |
| values | Values files to pass to helm template --values. | List of labels | optional | [] |
helm_toolchain rule.
Rules
helm_toolchain
load("@rules_helm//helm:helm_toolchain.bzl", "helm_toolchain")
helm_toolchain(name, helm, plugins)
A helm toolchain.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| helm | A helm binary | Label | required | |
| plugins | Additional plugins to make available to helm. | List of labels | optional | [] |
Bzlmod extensions
Module Extensions
helm
helm = use_extension("@rules_helm//helm:extensions.bzl", "helm")
helm.host_tools(name, version)
helm.plugin(name, integrity, strip_prefix, url_templates, version, yaml)
helm.toolchain(name, plugins)
TAG CLASSES
host_tools
An extension for creating a host alias repository that provides a shorter name for the host platform's helm binary.
An example of defining and using host tools:
helm = use_extension("@rules_helm//helm:extensions.bzl", "helm")
helm.host_tools(name = "helm")
use_repo(helm, "helm")
# Then you can use @helm//:helm in your BUILD files
Attributes
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | The name of the host alias repository. | Name | optional | "helm" |
| version | The version of helm to use for host tools. | String | optional | "4.2.0" |
plugin
An extension tag for declaring Helm plugins.
Plugins are downloaded per-platform and made available to helm.toolchain() tags that reference them by name. Only platforms listed in integrity (and url_templates) will receive the plugin.
An example of declaring the helm-diff plugin and wiring it into a named toolchain:
helm = use_extension("@rules_helm//helm:extensions.bzl", "helm")
helm.host_tools()
helm.plugin(
name = "diff",
version = "3.15.5",
strip_prefix = "diff",
url_templates = {
"darwin-arm64": ["https://github.com/databus23/helm-diff/releases/download/v{version}/helm-diff-macos-arm64.tgz"],
"linux-amd64": ["https://github.com/databus23/helm-diff/releases/download/v{version}/helm-diff-linux-amd64.tgz"],
},
integrity = {
"darwin-arm64": "sha256-KJmZ7wY3gAcWFzK5R9+TfQlaRfEXzJ7hDNRC8NgIDog=",
"linux-amd64": "sha256-ToJjCrKyMxfAOeezsWYF95qKwPPSKHPg1G6pzZgN2o4=",
},
)
helm.toolchain(
name = "with_diff",
plugins = ["diff"],
)
use_repo(helm, "helm", "helm_toolchains", "with_diff_toolchains")
register_toolchains("@helm_toolchains//:all")
Attributes
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | The name of the plugin. | Name | required | |
| integrity | A mapping of helm platform name to integrity hash. Only platforms listed here will receive the plugin. | Dictionary: String -> String | required | |
| strip_prefix | A directory prefix to strip from the extracted plugin archive. | String | optional | "" |
| url_templates | Mapping of helm platform name to a list of URL templates for downloading the plugin on that platform. Only {version} is substituted; spell the platform name into the URL string directly. Every key in integrity must have a matching entry here. | Dictionary: String -> List of strings | required | |
| version | The version of the plugin to download. | String | required | |
| yaml | Relative path to plugin.yaml within the extracted archive (after strip_prefix). | String | optional | "plugin.yaml" |
toolchain
Define a named set of helm toolchains with specific plugins.
Creates an independent hub repository @{name}_toolchains containing toolchains for the default helm version with the specified plugins baked in. Only platforms where all referenced plugins are available will have toolchains generated.
The hub is not registered automatically — call register_toolchains explicitly, or use a Starlark transition to override toolchain resolution.
helm = use_extension("@rules_helm//helm:extensions.bzl", "helm")
helm.plugin(name = "diff", ...)
helm.toolchain(
name = "with_diff",
plugins = ["diff"],
)
use_repo(helm, "with_diff_toolchains")
register_toolchains("@with_diff_toolchains//:all")
Attributes
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | Name prefix for the hub repository. Produces @{name}_toolchains. | Name | required | |
| plugins | Plugin names (from helm.plugin() tags) to include in these toolchains. | List of strings | optional | [] |
helm_charts
helm_charts = use_extension("@rules_helm//helm:extensions.bzl", "helm_charts")
helm_charts.chart(name, sha256, url)
Module extension for fetching Helm charts from OCI registries.
Charts live in their own extension, so an unreachable registry does not stop the helm extension from resolving toolchains. All tags are resolved in one evaluation, so a lookup that fails (an unknown version or an unreachable registry) fails every repository from this extension. Set sha256 to skip the lookup. A command that loads a target from one of these repositories, such as bazel query, needs every lookup that has no stored fact. Tags from every module are used, so repository names must be unique across modules.
TAG CLASSES
chart
Fetch a Helm chart from an OCI registry with helm_import_repository.
The repository holds a helm_import target named after the name in the Chart.yaml of the chart, which is normally the last path segment of url without the version. Refer to it as @<name>//:<chart>. The shorthand @<name> is an alias of it, but only when the name in use_repo is the same as the tag name, because Bazel reads @x as @x//:x. Neither name nor the chart can be called license or package_metadata.
If sha256 is unset, the extension reads the digest of the chart package from the registry manifest, and trusts the registry for it on first use. On Bazel 8.5 and newer the digest is stored as a fact in MODULE.bazel.lock, keyed by url, so later evaluations make no registry request for it. Older Bazel versions record the digest in the lockfile as part of the repository. Without a lockfile, the digest is looked up whenever the extension is evaluated, and a version tag that the registry moves gives a different chart. Set sha256 to pin the digest in MODULE.bazel.
Each lookup is a token request and a manifest download, and the lookups run one after another. While a lookup is needed, an unreachable registry fails the evaluation, and so fails every target that depends on a repository from this extension. This applies whenever no stored fact exists: with the lockfile off, on the first evaluation, or after you delete the fact. A tag with sha256 makes no lookup while the extension evaluates. Fetching the chart can still contact the registry, unless the chart is in the repository cache.
A stored digest is not checked against the registry. If the registry replaces the chart behind a version tag, the fetch fails with a checksum mismatch. Delete the entry for url from the facts section of MODULE.bazel.lock to look the digest up again.
helm_charts = use_extension("@rules_helm//helm:extensions.bzl", "helm_charts")
helm_charts.chart(
name = "karpenter",
url = "oci://public.ecr.aws/karpenter/karpenter:1.9.0",
)
use_repo(helm_charts, "karpenter")
# Then you can use @karpenter//:karpenter as a dependency in your BUILD files
Attributes
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | The name of the repository. | Name | required | |
| sha256 | The expected SHA-256 hash of the chart package. If unset, the extension looks it up in the registry. | String | optional | "" |
| url | The chart url, in the form oci://<host>/<path>:<version>. | String | required |
Container images
A chart's images attribute accepts push targets from
rules_oci and
rules_img, and rules_helm
stamps the pushed repository and digest into the chart. rules_helm itself
depends on neither. Each is wired up by a companion module that lives in this
repository under extensions/
and is released from the same tag, with the same version, as rules_helm.
| Module | Depends on | Load from |
|---|---|---|
rules_helm_img | rules_img | @rules_helm_img//:defs.bzl |
rules_helm_oci | rules_oci | @rules_helm_oci//:defs.bzl |
As in rules_helm, each rule also has its own file next to defs.bzl, e.g.
@rules_helm_img//:helm_img_image.bzl, for BUILD files that only want one
thing.
Each module re-exports every public symbol of @rules_helm//helm:defs.bzl
plus the push rule its image rules provide (image_push or oci_push), so a
chart that bundles images is written against one load. Rules that are
specific to one set of image rules land in its module rather than in
rules_helm.
The contract
rules_helm reads one thing from an image:
HelmImageInfo. It carries the label values
refer to, a repository file, the raw manifest whose sha256 is the digest, the
remote tags, and the executable that pushes the image. helm_package.images
accepts any target that provides it.
Three things provide it today:
rules_helmitself, foroci_push,image_pushandimage_importtargets listed directly inimages. An aspect recognises them by shape and reads their attributes, which is all it can do without depending on either ruleset. This is what keeps existing charts working unchanged.- helm_img_image from
rules_helm_imgand helm_oci_image fromrules_helm_oci. These read the image rules' own providers (DeployInfoandPullInfoin the case ofrules_img) and are the preferred path for new charts. Values keep referring to the wrapped push target. - helm_image from
rules_helm, which takes the files directly, for images built by something else entirely.
Setup
bazel_dep(name = "rules_helm_img", version = "{version}")
A bazel_dep on the companion module pulls in rules_helm, so it does not
need to be listed separately. The rules for building the images themselves
(image_manifest, oci_image and friends) are still loaded from rules_img
or rules_oci, which means a direct bazel_dep on whichever one you use.
Example
load("@rules_helm_img//:defs.bzl", "helm_chart", "helm_img_image", "image_push")
load("@rules_img//img:image.bzl", "image_manifest")
image_manifest(
name = "app",
layers = [":app_layer"],
)
image_push(
name = "app.push",
image = ":app",
registry = "docker.io",
repository = "my-org/app",
tags = ["latest"],
)
helm_img_image(
name = "app.helm",
image = ":app.push",
)
helm_chart(
name = "chart",
images = [":app.helm"],
)
With values.yaml referencing the push target by label:
image: "{@//:app.push}"
The packaged chart carries docker.io/my-org/app@sha256:... in its place.
Pushing the chart with multi_deploy
rules_img's multi_deploy pushes all of its operations in one run, but
only targets that provide DeployInfo or MultipleDeployInfo can be
operations, and helm_push provides neither. helm_oci_manifest
from rules_helm_img describes the chart as the OCI artifact helm push
creates, so the chart and its images can be pushed together:
load("@rules_helm_img//:defs.bzl", "helm_oci_manifest")
load("@rules_img//img:multi_deploy.bzl", "multi_deploy")
helm_oci_manifest(
name = "chart.oci_manifest",
chart = ":chart",
registry_url = "oci://registry.example.com/charts",
)
multi_deploy(
name = "deploy",
operations = [
":app.push",
":chart.oci_manifest",
],
)
helm_img_image rule.
Rules
helm_img_image
load("@rules_helm_img//:helm_img_image.bzl", "helm_img_image")
helm_img_image(name, image)
Describe a rules_img image to rules_helm.
Accepts an image_push target, or an image_import target as generated by
img_pull, and provides HelmImageInfo from their DeployInfo and PullInfo
providers. Values keep referring to the wrapped target, e.g.
{@//app:image.push}.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| image | An image_push or image_import target. | Label | required |
helm_oci_manifest macro.
Functions
helm_oci_manifest
load("@rules_helm_img//:helm_oci_manifest.bzl", "helm_oci_manifest")
helm_oci_manifest(*, name, chart, registry_url, registry_url_file, visibility, **kwargs)
Describe a chart as the OCI artifact helm push creates, for rules_img's multi_deploy.
The target is an image_manifest that provides DeployInfo, so it can be listed in the
operations of a multi_deploy. Running the
multi_deploy pushes the chart to <registry_url>/<chart name>:<chart version>, with +
in the version replaced by _, as helm push would. Only the chart is pushed; push its
images with their own targets.
load("@rules_helm_img//:defs.bzl", "helm_oci_manifest")
load("@rules_img//img:multi_deploy.bzl", "multi_deploy")
helm_oci_manifest(
name = "my_chart_oci_manifest",
chart = ":my_chart",
registry_url = "oci://registry.example.com/charts",
)
multi_deploy(
name = "deploy",
operations = [":my_chart_oci_manifest"],
)
The pushed manifest is the one helm push creates when it runs in UTC, so its digest is the
one helm_oci_digest gives. Helm writes the
org.opencontainers.image.created annotation in the local time zone, so helm push in
another zone pushes a different digest for the same chart.
Compared with helm_push:
- Only
oci://registries are supported, sopush_cmdand plugins such ascm-pushare not. - Registry credentials come from
rules_img(Docker config and credential helpers), not from theHELM_REGISTRY_*variables (HELM_REGISTRY_USERNAME,HELM_REGISTRY_PASSWORDandHELM_REGISTRY_PASSWORD_FILE). - There is no
include_images.
rules_img expands Go templates in annotation values. {{ in a chart's metadata is escaped,
so the annotations match the chart.
| target | rule |
|---|---|
{name} | image_manifest |
{name}.oci_digest | helm_oci_digest |
{name}.files | config blob, annotations, tag, repository and layer files |
{name}.layer | layer_from_file |
{name}.push_spec | image_push_spec |
PARAMETERS
| Name | Description | Default Value |
|---|---|---|
| name | The name of the image_manifest target. | none |
| chart | A helm_chart or helm_package target. Charts from helm_import are not supported. | none |
| registry_url | The registry URL given to helm push, for example oci://registry.example.com/charts. Mutually exclusive with registry_url_file. | None |
| registry_url_file | A file containing the registry URL. Mutually exclusive with registry_url. | None |
| visibility | The visibility of {name}. The other targets are private. | None |
| kwargs | Common attributes such as tags, target_compatible_with and testonly, applied to every target. | none |
helm_oci_image rule.
Rules
helm_oci_image
load("@rules_helm_oci//:helm_oci_image.bzl", "helm_oci_image")
helm_oci_image(name, image)
Describe a rules_oci image to rules_helm.
Accepts an oci_push target and provides HelmImageInfo for the image it
pushes. Values keep referring to the wrapped target, e.g. {@//app:image.push}.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| image | An oci_push target. | Label | required |