简体   繁体   English

Bazel 无法在映像中安装_pkgs

[英]Bazel unable to install_pkgs in an image

I am trying to add some packages to distroless debian-11 python image ( gcr.io/distroless/python3-debian11:debug ).我正在尝试将一些软件包添加到 distroless debian-11 python 映像( gcr.io/distroless/python3-debian11:debug )。 Bazel build is succeeding but when I run the generate image, the debian pacakges were not present. Bazel 构建成功,但是当我运行生成映像时,debian pacakges 不存在。 In case if you like to clone for quick testing here is the project link git clone https://github.com/BhanuKiranChaluvadi/getting-started-with-bazel.git .如果您想克隆以进行快速测试,这里是项目链接git clone https://github.com/BhanuKiranChaluvadi/getting-started-with-bazel.git Here is my project structure这是我的项目结构

├── BUILD
├── README.md
├── ros2
│   └── BUILD
└── WORKSPACE

ros2/BUILD ros2/构建

load("@io_bazel_rules_docker//container:container.bzl", "container_image")
load("@io_bazel_rules_docker//contrib:test.bzl", "container_test")
load("@io_bazel_rules_docker//docker/package_managers:download_pkgs.bzl", "download_pkgs")
load("@io_bazel_rules_docker//docker/package_managers:install_pkgs.bzl", "install_pkgs")

download_pkgs(
    name = "ros2_humble_pkgs",
    image_tar = "@debian11-slim//image",
    packages = [
        "libpython3.9",
        "libtinyxml2-8",
        "libfmt7",
    ],
)

'''

install_pkgs(
    name = "ros2_pkgs_image",
    image_tar = "@debian11-slim//image",
    installables_tar = ":ros2_humble_pkgs.tar",
    installation_cleanup_commands = "rm -rf /var/lib/apt/lists/*",
    output_image_name = "debian11-slim/ros2",
)
'''

install_pkgs(
    name = "ros2_pkgs_image",
    image_tar = "@python3-debian11//image",    # distroless image -- see WORKSPACE
    installables_tar = ":ros2_humble_pkgs.tar",
    installation_cleanup_commands = "rm -rf /var/lib/apt/lists/*",
    output_image_name = "distroless/ros2-debian11",
)

If I uncomment the block with image_tar = "@debian11-slim//image" and comment the image_tar = "@python3-debian11//image" .如果我用image_tar = "@debian11-slim//image"取消注释该块并注释image_tar = "@python3-debian11//image" The generated image looks fine and all the packages were installed as expected.生成的图像看起来不错,并且所有软件包都按预期安装。 It has only issues with the python3-debian11 distroless image它只对python3-debian11 distroless 映像有问题

WORKSPACE工作空间

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "io_bazel_rules_docker",
    sha256 = "b1e80761a8a8243d03ebca8845e9cc1ba6c82ce7c5179ce2b295cd36f7e394bf",
    urls = ["https://github.com/bazelbuild/rules_docker/releases/download/v0.25.0/rules_docker-v0.25.0.tar.gz"],
)

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

load(
    "@io_bazel_rules_docker//repositories:go_repositories.bzl",
    container_go_deps = "go_deps",
)
container_go_deps()

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

load("@io_bazel_rules_docker//container:container.bzl", "container_pull")
load("@io_bazel_rules_docker//python3:image.bzl", _python_image_repos = "repositories")

_python_image_repos()

container_pull(
    name = "python3-debian11",
    registry = "gcr.io",
    repository = "distroless/python3-debian11",
#   digest = "sha256:89dbc1d37ecf23622c3c795a4e50035e7c550084291f789003da890653d19c25",
    tag = "debug",
)

container_pull(
    name = "debian11-slim",
    registry = "docker.io",
    repository = "library/debian",
    digest = "sha256:d2285c63f42a27d633afa75929529c3761883faac292e7c1cf310d91c7399863",
    tag = "11-slim",
)

After a little bit of searching through the files bazel build --logging 6 //... generated bazel-bin/ros2/ros2_pkgs_image.install在对文件进行一些搜索之后bazel build --logging 6 //...生成bazel-bin/ros2/ros2_pkgs_image.install

ros2_pkgs_image.install ros2_pkgs_image.install

#!/usr/bin/env bash
# This script installs debs in installables.tar through dpkg and apt-get.
# It expects to be volume-mounted inside a docker image, in /tmp/pkginstall
# along with the installables.tar.
set -e
pushd /tmp/pkginstall

tar -xvf bazel-out/k8-fastbuild/bin/ros2/ros2_humble_pkgs.tar
dpkg -i --force-depends ./*.deb
dpkg --configure -a
apt-get install -f
rm -rf /var/lib/apt/lists/*
# delete the files that vary build to build
rm -f /var/log/dpkg.log
rm -f /var/log/alternatives.log
rm -f /var/cache/ldconfig/aux-cache
rm -f /var/cache/apt/pkgcache.bin
mkdir -p /run/mount/ && touch /run/mount/utab
popd
umount -l /tmp/pkginstall
rm -rf /tmp/*

It looks like it is mounting the downloaded packages folder and unpacking using dpkg.看起来它正在安装下载的包文件夹并使用 dpkg 解包。 But distroless python images doesn't have dpkg/apt install in them.但是 distroless python 图像中没有 dpkg/apt 安装。 Is that the reason the packages are not being installed ?这是没有安装软件包的原因吗? If so why the bazel build //... is not failing ?如果是这样,为什么bazel build //...没有失败?

DEBUG: If you would like to debug generated image DEBUG:如果您想调试生成的图像

docker run -it --rm --entrypoint sh distroless/ros2-debian11:latest
# example library from libfmt
ls /usr/lib/x86_64-linux-gnu/libfmt.so.7.1.3

install_pkgs start the container and download all the necessary packages. install_pkgs启动容器并下载所有必要的包。 Since distroless packages has not apt package installed inside them.由于 distroless 软件包中没有安装 apt 软件包。 The installation package might be failing.安装包可能失败。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM