0

I would like to push a Docker image to a registry with as tag the SHA-256 digest of the image. I am using Bazel and more specifically container_push from docker_rules. Unfortunately, I am unable to retrieve the image's digest and tag the image with it.

Assuming I have the following BUILD.bazel config, how can I do this?

go_image(
    name = "image",
    embed = [":app1_lib"],
    goarch = "amd64",
    goos = "linux",
)

container_push(
    name = "publish",
    format = "Docker",
    image = ":image",
    registry = DOCKER_REGISTRY,
    repository = "app1",
    skip_unchanged_digest = True,
    tag = "{ ??? }",
)
Vertexwahn
  • 7,709
  • 6
  • 64
  • 90
nickdecooman
  • 153
  • 11

1 Answers1

3

I noticed the basel-out folder contained for my target a file called image.json.sha256. Using this in the tag_file property from container_push produces the expected tag.

go_image(
    name = "image",
    embed = [":app1_lib"],
    goarch = "amd64",
    goos = "linux",
)

container_push(
    name = "publish",
    format = "Docker",
    image = ":image",
    registry = DOCKER_REGISTRY,
    repository = "app1",
    skip_unchanged_digest = True,
    tag_file = "image.json.sha256",
)
nickdecooman
  • 153
  • 11