bazel:检测到工作区文件中的循环。这表明在定义之前使用了存储库

问题描述 投票:0回答:0

我有以下文件并尝试使用 bazel 6.1.1 编译简单的 python 应用程序并出现错误。

我的档案:

➜ tree                              
.
├── BUILD
├── main.py
└── WORKSPACE

错误

➜ bazel build //...
WARNING: Ignoring JAVA_HOME, because it must point to a JDK, not a JRE.
ERROR: Failed to load Starlark extension '@io_bazel_rules_docker//repositories:repositories.bzl'.
Cycle in the workspace file detected. This indicates that a repository is used prior to being defined.
The following chain of repository dependencies lead to the missing definition.
 - @io_bazel_rules_docker
This could either mean you have to add the '@io_bazel_rules_docker' repository with a statement like `http_archive` in your WORKSPACE file (note that transitive dependencies are not added automatically), or move an existing definition earlier in your WORKSPACE file.
ERROR: Error computing the main repository mapping: cycles detected during computation of main repo mapping
Loading: 

建造

load("@io_bazel_rules_docker//python3:image.bzl", "py3_image")

py3_image(
    name = "main",
    main = "main.py",
    srcs = ["main.py"],
    base =  "@python_container//image",
    deps = [],
)

工作空间

load(
    "@io_bazel_rules_docker//repositories:repositories.bzl",
    container_repositories = "repositories",
)

container_repositories()

load(
    "@io_bazel_rules_docker//python:image.bzl",
    _py_image_repos = "repositories",
)

_py_image_repos()

load("@io_bazel_rules_docker//container:container.bzl", "container_pull")
load("@io_bazel_rules_docker//container:container.bzl", "container_layer", "container_image")

container_layer(
    name = "python_symlink",
    symlinks = {
      "/usr/bin/python": "/usr/local/bin/python",
      "/usr/bin/python3": "/usr/local/bin/python",
    },
)

container_image(
    name = "python",
    base = "@python_container//image",
    layers = [":python_symlink"],
    visibility = ["//visibility:public"],
)

container_pull(
    name = "python_container",
    registry = "docker.io/library",
    repository = "python",
    tag = "3.9-slim",
)

main.py

print("Hello world!")
python bazel bazel-rules
© www.soinside.com 2019 - 2024. All rights reserved.