0

I'm using container_pull in my WORKSPACE file. (It's part of bazel docker rules)
Here is what it looks like:

container_pull(
    name = "base-image",
    registry = "registry:9999",
    repository = "base-image",
    digest = "sha256:e6f44554a270025c578c0f91160d809735c2589baae80bafcdeebefb0c0b04b6",
    tag = "1.1.0"
)

Howeve, there is a file containing the version of base-image, and I want it to be read from that file, instead of hardcoding in WORKSPACE.
How can I read a file content in WORKSPACE?

Emran
  • 544
  • 7
  • 26

1 Answers1

0

There's no direct way to read a file from the workspace file. The container_pull rule would have to add support for reading from a file.

A workaround is to put the file that contains the information into .bzl format, and load that from the workspace file.

Something like this:

versions.bzl:

BASE_IMAGE_VERSION = "1.1.0"

WORKSPACE:

load("//:versions.bzl", "BASE_IMAGE_VERSION")

container_pull(
    name = "base-image",
    registry = "registry:9999",
    repository = "base-image",
    digest = "sha256:e6f44554a270025c578c0f91160d809735c2589baae80bafcdeebefb0c0b04b6",
    tag = BASE_IMAGE_VERSION,
)

Bazel does a similar thing in its own workspace file: https://github.com/bazelbuild/bazel/blob/669a1a2634bdf267f890cf88833c9712d4e75016/WORKSPACE#L589

ahumesky
  • 4,203
  • 8
  • 12