Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extension to allow bazelmod style handling of dependencies #124

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions helm/extensions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load(
"//helm:defs.bzl",
"helm_import_repository",
)
load(
"//helm:repositories.bzl",
"helm_host_alias_repository",
Expand Down Expand Up @@ -47,6 +51,22 @@ def _helm_impl(ctx):
_register_toolchains(**toolchain_config)
_register_go_yaml()

# Separate iteration, because this can depend on the _register_toolchains called above.
# And the _register_toolchains needs to be called *after* iteration of all modules.
for module in ctx.modules:
for repository in module.tags.import_repository:
if not module.is_root:
print("Ignoring import_repository of", repository.name, "from", repository.repository, "because it's not in the root module") # buildifier: disable=print
continue
helm_import_repository(
name = repository.name,
chart_name = repository.chart_name,
repository = repository.repository,
sha256 = repository.sha256,
url = repository.url,
version = repository.version,
)

def _register_toolchains(version, helm_url_templates, plugins):
if not version in HELM_VERSIONS:
fail("{} is not a supported version ({})".format(version, HELM_VERSIONS.keys()))
Expand Down Expand Up @@ -132,10 +152,33 @@ _toolchain = tag_class(
},
)

_import_repository = tag_class(attrs = {
"name": attr.string(
doc = "Name for the import dependency",
),
"chart_name": attr.string(
doc = "Chart name to import.",
),
"repository": attr.string(
doc = "Chart repository url where to locate the requested chart.",
mandatory = True,
),
"sha256": attr.string(
doc = "The expected SHA-256 hash of the chart imported.",
),
"url": attr.string(
doc = "The url where the chart can be directly downloaded.",
),
"version": attr.string(
doc = "Specify a version constraint for the chart version to use.",
),
})

helm = module_extension(
implementation = _helm_impl,
tag_classes = {
"options": _toolchain, # deprecated: use toolchain instead and remove in next major version
"toolchain": _toolchain,
"import_repository": _import_repository,
},
)