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

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

Open
chrismgrayftsinc opened this issue May 2, 2023 · 1 comment
Open

Comments

@chrismgrayftsinc
Copy link

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.

@chrismgrayftsinc
Copy link
Author

I do see the example custom resolver in the examples directory. Perhaps that would be the way to go.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant