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

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.

targetrulecondition
{name}helm_packageNone
{name}.push_imageshelm_push_imagesNone
{name}.oci_digesthelm_oci_digestNone
{name}.push_registryhelm_push (include_images = False)registry_url or registry_url_file is defined.
{name}.pushhelm_push (include_images = True)registry_url or registry_url_file is defined.
{name}.installhelm_installNone
{name}.uninstallhelm_uninstallNone
{name}.upgradehelm_upgradeNone

PARAMETERS

NameDescriptionDefault Value
nameThe name of the helm_package target.none
chartThe path to the chart directory. Defaults to Chart.yaml.None
chart_jsonThe json encoded contents of Chart.yaml.None
crdsA list of crd files to include in the package.None
valuesThe path to the values file. Defaults to values.yaml.None
values_jsonThe json encoded contents of values.yaml.None
substitutionsA dictionary of substitutions to apply to values.yaml.{}
templatesA list of template files to include in the package.None
schemaA JSON Schema file for values. Defaults to values.schema.json.None
filesFiles accessed in templates via the .Files api.[]
imagesThe container images the chart refers to. See helm_package.images.[]
depsA list of helm package dependencies.None
install_nameThe helm install name to use. name will be used if unset.None
registry_urlThe 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_fileA 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_urlThe registry url to log into for publishing helm charts.None
push_cmdAn alternative command to push for publishing helm charts.None
helm_optsAdditional options to pass to helm.[]
install_optsAdditional options to pass to helm install.[]
package_optsAdditional options to pass to helm package.[]
push_optsAdditional options to pass to helm push.[]
upgrade_optsAdditional options to pass to helm upgrade.[]
uninstall_optsAdditional options to pass to helm uninstall.[]
dataAdditional runtime data to pass to the helm install, upgrade, and uninstall targets.[]
stampWhether to encode build information into the helm chart.None
kwargsAdditional 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

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
dataAdditional data to pass to the helm invocation.List of labelsoptional[]
commandSubcommand tokens placed between helm_opts and opts (e.g. ["diff", "upgrade"]).List of stringsrequired
helm_optsAdditional arguments to pass to helm before the subcommand.List of stringsoptional[]
install_nameRelease name appended as a positional after opts. Omitted when unset.Stringoptional""
optsAdditional arguments to pass after the subcommand.List of stringsoptional[]
packageOptional helm package. When set, its chart path is appended as the final positional argument.LabeloptionalNone
valuesValues files to pass to the subcommand via --values.List of labelsoptional[]

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_image
  • rules_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

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
manifestThe raw OCI manifest or index exactly as it is pushed. Its sha256 is the digest stamped into the chart.Labelrequired
pusherAn executable that pushes the image. Run before the chart is installed or pushed. Leave unset for images that are only referenced.LabeloptionalNone
remote_tagsA file containing the remote tags, one per line. With exactly one tag, values may stamp {@label.tag}.LabeloptionalNone
repositoryA file containing <registry>/<repository> on a single line, with no scheme.Labelrequired

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

