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}")

Run as a tool

bazel run @helm//:helm -- ...

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"],
)

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.[]
imagesA list of oci_push or image_push targets[]
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_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.

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.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.

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.

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)

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 .tgz file's mtime is used for the creation annotation, formatted in UTC to match the push side.

The digest file contains a single line: sha256:<hex>.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
chartA helm_chart target providing HelmPackageInfo.Labelrequired

HelmOCIDigestInfo

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

HelmOCIDigestInfo(digest)

OCI manifest digest for a Helm chart, computed at build time.

FIELDS

NameDescription
digestFile: Text file containing the OCI manifest digest (sha256:...)

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[]
imagesA list of oci_push or image_push targets.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[Target]: A list of @rules_oci//oci:defs.bzl%oci_push or @rules_img//img:push.bzl%image_push targets
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.

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.

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.

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[]