masmovil / masorange_rules_helm

Bazel rules to manipulate and operate Helm charts with Bazel, decrpyt sops secrets, and run operations over cloud services
Apache License 2.0
61 stars 32 forks source link

feat: rules rewrite to version v1 #70

Closed danigar closed 1 week ago

danigar commented 11 months ago

Major rewrite and refactor of the rules. Add bzlmod and rules_oci support.

Add new features to existent rules and implement new ones:

Fix several issues:

Adds Bzlmod support rules_oci support (rules_docker are still supported) Rewrite all the docs using stardoc Improve CI and release process Publish the rules to the bazel central registry

All the changes should be retrocompatible and the APIS remains the same. Some rule attributes have been marked as deprecated but are still supported.

borg286 commented 10 months ago

I'm trying to build your awesome branch, but in both the feat/bzlmod and this v1 branch I'm hitting this error. Please paste in the build command you're using, preferably with the version of bazel. I'd like to help.

mrmath@mrmath ~/helm/bazel-helm-rules % git branch

borg286 commented 10 months ago

For the helm_uninstall, can we ensure that we use the helm flag that makes it acceptable if the target doesn't exist? I'd like to invoke the rule as part of a CICD pipeline that runs periodically and a non-zero exit code would count as a failure. I'd like code to act as my intent, and invoking the helm_uninstall rule should have a 0 exit code when the chart no longer is running.

borg286 commented 10 months ago

I think the workspace requires a running helm museum, prepopulated with this helm_chart_a. I suspect I need to push the chart into this museum so that when I build from a clean bazel, that this chart gets downloaded so it is available to be used elsewhere in the build pipeline. Sadly I don't know how to pre-populate it.

This is how I think I'm supposed to run the museum.

docker run --rm -it \ -p 8080:8080 \ -e DEBUG=1 \ -e STORAGE=local \ -e STORAGE_LOCAL_ROOTDIR=/charts \ -v $(pwd)/charts:/charts -d \ ghcr.io/helm/chartmuseum:v0.16.1

But I'd love to know how to pre-populate it. I'd also love to see your .bazelrc file so I can make sure I'm replicating your build steps.

borg286 commented 10 months ago

Thanks for uploading that repositories.bzl file. Re-pulling from your branch fixes that issue, and the handful of hacks before I again hit the above snag where I think I need to be running the helm museum. Thank you for being so responsive. I suspect it is as simple as copying out some small helm chart, packaging it up manually with helm, then using helm to push it to my local museum running in docker. Sadly I don't know what specific commands to run to get bootstrapped

danigar commented 10 months ago

Hi @borg286. So glad you are testing the rules that early. Note that this is still a working on PR so probably you will face some issues. You are right, repositories.bzl was missing from the vcs. I've already uploaded. Thanks for the feedback. I haven't tried the rules yet without bzlmod. About testing, I have to work more on helm push/pull tests, so I recommend you running only helm chart tests. There are also some tests than need stamping, so this is how I run them bazel test //helm/tests/helm_chart:all --workspace_status_command=path-to-the-repo/stamp.sh --stamp. In my .bazelrc.user i just turn bazlmod on common --enable_bzlmod.

borg286 commented 10 months ago

I suspect you are not encountering the following issue. I assume that, based on the code, it would have downloaded the right version of helm. I have it installed

% helm version version.BuildInfo{Version:"v3.13.1", GitCommit:"3547a4b5bf5edb5478ce352e18858d8a552a4110", GitTreeState:"clean", GoVersion:"go1.20.8"}

But even if I didn't have it installed, it seems like it should simply download it. Do you have any advice?

% bazel test //helm/tests/helm_chart:all --workspace_status_command=~/helm/bazel-helm-rules/stamp.sh --stamp --toolchain_resolution_debug='//toolchains/helm:toolchain_type' ERROR: /home/mrmath/.cache/bazel/_bazel_mrmath/89a0ba2d7022a7a191918961ecdb81d0/external/helm_toolchains/BUILD.bazel:6:19: While resolving toolchains for target @helm_toolchains//:resolved_toolchain: No matching toolchains found for types //toolchains/helm:toolchain_type. To debug, rerun with --toolchain_resolution_debug='//toolchains/helm:toolchain_type' If platforms or toolchains are a new concept for you, we'd encourage reading https://bazel.build/concepts/platforms-intro. ERROR: Analysis of target '//helm/tests/helm_chart:chart_a_image_dep_lint' failed; build aborted:

danigar commented 10 months ago

Hi @borg286. I'm doing some refactor to how toolchains are implemented, because there are some redundant code and definitions. I've already fixed helm toolchain. Maybe this will solve your problem..

borg286 commented 10 months ago

I posit that perhaps I'm getting the error above because this line is refering to a repository that hasn't finished being built yet toolchain_type = "@masmovil_bazel_rules//toolchains/helm:toolchain_type",

I know the docs say that this build rule can be defined anywere, but I wonder if we're hitting a snag because we're pointing to a build target that needs to be compiled first. ie. we've got a cycle. I don't know if this helps, but that is my theory.