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

Error replacing image stamps: Failed to find key #96

Open
amsokol opened this issue Sep 23, 2024 · 3 comments
Open

Error replacing image stamps: Failed to find key #96

amsokol opened this issue Sep 23, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@amsokol
Copy link

amsokol commented Sep 23, 2024

Hello,

First thanks author very much for the great tool!

I faced with the bug, I think.

My environment is:
Ubuntu Linux 24.04.1 (arm64)
Bazel 7.3.1
rules_helm 0.5.1
rules_oci 2.0.0

My code is the following:

def helm_package(
        name,
        package,
        values,
        images = {},
        api_version = "v2",
        type = "application",
        app_version = "1.0.0",
        version = "0.1.0",
        description = "A Helm chart",
        templates = [],
        substitutions = []):

    # Normalize the rule name by replacing hyphens and dots with underscores.
    rule_name = name.replace("-", "_").replace(".", "_")

    # Iterate over the images dictionary and push each image to the OCI registry.
    for image in images:
        tag = images[image]
        oci_push(
            name = "%s.push" % image,  # Name of the OCI push target.
            image = "%s" % image,  # Image name.
            remote_tags = [tag],  # Tags to apply to the pushed image.
            repository = "%s/%s/%s" % (REGISTRY_PUSH_URI, package, to_registy_image_name(image)),  # Repository URI.
        )

    # Create a Helm chart file with the specified parameters.
    chart_file(
        name = "%s.chart_file" % rule_name,  # Name of the chart file target.
        api_version = api_version,  # API version of the Helm chart.
        app_version = app_version,  # Application version of the Helm chart.
        chart_name = "%s-chart" % name,  # Name of the Helm chart.
        description = description,  # Description of the Helm chart.
        type = type,  # Type of the Helm chart.
        version = version,  # Version of the Helm chart.
    )

    # Define the Helm chart target.
    helm_chart(
        name = "%s" % rule_name,  # Name of the Helm chart target.
        chart = ":%s.chart_file" % rule_name,  # Reference to the chart file target.
        substitutions = substitutions,  # Substitutions to apply to the Helm chart.
        templates = templates,  # Template files for the Helm chart.
        values = values,  # Values file for the Helm chart.
        images = [
            ":%s.push" % image
            for image in images
        ],
    )

I get the error when I build:

Error replacing image stamps: Failed to find key @@//<oci_push rule created using "for/in"> in content

Thanks in advance for any help.

@abrisco abrisco added the bug Something isn't working label Sep 23, 2024
@abrisco
Copy link
Owner

abrisco commented Sep 23, 2024

I wonder if this is caused by newer versions of rules_oci. What version are you using?

@amsokol
Copy link
Author

amsokol commented Sep 24, 2024

@abrisco thanks for your reply.

Yes, I'm using the newest (v2.0.0) rules_oci.

@abrisco
Copy link
Owner

abrisco commented Sep 25, 2024

@abrisco thanks for your reply.

Yes, I'm using the newest (v2.0.0) rules_oci.

Ah sorry, you'd mentioned the version in your original post 😅

It looks like the rules require images to be replaced within templates and if one is provided that's not replaced an error occurs
https://github.com/abrisco/rules_helm/blame/282d4ec40f8ce83f0f43c73c34bfc7b2b973746c/helm/private/packager/packager.go#L307-L319

In a way that seems reasonable to help devs avoid unnecessary dependencies but if that's really the intent here then the messaging is pretty lacking. I'd be happy to review a PR to improve the UX here if that's indeed the issue 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants