【发布时间】:2022-11-23 03:34:38
【问题描述】:
我有一个包含多种语言和工件的 monorepo,我想过渡到 Bazel。 我们想使用我们现有的 Dockerfiles 构建 docker 镜像,使用 genrule - 避免将所有 dockerfiles 转换为 docker-rules(至少在这一点上)。
我们知道这不是 Bazel 的最佳实践,但我们认为它可以让我们轻松过渡。
我正在测试这个 Dockerfile
FROM alpine:3.8
ENTRYPOINT ["echo"]
CMD ["Hello Bazel!"]
我尝试关注this post,但在运行 docker build 命令时(甚至在 Bazel 之外)我得到了这个 -
> tar -czh . | docker build -t hello-bazel -
[+] Building 0.1s (2/2) FINISHED
=> [internal] load remote build context 0.0s
=> ERROR copy /context / 0.1s
------
> copy /context /:
------
failed to solve with frontend dockerfile.v0: failed to read dockerfile: Error processing tar file(gzip: invalid header):
我尝试将 genrule 与基本的 docker build 命令一起使用 -
genrule(
name = "gc-hello-bazel",
srcs = ["Dockerfile"],
outs = ["imagesha.txt"],
cmd = "docker build -t hello-bazel -f $(location Dockerfile) . > $@",
tools = ["Dockerfile"],
)
但是构建失败了
failed to solve with frontend dockerfile.v0: failed to read dockerfile: open Dockerfile: no such file or directory
如果重要的话,这是我的目录结构:
-WORKSPACE
-<some-root-dirctories>
-<a-root-directory>
-<subdir>
-<subsubdir1>
-my_docker
-Dockerfile
-BUILD.bazel
我究竟做错了什么?
TL;DR:我正在寻找一个使用 Dockerfile 和 Bazel 的 Genrule 构建 docker 的工作示例
【问题讨论】:
标签: build dockerfile bazel bazel-rules bazel-genrule