Bazel Docker容器镜像不复制文件 [英] Bazel docker container image not copying file

查看:0
本文介绍了Bazel Docker容器镜像不复制文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试模拟theRUN step您可以在Bazel docker container image rule中显示的docker文件中使用,但由于container_image规则没有复制功能,我正在尝试使用可用的功能。

RUN GRPC_HEALTH_PROBE_VERSION=v0.3.1 && 
    wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 && 
    chmod +x /bin/grpc_health_probe
  go_image(
      name = "go_auth_image",
      embed = [":go-auth_lib"],
      visibility = ["//visibility:public"],
  )

  container_image(
      name = "go_auth_api",
      visibility = ["//visibility:public"],
      base = ":go_auth_image",
      ports = ["5001", "5002"],
      files = ["grpc_health_probe-linux-amd64"],
      symlinks = {
          "grpc_health_prob-linux-amd64": "/bin/grpc_health_probe",
      },
      cmd = [
          "apk add --no-cache git",
          "chmod +x /bin/grpc_health_probe",
      ],
  )

注意:file_map似乎不是container_image

的参数

当我将此镜像部署到K8S时,镜像运行正常,但在描述Pod时,活性探测器(如下所述)失败。

          livenessProbe:
            exec:
              command: ["/bin/grpc_health_probe", "-addr=:5002"]
            initialDelaySeconds: 5
            periodSeconds: 30
            timeoutSeconds: 2
            successThreshold: 1
            failureThreshold: 3
  Warning  Unhealthy  6m42s                  kubelet            Liveness probe errored: rpc error: code = Unknown desc = failed to exec in container: failed to start exec "b6c89b7ec907e572f80be59e8d4b5cad6535a3479d67a3563a09e0d1d2f7ca03": OCI runtime exec failed: exec failed: container_linux.go:370: starting container process caused: exec: "/bin/grpc_health_probe": stat /bin/grpc_health_probe: no such file or directory: unknown

使用Bazel设置此探测器的正确方式是什么(我已确认此方法适用于Dockerfile设置)

推荐答案

container_run_and_commitRUN最接近。类似以下内容的内容直接等同于:

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

GRPC_HEALTH_PROBE_VERSION = "v0.3.1"

container_run_and_commit(
    name = "install_stuff",
    image = ":go_auth_image.tar",
    commands = [
        "wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/%s/grpc_health_probe-linux-amd64" % GRPC_HEALTH_PROBE_VERSION,
        "chmod +x /bin/grpc_health_probe",
    ],
)


container_image(
    name = "go_auth_api",
    visibility = ["//visibility:public"],
    base = ":install_stuff",
    ... # everything else you're doing with container_image
)

它运行命令a生成新映像,然后使用container_image向结果中添加内容。

然而,使用Bazel进行更多的构建将更好地利用Bazel的缓存,并且更具可重复性。我认为这就是您正在对grpc_health_probe-linux-amd64源文件执行的操作。该方法如下所示:

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

container_image(
    name = "add_stuff",
    base = ":go_auth_image",
    ports = ["5001", "5002"],
    files = ["grpc_health_probe-linux-amd64"],
    symlinks = {
        "grpc_health_prob-linux-amd64": "/bin/grpc_health_probe",
    },
)

container_run_and_commit(
    name = "go_auth_api",
    visibility = ["//visibility:public"],
    image = ":add_stuff.tar",
    commands = [
        "apk add --no-cache git",
        "chmod +x /bin/grpc_health_probe",
    ],
)

首先使用container_image添加内容,然后运行命令。

此外,您可以使用pkg_tar打包文件+symlink(它和container_image一样有一个symlinks属性),然后设置mode = 0755,而不是运行chmod +xcontainer_image.tars将获取tar文件并将其添加到图像中。通常,pkg_tar为构建文件提供了很大的灵活性,并且container_image直接将其功能的子集用于简单的用例。

container_image.cmd相当于Dockerfile中的CMD。它只是在使用容器时设置信息,在构建容器时不做任何事情。我认为您根本不想为此使用它。

这篇关于Bazel Docker容器镜像不复制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