What Do I Do If "An error occurred during the fetch of repository 'io_bazel_rules_docker'" Is Displayed When Bazel Is Used?

Symptom

The message "ERROR: An error occurred during the fetch of repository 'io_bazel_rules_docker'" is displayed when you run the command bazel build --config=monolithic //tensorflow/compiler/aot:xlacompilebazel build for compilation. After making sure your server is working normally over the Internet and perform compilation again, you still get the following message displayed.

ERROR: An error occurred during the fetch of repository 'io_bazel_rules_docker':
   java.io.IOException: Error downloading [https://github.com/bazelbuild/rules_docker/releases/download/v0.14.3/rules_docker-v0.14.3.tar.gz] to /home/test/.cache/bazel/_bazel_test/abd37aaac8a380ca5a3f13938322fcb2/external/io_bazel_rules_docker/rules_docker-v0.14.3.tar.gz: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
ERROR: no such package '@io_bazel_rules_docker//repositories': java.io.IOException: Error downloading [https://github.com/bazelbuild/rules_docker/releases/download/v0.14.3/rules_docker-v0.14.3.tar.gz] to /home/test/.cache/bazel/_bazel_test/abd37aaac8a380ca5a3f13938322fcb2/external/io_bazel_rules_docker/rules_docker-v0.14.3.tar.gz: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
INFO: Elapsed time: 24.586s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded)

Solution

If you cannot download the packages in normal Internet connection, fix the error as follows:

  1. Download these packages from the following URLs to the local PC and upload them to any directory on the Linux server, for example, $HOME/bazel_tools.
    https://github.com/bazelbuild/rules_docker/releases/download/v0.14.3/rules_docker-v0.14.3.tar.gz
    https://github.com/bazelbuild/bazel-skylib/releases/download/0.8.0/bazel-skylib.0.8.0.tar.gz
    https://github.com/bazelbuild/rules_swift/releases/download/0.11.1/rules_swift.0.11.1.tar.gz
    https://github.com/llvm-mirror/llvm/archive/7a7e03f906aada0cf4b749b51213fe5784eeff84.tar.gz
    The following lists the absolute paths of the above files on the Linux server.
    /home/test/bazel_tools/rules_docker-v0.14.3.tar.gz
    /home/test/bazel_tools/bazel-skylib.0.8.0.tar.gz
    /home/test/bazel_tools/rules_swift.0.11.1.tar.gz
    /home/test/bazel_tools/llvm-7a7e03f906aada0cf4b749b51213fe5784eeff84.tar.gz
  2. Modify the download URLs in the Bazel-related files.
    1. Switch to the tensorflow-1.15.0 directory, run the vi WORKSPACE command to open the WORKSPACE file, and change each download URL to its corresponding absolute path on the Linux server.
      bazel_toolchains_repositories()
      http_archive(
          name = "io_bazel_rules_docker",
          sha256 = "6287241e033d247e9da5ff705dd6ef526bac39ae82f3d17de1b69f8cb313f9cd",
          strip_prefix = "rules_docker-0.14.3",
          urls = ["file:///home/test/bazel_tools/rules_docker-v0.14.3.tar.gz"],
      )
      
      load(
          "@io_bazel_rules_docker//repositories:repositories.bzl",
          container_repositories = "repositories",
      )
      container_repositories()
      
      load("//third_party/toolchains/preconfig/generate:workspace.bzl",
           "remote_config_workspace")
      remote_config_workspace()
      
      # Apple and Swift rules.
      http_archive(
          name = "build_bazel_rules_apple",
          sha256 = "6efdde60c91724a2be7f89b0c0a64f01138a45e63ba5add2dca2645d981d23a1",
          urls = ["https://github.com/bazelbuild/rules_apple/releases/download/0.17.2/rules_apple.0.17.2.tar.gz"],
      )  # https://github.com/bazelbuild/rules_apple/releases
      http_archive(
          name = "build_bazel_rules_swift",
          sha256 = "96a86afcbdab215f8363e65a10cf023b752e90b23abf02272c4fc668fcb70311",
          urls = ["file:///home/test/bazel_tools/rules_swift.0.11.1.tar.gz"],
      )  # https://github.com/bazelbuild/rules_swift/releases

      Run the wq! command to save the modification and exit.

    2. Modify the llvm URL to its absolute path on the Linux server in the workspace.bzl file in the tensorflow-1.15.0/tensorflow directory.
          # TODO(phawkins): currently, this rule uses an unofficial LLVM mirror.
          # Switch to an official source of snapshots if/when possible.
          tf_http_archive(
              name = "llvm",
              build_file = clean_dep("//third_party/llvm:llvm.autogenerated.BUILD"),
              sha256 = "599b89411df88b9e2be40b019e7ab0f7c9c10dd5ab1c948cd22e678cc8f8f352",
              strip_prefix = "llvm-7a7e03f906aada0cf4b749b51213fe5784eeff84",
              urls = [
                  "https://mirror.bazel.build/github.com/llvm-mirror/llvm/archive/7a7e03f906aada0cf4b749b51213fe5784eeff84.tar.gz",
                  "file:///home/test/bazel_tools/llvm-7a7e03f906aada0cf4b749b51213fe5784eeff84.tar.gz",
              ],
          )
    3. After modification, switch to the tensorflow-1.15.0 directory and compile the xlacompile tool with the following command.
      bazel build --config=monolithic //tensorflow/compiler/aot:xlacompile

      If you see the message "ERROR: An error occurred during the fetch of repository 'bazel_skylib':", take the next step to edit files related to bazel_skylib.

    4. Modify the related URL in the .cache directory.

      Switch to the $HOME directory and run the grep -r bazel-skylib.0.8.0 .cache/ command to check which file in the .cache directory references the URL of bazel-skylib.0.8.0.tar.gz. Then, go to the directory of the file, for example, .cache/bazel/_bazel_test/abd37aaac8a380ca5a3f13938322fcb2/external/io_bazel_rules_closure/closure/repositories.bzl.

      Open the file and change the URL to the following absolute path.

      file:///home/test/bazel_tools/bazel-skylib.0.8.0.tar.gz

      Run the wq! command to save the modification and exit.