NameDescription
aliaseslist[Label]: Other labels values may use to refer to the image.
labelLabel: The label values use to refer to the image, e.g. {@//app:image.push}.
manifestFile: The raw OCI manifest or index, byte for byte what is pushed or was pulled. Its sha256 is the image digest.
pusherFile (optional): An executable that pushes the image. None for pulled images, which are referenced but never pushed.
repositoryFile: A single line, <registry>/<repository>, with no scheme.
runfilesrunfiles: Everything pusher needs at run time.
tagsFile (optional): The remote tags, one per line.

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

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
chartA Helm chart's .tgz file.LabeloptionalNone
versionThe version fo the helm chartStringoptional""

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_metadata identifies the chart by purl, pkg:oci/... for a chart from an OCI registry and pkg:generic/... with the download_url and sha256 checksum otherwise. It is the default_package_metadata of the repository.
  • //:license declares the chart's license, the SPDX identifier named by the licenses or artifacthub.io/license annotation of Chart.yaml or recognized in the LICENSE file shipped with the chart. It is NOASSERTION when neither is available. The license file, if any, is kept next to the chart as the license text.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this repository.Namerequired
chart_nameChart name to import. Must be set if repository is specifiedStringoptional""
repositoryChart repository url where to locate the requested chart. Mutually exclusive with url.Stringoptional""
sha256The 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.Stringoptional""
urlThe url where a chart can be directly downloaded. Mutually exclusive with chart_name, repository, and versionStringoptional""
versionSpecify a version constraint for the chart version to use. Must be set if repository is specified.Stringoptional""

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

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
dataAdditional data to pass to helm install.List of labelsoptional[]
helm_optsAdditional arguments to pass to helm during install.List of stringsoptional[]
install_nameThe name to use for the helm install command. The target name will be used if unset.Stringoptional""
optsAdditional arguments to pass to helm install.List of stringsoptional[]
packageThe helm package to install.Labelrequired
valuesValues files to pass to helm install --values.List of labelsoptional[]

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

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
dataAdditional data to pass to helm uninstall.List of labelsoptional[]
helm_optsAdditional arguments to pass to helm during install.List of stringsoptional[]
install_nameThe name to use for the helm install command. The target name will be used if unset.Stringoptional""
optsAdditional arguments to pass to helm uninstall.List of stringsoptional[]

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

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
dataAdditional data to pass to helm upgrade.List of labelsoptional[]
helm_optsAdditional arguments to pass to helm during upgrade.List of stringsoptional[]
install_nameThe name to use for the helm upgrade command. The target name will be used if unset.Stringoptional""
optsAdditional arguments to pass to helm upgrade.List of stringsoptional[]
packageThe helm package to upgrade.Labelrequired
valuesValues files to pass to helm upgrade --values.List of labelsoptional[]

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

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
chartThe helm package to run linting on.Labelrequired
optsAdditional arguments to pass to helm lint.List of stringsoptional[]
substitutionsA dictionary of substitutions passed to `helm lint --set flag.Dictionary: String -> Stringoptional{}
valuesA list of files passed to `helm lint --values flag.List of labelsoptional[]

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

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
chartA helm_chart target providing HelmPackageInfo.Labelrequired
registry_urlThe 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.Stringoptional""
registry_url_fileA 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.LabeloptionalNone

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

NameDescription
annotationsFile: The manifest annotations, as a JSON object of strings
configFile: The raw OCI config blob (application/vnd.cncf.helm.config.v1+json)
digestFile: Text file containing the OCI manifest digest (sha256:...)
manifestFile: The raw OCI manifest bytes whose digest is in digest
repositoryFile: <registry>/<repository> that helm push pushes to, or None when no registry URL is set
tagFile: The tag helm push uses, which is the chart version with + replaced by _

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

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
depsOther helm packages this package depends on.List of labelsoptional[]
chartThe Chart.yaml file of the helm chartLabeloptionalNone
chart_jsonThe Chart.yaml file of the helm chart as a json objectStringoptional""
crdsAll Custom Resource Definitions associated with the current helm chart. E.g., the ./crds directoryList of labelsoptional[]
filesFiles accessed in templates via the .Files apiList of labelsoptional[]
imagesThe 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 labelsoptional[]
optsAdditional arguments to pass to helm package commands.List of stringsoptional[]
schemaThe values.schema.json file for the current package.LabeloptionalNone
stampWhether 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.
Integeroptional-1
substitutionsA dictionary of substitutions to apply to the values.yaml file.Dictionary: String -> Stringoptional{}
templatesAll templates associated with the current helm chart. E.g., the ./templates directoryList of labelsoptional[]
valuesThe values.yaml file for the current package.LabeloptionalNone
values_jsonThe values.yaml file for the current package as a json object.Stringoptional""

HelmPackageInfo provider

Providers

HelmPackageInfo

load("@rules_helm//helm:helm_package_info.bzl", "HelmPackageInfo")

HelmPackageInfo(chart, images, metadata)

A provider for helm packages

FIELDS

NameDescription
chartFile: The result of helm package
imageslist[HelmImageInfo]: The images bundled into the chart
metadataFile: 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

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
dataAdditional files associated with the plugin.List of labelsoptional[]
plugin_nameAn explicit name for the plugin. If unset, name will be used.Stringoptional""
yamlThe yaml file representing the pluginLabelrequired

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 --password or a file containing the --password value.

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

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
envEnvironment variables to set when running this target.Dictionary: String -> Stringoptional{}
include_imagesIf True, images depended on by package will be pushed as well.BooleanoptionalFalse
login_urlThe URL of the registry to use for helm login. E.g. my.registry.ioStringoptional""
optsAdditional arguments to pass to helm commands.List of stringsoptional[]
packageThe helm package to push to the registry.Labelrequired
push_cmdAn alternative command to push for publishing the helm chart. E.g. cm-pushStringoptional""
registry_urlThe registry URL at which to push the helm chart to. E.g. oci://my.registry.io/chart-name. Mutually exclusive with registry_url_file.Stringoptional""
registry_url_fileA file containing the registry URL at which to push the helm chart to. Mutually exclusive with registry_url.LabeloptionalNone

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

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
envEnvironment variables to set when running this target.Dictionary: String -> Stringoptional{}
packageThe helm package to upload images from.Labelrequired

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 --password or a file containing the --password value.

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

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
envEnvironment variables to set when running this target.Dictionary: String -> Stringoptional{}
include_imagesIf True, images depended on by package will be pushed as well.BooleanoptionalFalse
login_urlThe URL of the registry to use for helm login. E.g. my.registry.ioStringoptional""
optsAdditional arguments to pass to helm commands.List of stringsoptional[]
packageThe helm package to push to the registry.Labelrequired
push_cmdAn alternative command to push for publishing the helm chart. E.g. cm-pushStringoptional""
registry_urlThe registry URL at which to push the helm chart to. E.g. oci://my.registry.io/chart-name. Mutually exclusive with registry_url_file.Stringoptional""
registry_url_fileA file containing the registry URL at which to push the helm chart to. Mutually exclusive with registry_url.LabeloptionalNone

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

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
outThe output file to write the output from helm template.Label; nonconfigurableoptionalNone
chartThe helm package to resolve charts for.Labelrequired
optsAdditional arguments to pass to helm template.List of stringsoptional[]
valuesValues files to pass to helm template --values.List of labelsoptional[]

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

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
chartThe helm package to resolve templates for. Mutually exclusive with installer.Labelrequired
installerThe helm_install/helm_upgrade target to resolve templates for. Mutually exclusive with chart.LabeloptionalNone
optsAdditional arguments to pass to helm template.List of stringsoptional[]
template_patternsA mapping of template paths to regex patterns required to match.Dictionary: String -> List of stringsoptional{}
valuesValues files to pass to helm template --values.List of labelsoptional[]

helm_toolchain rule.

Rules

helm_toolchain

load("@rules_helm//helm:helm_toolchain.bzl", "helm_toolchain")

helm_toolchain(name, helm, plugins)

A helm toolchain.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
helmA helm binaryLabelrequired
pluginsAdditional plugins to make available to helm.List of labelsoptional[]

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

NameDescriptionTypeMandatoryDefault
nameThe name of the host alias repository.Nameoptional"helm"
versionThe version of helm to use for host tools.Stringoptional"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

NameDescriptionTypeMandatoryDefault
nameThe name of the plugin.Namerequired
integrityA mapping of helm platform name to integrity hash. Only platforms listed here will receive the plugin.Dictionary: String -> Stringrequired
strip_prefixA directory prefix to strip from the extracted plugin archive.Stringoptional""
url_templatesMapping 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 stringsrequired
versionThe version of the plugin to download.Stringrequired
yamlRelative path to plugin.yaml within the extracted archive (after strip_prefix).Stringoptional"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

NameDescriptionTypeMandatoryDefault
nameName prefix for the hub repository. Produces @{name}_toolchains.Namerequired
pluginsPlugin names (from helm.plugin() tags) to include in these toolchains.List of stringsoptional[]

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

NameDescriptionTypeMandatoryDefault
nameThe name of the repository.Namerequired
sha256The expected SHA-256 hash of the chart package. If unset, the extension looks it up in the registry.Stringoptional""
urlThe chart url, in the form oci://<host>/<path>:<version>.Stringrequired

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.

ModuleDepends onLoad from
rules_helm_imgrules_img@rules_helm_img//:defs.bzl
rules_helm_ocirules_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_helm itself, for oci_push, image_push and image_import targets listed directly in images. 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_img and helm_oci_image from rules_helm_oci. These read the image rules' own providers (DeployInfo and PullInfo in the case of rules_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

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
imageAn image_push or image_import target.Labelrequired

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, so push_cmd and plugins such as cm-push are not.
  • Registry credentials come from rules_img (Docker config and credential helpers), not from the HELM_REGISTRY_* variables (HELM_REGISTRY_USERNAME, HELM_REGISTRY_PASSWORD and HELM_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.

targetrule
{name}image_manifest
{name}.oci_digesthelm_oci_digest
{name}.filesconfig blob, annotations, tag, repository and layer files
{name}.layerlayer_from_file
{name}.push_specimage_push_spec

PARAMETERS

NameDescriptionDefault Value
nameThe name of the image_manifest target.none
chartA helm_chart or helm_package target. Charts from helm_import are not supported.none
registry_urlThe registry URL given to helm push, for example oci://registry.example.com/charts. Mutually exclusive with registry_url_file.None
registry_url_fileA file containing the registry URL. Mutually exclusive with registry_url.None
visibilityThe visibility of {name}. The other targets are private.None
kwargsCommon 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

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
imageAn oci_push target.Labelrequired

Kubernetes tools

kubectl_toolchain

k8s extension