Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Stamp substitution in image names does not work as expected #727

Description

@chrismgrayftsinc

I have a macro that I am converting from using --define variable substitution to bazel stamps. Here is a snippet:

    docker_push(
        name = "push-" + project_name,
        image = ":" + project_name + "-image",
        registry = "index.docker.io",
        repository = repository,
        tag = "{STABLE_VERSION}",
        stamp = "@io_bazel_rules_docker//stamp:always",
    )

    k8s_object(
        name = "test-k8s",
        cluster = "staging.k8s.local",
        images = {
            repository + ":{STABLE_VERSION}": "//:" + project_name + "-image",
        },
        template = k8s_template,
    )

We also use jsonnet and bazel stamps to generate the k8s_template:

jsonnet_to_json(
    name = "deployment-staging-json",
    src = "deployment-staging.jsonnet",
    outs = ["deployment-staging.json"],
    ext_strs = {"VERSION": "{STABLE_VERSION}"},
    stamp_keys = ["VERSION"],
    visibility = ["//:__subpackages__"],
    yaml_stream = True,
    deps = [
        ":deployment",
    ],
)

so the template is generated with the stamp key substituted in. My intuition was that the {STABLE_VERSION} tag would be stamp-substituted but it is not. When I run bazel run --workspace_status_command="echo STABLE_VERSION test" :test-k8s.replace, I get the error

2023/05/02 16:18:21 The following images given as --image_spec were not found in the template:
2023/05/02 16:18:21 <repo>/<service>:{STABLE_VERSION}
2023/05/02 16:18:21 --allow_unused_images can be specified to ignore this error.

It is interesting to note that the image is uploaded to Docker Hub with the expected test tag, so there is some substitution done on the image tag, just not when looking in the k8s template I guess.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions