繁体   English   中英

使用 Bazel 将 Go 测试二进制文件添加到 container_image

[英]Add Go Test binary to container_image using Bazel

我正在构建一个 go 测试 package,我想将其包含在 Docker 图像中。 可以使用bazel build //testing/e2e:e2e_test二进制文件。 这会在 bazel_bin 文件夹中创建一个二进制文件。 现在我想把这个二进制文件添加到 docker 图像中......

container_image(
    name = "image",
    base = "@alpine_linux_amd64//image",
    entrypoint = ["/e2e_test"],
    files = [":e2e_test"],
)

这给了我以下错误

ERROR: ...BUILD.bazel:27:16: in container_image_ rule //testing/e2e:image: non-test target '//testing/e2e:image' depends on testonly target '//testing/e2e:e2e_test' and doesn't have testonly attribute set
ERROR: Analysis of target '//testing/e2e:image' failed; build aborted: Analysis of target '//testing/e2e:image' failed

最终,我想要完成的是使用 Go 测试框架创建一个包含一套端到端测试的应用程序。 然后我可以在 docker 容器中分发这些测试,以便在测试环境中运行。

错误是说非 testonly 目标取决于 testonly 目标,testonly 的文档说不允许:

如果为 True,则只有 testonly 目标(例如测试)可以依赖此目标。

等效地,不允许不是testonly的规则依赖于任何testonly规则。

您可以通过使您的目标testonly像这样来做您正在寻找的事情:

container_image(
    name = "image",
    testonly = True,
    base = "@alpine_linux_amd64//image",
    entrypoint = ["/e2e_test"],
    files = [":e2e_test"],
)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM