rules_helm

Bazel rules for producing helm charts

Setup WORKSPACE

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# See releases for urls and checksums
http_archive(
    name = "rules_helm",
    sha256 = "{sha256}",
    urls = ["https://github.com/abrisco/rules_helm/releases/download/{version}/rules_helm-v{version}.tar.gz"],
)

load("@rules_helm//helm:repositories.bzl", "helm_register_toolchains", "rules_helm_dependencies")

rules_helm_dependencies()

helm_register_toolchains()

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

rules_helm_transitive_dependencies()

Setup MODULE

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

Bazel rules for Helm.

Rules

Providers

Functions

Aspects

Repository Rules

chart_file

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

chart_file(name, api_version, app_version, chart_name, description, type, version)

Create a Helm chart file.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
api_versionThe Helm API versionStringoptional"v2"
app_versionThe version number of the application being deployed.Stringoptional"1.16.0"
chart_nameThe name of the chartStringoptional""
descriptionA descritpion of the chart.Stringoptional"A Helm chart for Kubernetes by Bazel."
typeThe chart type.Stringoptional"application"
versionThe chart version.Stringoptional"0.1.0"

helm_import

load("@rules_helm//helm:defs.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_install

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

helm_install(name, data, helm_opts, install_name, opts, package)

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

helm_lint_test

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

helm_lint_test(name, chart)

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

helm_package

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

helm_package(name, deps, chart, chart_json, crds, files, images, 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 targets.List of labelsoptional[]
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""

helm_plugin

load("@rules_helm//helm:defs.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

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

helm_push(name, env, include_images, login_url, package, registry_url)

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""
packageThe helm package to push to the registry.Labelrequired
registry_urlThe registry URL at which to push the helm chart to. E.g. oci://my.registry.io/chart-nameStringrequired

helm_push_images

load("@rules_helm//helm:defs.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:defs.bzl", "helm_push_registry")

helm_push_registry(name, env, include_images, login_url, package, registry_url)

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""
packageThe helm package to push to the registry.Labelrequired
registry_urlThe registry URL at which to push the helm chart to. E.g. oci://my.registry.io/chart-nameStringrequired

helm_template_test

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

helm_template_test(name, chart, installer, template_patterns)

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
template_patternsA mapping of template paths to regex patterns required to match.Dictionary: String -> List of stringsoptional{}

helm_toolchain

load("@rules_helm//helm:defs.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[]

helm_uninstall

load("@rules_helm//helm:defs.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:defs.bzl", "helm_upgrade")

helm_upgrade(name, data, helm_opts, install_name, opts, package)

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

HelmPackageInfo

load("@rules_helm//helm:defs.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 targets
metadataFile: A json encoded file containing metadata about the helm chart

chart_content

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

chart_content(name, api_version, description, type, version, app_version)

A convenience wrapper for defining Chart.yaml files with helm_package.chart_json.

PARAMETERS

NameDescriptionDefault Value
nameThe name of the chartnone
api_versionThe Helm API version"v2"
descriptionA descritpion of the chart."A Helm chart for Kubernetes by Bazel."
typeThe chart type."application"
versionThe chart version."0.1.0"
app_versionThe version number of the application being deployed."1.16.0"

RETURNS

str: A json encoded string which represents Chart.yaml contents.

helm_chart

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

helm_chart(*, name, chart, chart_json, crds, values, values_json, substitutions, templates, files,
           images, deps, install_name, registry_url, login_url, helm_opts, install_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}.push_registryhelm_push (include_images = False)registry_url is defined.
{name}.pushhelm_push (include_images = True)registry_url 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
filesFiles accessed in templates via the .Files api.[]
imagesA list of oci_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.None
login_urlThe registry url to log into for publishing helm charts.None
helm_optsAdditional options to pass to helm.[]
install_optsAdditional options to pass to helm install.[]
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_register_toolchains

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

helm_register_toolchains(version, helm_url_templates, plugins)

Register helm toolchains.

PARAMETERS

NameDescriptionDefault Value
versionThe version of Helm to use"3.17.0"
helm_url_templatesA list of url templates where helm can be downloaded.["https://get.helm.sh/helm-v{version}-{platform}.{compression}"]
pluginsLabels to helm_plugin targets to add to generated toolchains.[]

rules_helm_dependencies

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

rules_helm_dependencies()

Defines helm dependencies

helm_lint_aspect

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

helm_lint_aspect()

An aspect for running helm lint on helm package targets

ASPECT ATTRIBUTES

ATTRIBUTES

helm_import_repository

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

helm_import_repository(name, chart_name, repo_mapping, repository, sha256, url, version)

A rule for fetching external Helm charts from an arbitrary repository.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this repository.Namerequired
chart_nameChart name to import.Stringoptional""
repo_mappingIn WORKSPACE context only: a dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.

For example, an entry "@foo": "@bar" declares that, for any time this repository depends on @foo (such as a dependency on @foo//some:target, it should actually resolve that dependency within globally-declared @bar (@bar//some:target).

This attribute is not supported in MODULE.bazel context (when invoking a repository rule inside a module extension's implementation function).
Dictionary: String -> Stringoptional
repositoryChart repository url where to locate the requested chart.Stringrequired
sha256The expected SHA-256 hash of the chart imported.Stringoptional""
urlThe url where the chart can be directly downloaded.Stringoptional""
versionSpecify a version constraint for the chart version to use.Stringoptional""