Problems with creating files and directories within a Docker container created with rules_oci

74 views Asked by At

My "minimal" setup looks like this:

MODULE.bazel:

bazel_dep(name = "rules_oci", version = "1.6.0")
bazel_dep(name = "rules_pkg", version = "0.9.1")

oci = use_extension("@rules_oci//oci:extensions.bzl", "oci")
oci.toolchains(crane_version = "v0.17.0")
use_repo(oci, "oci_crane_toolchains", "oci_crane_registry_toolchains", "oci_auth_config")

register_toolchains("@oci_crane_toolchains//:all", "@oci_crane_registry_toolchains//:all")

oci.pull(
    name = "bazel",
    tag = "7.0.1",
    image = "gcr.io/bazel-public/bazel",
)

use_repo(oci, "bazel")

BUILD.bazel:

load("@rules_oci//oci:defs.bzl", "oci_image", "oci_push", "oci_tarball")
load("@rules_pkg//:pkg.bzl", "pkg_tar")

pkg_tar(
    name = "app",
    srcs = ["test.sh"],
    mode = "0755",
    package_dir = "/home/ubuntu"
)

oci_image(
    name = "image",
    base = "@bazel",
    cmd = ["test.sh"],
    tars = [":app"],
)

oci_tarball(
    name = "tarball",
    image = ":image",
    repo_tags = ["vertexwahn/my_example:v0.0.1"],
)

.bazelversion:

7.0.1

test.sh:

#!/usr/bin/sh

echo "Hello World!"
mkdir foobar
cd foobar
touch some_file.txt
ls -al

When I try to run the above docker image via:

bazel run //:tarball # build docker image
docker run vertexwahn/my_example:v0.0.1 # run docker container

I get this error:

FATAL: mkdir('/home/ubuntu/.cache/bazel/_bazel_ubuntu'): (error: 13): Permission denied

If I run

docker run --interactive --entrypoint=/bin/bash gcr.io/bazel-public/bazel:7.0.1

And then perform the commands form test.sh manually, it works as expected (folder foobar gets created an contains the file some_file.txt).

If I switch the image to Ubuntu, via:

oci.pull(
    name = "ubuntu",
    digest = "sha256:67211c14fa74f070d27cc59d69a7fa9aeff8e28ea118ef3babc295a0428a6d21",
    image = "ubuntu",
    platforms = [
        "linux/arm64/v8",
        "linux/amd64",
    ],
)

Everything works as expected.

I need Bazel in my Docker container and do not want to bootstrap it myself. Any hints welcome!

0

There are 0 answers