Rules_docker: container_run_and_commit says: Unable to extract manifest.json

Created on 18 Nov 2019  路  5Comments  路  Source: bazelbuild/rules_docker

Hi contributors to rules_docker! Thanks tons for your contributions

Running bazel build //tests:openjdk8-image works.

This is my BUILD file:

load("@io_bazel_rules_docker//container:image.bzl", "container_image")
load("@io_bazel_rules_docker//docker/util:run.bzl", "container_run_and_commit")

container_image(
  name = "openjdk8-image",
  base = "@openjdk8//image",
  tags = ["local"],
)

container_run_and_commit(
  name = "new-image",
  commands = [
    "touch a",
  ]
)

But running bazel build //tests:new-image gets me:

(venv3.5) root@vagrant:~/tgkj# bazel build //tests:new-image -s
INFO: Writing tracer profile to '/home/vagrant/.cache/bazel/_bazel_root/6350b857406c0b635c0d7384284d6069/command.profile.gz'
INFO: Analyzed target //tests:new-image (59 packages loaded, 6640 targets configured).
INFO: Found 1 target...
SUBCOMMAND: # //tests:openjdk8-image [action 'ImageLayer tests/openjdk8-image-layer.tar', configuration: 9a088452797200c5bf92e0469646fb64]
(cd /home/vagrant/.cache/bazel/_bazel_root/6350b857406c0b635c0d7384284d6069/execroot/my_wksp && \
  exec env - \
    PATH=/home/vagrant/tgkj/venv3.5/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin \
  bazel-out/host/bin/external/io_bazel_rules_docker/container/build_tar '--output=bazel-out/k8-fastbuild/bin/tests/openjdk8-image-layer.tar' '--directory=/' '--mode=0o555' '--xz_path=/usr/bin/xz' '--manifest=bazel-out/k8-fastbuild/bin/tests/openjdk8-image-layer.manifest')
SUBCOMMAND: # //tests:new-image [action 'Action tests/new-image_commit.tar', configuration: 9a088452797200c5bf92e0469646fb64]
(cd /home/vagrant/.cache/bazel/_bazel_root/6350b857406c0b635c0d7384284d6069/execroot/my_wksp && \
  exec env - \
    PATH=/home/vagrant/tgkj/venv3.5/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin \
  bazel-out/k8-fastbuild/bin/tests/new-image.build)
ERROR: /home/vagrant/tgkj/tests/BUILD:16:1: Action tests/new-image_commit.tar failed (Exit 1) new-image.build failed: error executing command bazel-out/k8-fastbuild/bin/tests/new-image.build

Use --sandbox_debug to see verbose messages from the sandbox
+ TO_JSON_TOOL=bazel-out/host/bin/external/io_bazel_rules_docker/docker/util/to_json
+ source external/io_bazel_rules_docker/docker/util/image_util.sh
+ DOCKER=/usr/bin/docker
+ [[ -z /usr/bin/docker ]]
++ bazel-out/host/bin/external/io_bazel_rules_docker/contrib/extract_image_id bazel-out/k8-fastbuild/bin/tests/openjdk8-image-layer.tar
Unable to extract manifest.json, make sure bazel-out/k8-fastbuild/bin/tests/openjdk8-image-layer.tar is a valid docker image.
 "filename 'manifest.json' not found"
----------------
Note: The failure of target @io_bazel_rules_docker//contrib:extract_image_id (with exit code 1) may have been caused by the fact that it is a Python 2 program that was built in the host configuration, which uses Python 3. You can change the host configuration (for the entire build) to instead use Python 2 by setting --host_force_python=PY2.

If this error started occurring in Bazel 0.27 and later, it may be because the Python toolchain now enforces that targets analyzed as PY2 and PY3 run under a Python 2 and Python 3 interpreter, respectively. See https://github.com/bazelbuild/bazel/issues/7899 for more information.
----------------
+ image_id=
Target //tests:new-image failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 17.222s, Critical Path: 1.21s
INFO: 1 process: 1 processwrapper-sandbox.
FAILED: Build did NOT complete successfully
(venv3.5) root@vagrant:~/tgkj#

I don't know how to troubleshoot the issue!

Most helpful comment

This works for me if I do:

container_run_and_commit(
  image = "@openjdk8//image:image.tar",
  name = "new-image",
  commands = [
    "touch a",
  ]
)

Closing, but please let me know if you want me to reopen for some reason.

All 5 comments

Well, openjdk8-image-layer.tar is an empty tar file:

(venv3.5) root@vagrant:~/tgkj# ls -la bazel-out/k8-fastbuild/bin/tests/openjdk8-image-layer.tar
-r-xr-xr-x 1 root root 10240 Nov 12 08:40 bazel-out/k8-fastbuild/bin/tests/openjdk8-image-layer.tar

10240 bytes is an empty tar file: https://superuser.com/questions/448623/how-to-get-an-empty-tar-archive

Even the output of the bazel build //tests:openjdk8-image is an empty tar file:

(venv3.5) root@vagrant:~/tgkj# bazel build //tests:openjdk8-image
INFO: Writing tracer profile to '/home/vagrant/.cache/bazel/_bazel_root/6350b857406c0b635c0d7384284d6069/command.profile.gz'
INFO: Analyzed target //tests:openjdk8-image (18 packages loaded, 102 targets configured).
INFO: Found 1 target...
Target //tests:openjdk8-image up-to-date:
  bazel-bin/tests/openjdk8-image-layer.tar
INFO: Elapsed time: 4.732s, Critical Path: 0.02s
INFO: 0 processes.
INFO: Build completed successfully, 1 total action
(venv3.5) root@vagrant:~/tgkj# ls -la bazel-bin/tests/openjdk8-image-layer.tar
-r-xr-xr-x 1 root root 10240 Nov 12 08:40 bazel-bin/tests/openjdk8-image-layer.tar
container_pull(
    name = "openjdk8",
    registry = "index.docker.io",
    repository = "openjdk",
    tag = "8",
)

Why should this generate an empty tar file?

I experienced a similar error when using container_run_and_commit with :intermediate_image instead of :intermediate_image.tar

This works for me if I do:

container_run_and_commit(
  image = "@openjdk8//image:image.tar",
  name = "new-image",
  commands = [
    "touch a",
  ]
)

Closing, but please let me know if you want me to reopen for some reason.

Was this page helpful?
0 / 5 - 0 ratings