bazelbuild / rules_docker

Rules for building and handling Docker images with Bazel

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

container_run_and_commit failes to create image: "/usr/bin/python3.9: can't open file '//sh': [Errno 2] No such file or directory"

orblix opened this issue Β· comments

🐞 bug report

Affected Rule

The issue is caused by the rule:

container_run_and_commit

Is this a regression?

Yes.

Description

Trying to create a container image with the container_run_and_commit rule fails.

πŸ”¬ Minimal Reproduction

Trying to create a simple image with postgresql installed fails:

container_pull(
    name = "py3_debug_image_base",
    registry = "gcr.io",
    repository = "distroless/python3",
    digest = "sha256:84b5e6a7e091754b31b34e65307c2f60a4ab1c1ceb583db55da9bbe1f272498a",
)

container_run_and_commit(
    name = "install_postgres",
    commands = [
        "apt-get update",
        "apt-get install -y postgresql",
    ],
    image = "@py3_debug_image_base//image",
)

πŸ”₯ Exception or Error


bazelisk build package/api:install_postgres --define=VERBOSE_LOGS=1

INFO: Analyzed target //package/api:install_postgres (0 packages loaded, 12691 targets configured).
INFO: Found 1 target...
ERROR: /home/enzer/projects/package/api/BUILD:27:25: Action package/api/install_postgres_commit.tar failed: (Exit 1): install_postgres.build failed: error executing command (from target //package/api:install_postgres) bazel-out/k8-fastbuild/bin/package/api/install_postgres.build

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
Loaded image: bazel/image:image
/usr/bin/python3.9: can't open file '//sh': [Errno 2] No such file or directory
648e2f1fa2072c0ec21cb92b69eb8d5d9e172f9a4c5fe9b5a24908bc7433a16e
Target //package/api:install_postgres failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 4.770s, Critical Path: 3.21s
INFO: 2 processes: 2 internal.
FAILED: Build did NOT complete successfully

🌍 Your Environment

Operating System:

  
Linux or-workstation 5.10.0-20-cloud-amd64 #1 SMP Debian 5.10.158-2 (2022-12-13) x86_64 GNU/Linux
  

Output of bazel version:

  
Bazelisk version: v1.15.0
Build label: 6.0.0-pre.20221020.1
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Thu Oct 27 16:53:10 2022 (1666889590)
Build timestamp: 1666889590
Build timestamp as int: 1666889590
  

Rules_docker version:

  
v0.25.0
  

Anything else relevant?

Hey! The image gcr.io/distroless/python3
has apparently the entry point set to the /usr/bin/python3.9.

The commands that this rule executes are stored into the script and passed as a commend to the image, but since the entrypoint is set to python, python reads it

I assume the rule should override entry point, since it executes a shell script.

As a work-around you can reset entry point by adding

    docker_run_flags = [
        "--entrypoint=''",
    ],

to you install_postgres rule.

The image you are using doesn't have apt as well, so you may want to use the other base image as well.

This issue has been automatically marked as stale because it has not had any activity for 180 days. It will be closed if no further activity occurs in 30 days.
Collaborators can add an assignee to keep this open indefinitely. Thanks for your contributions to rules_docker!