Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error validating output TreeArtifact File when building an oci_image #425

Closed
njlr opened this issue Nov 28, 2023 · 18 comments · Fixed by #449
Closed

Error validating output TreeArtifact File when building an oci_image #425

njlr opened this issue Nov 28, 2023 · 18 comments · Fixed by #449
Labels
need: investigation A potential issue which we need to investigate first

Comments

@njlr
Copy link

njlr commented Nov 28, 2023

I am trying to migrate from rules_docker but am running into some issues.

Here is my setup:

.bazelversion

7.0.0rc4

WORKSPACE

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

http_archive(
  name = "rules_oci",
  sha256 = "d41d0ba7855f029ad0e5ee35025f882cbe45b0d5d570842c52704f7a47ba8668",
  strip_prefix = "rules_oci-1.4.3",
  url = "https://github.com/bazel-contrib/rules_oci/releases/download/v1.4.3/rules_oci-v1.4.3.tar.gz",
)

load("@rules_oci//oci:dependencies.bzl", "rules_oci_dependencies")

rules_oci_dependencies()

load("@rules_oci//oci:repositories.bzl", "LATEST_CRANE_VERSION", "oci_register_toolchains")

oci_register_toolchains(
  name = "oci",
  crane_version = LATEST_CRANE_VERSION,
)

oci_pull(
  name = "dotnet_runtime_deps_6_0_10",
  digest = "sha256:24554fadd483d8305974ded44bb1dbe4916e2f02500b9e2d78e7beb557cfebd0",
  image = "mcr.microsoft.com/dotnet/runtime-deps",
)

BUILD.bazel

load("@rules_oci//oci:defs.bzl", "oci_image")

oci_image(
  name = "image_debian",
  base = "@dotnet_runtime_deps_6_0_10",
  workdir = "/home",
)

The error:

$ bazel build //:image_debian
INFO: Analyzed target //:image_debian (2 packages loaded, 12 targets configured).
ERROR: /home/njlr/.cache/bazel/_bazel_njlr/c456fd825f274c1010edddb5a9ae4bdd/external/dotnet_runtime_deps_6_0_10_single/BUILD.bazel:16:18: Error while validating output TreeArtifact File:[[<execution_root>]bazel-out/k8-fastbuild/bin]external/dotnet_runtime_deps_6_0_10_single/blobs/sha256 : Failed to resolve relative path 24554fadd483d8305974ded44bb1dbe4916e2f02500b9e2d78e7beb557cfebd0 inside TreeArtifact /home/njlr/.cache/bazel/_bazel_njlr/c456fd825f274c1010edddb5a9ae4bdd/execroot/_main/bazel-out/k8-fastbuild/bin/external/dotnet_runtime_deps_6_0_10_single/blobs/sha256. The associated file is either missing or is an invalid symlink.
ERROR: /home/njlr/.cache/bazel/_bazel_njlr/c456fd825f274c1010edddb5a9ae4bdd/external/dotnet_runtime_deps_6_0_10_single/BUILD.bazel:16:18: Copying files to directory dotnet_runtime_deps_6_0_10_single/blobs/sha256 failed: not all outputs were created or valid
Target //:image_debian failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 1.303s, Critical Path: 0.14s
INFO: 2 processes: 1 internal, 1 linux-sandbox.
ERROR: Build did NOT complete successfully
@alexeagle
Copy link
Collaborator

Hm, I guess something about this mcr.microsoft.com/dotnet/runtime-deps image is constructed incorrectly, or else we are making an incorrect assumption about the layer metadata for images.
I think the next step is to open up that image and see whether the sha256 we are unable to locate ought to be there.

@alexeagle alexeagle added the need: investigation A potential issue which we need to investigate first label Nov 29, 2023
@njlr
Copy link
Author

njlr commented Nov 30, 2023

Hmm interesting, there are no sha256 files.

$ docker pull mcr.microsoft.com/dotnet/runtime-deps@sha256:24554fadd483d8305974ded44bb1dbe4916e2f02500b9e2d78e7beb557cfebd0

$ docker save mcr.microsoft.com/dotnet/runtime-deps@sha256:24554fadd483d8305974ded44bb1dbe4916e2f02500b9e2d78e7beb557cfebd0 > image.tar

$ tar -xvf ./image.tar 
9629ad6e05e05dcbe2efeb2e21050346d75e7716a89097e1a99a6128644fdb7f.json
d3010e0e22efbe19c9653b0d1f5b923649a3bb9a809b1024e3557b1a0a4cd51a/
d3010e0e22efbe19c9653b0d1f5b923649a3bb9a809b1024e3557b1a0a4cd51a/VERSION
d3010e0e22efbe19c9653b0d1f5b923649a3bb9a809b1024e3557b1a0a4cd51a/json
d3010e0e22efbe19c9653b0d1f5b923649a3bb9a809b1024e3557b1a0a4cd51a/layer.tar
eb18f9a708a4f682536a7eaf85f73a9f706040047016a3a41a974cbbe9829323/
eb18f9a708a4f682536a7eaf85f73a9f706040047016a3a41a974cbbe9829323/VERSION
eb18f9a708a4f682536a7eaf85f73a9f706040047016a3a41a974cbbe9829323/json
eb18f9a708a4f682536a7eaf85f73a9f706040047016a3a41a974cbbe9829323/layer.tar
manifest.json

$ docker inspect mcr.microsoft.com/dotnet/runtime-deps@sha256:24554fadd483d8305974ded44bb1dbe4916e2f02500b9e2d78e7beb557cfebd0     
[
    {
        "Id": "sha256:9629ad6e05e05dcbe2efeb2e21050346d75e7716a89097e1a99a6128644fdb7f",
        "RepoTags": [
            "bazel/image:image"
        ],
        "RepoDigests": [
            "mcr.microsoft.com/dotnet/runtime-deps@sha256:24554fadd483d8305974ded44bb1dbe4916e2f02500b9e2d78e7beb557cfebd0"
        ],
        "Parent": "",
        "Comment": "",
        "Created": "2022-10-25T04:25:58.281747234Z",
        "Container": "802335d3db455e68b4d872658e6bd032f7a56f24a0886d80f443c58cd37993f6",
        "ContainerConfig": {
            "Hostname": "802335d3db45",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "ASPNETCORE_URLS=http://+:80",
                "DOTNET_RUNNING_IN_CONTAINER=true"
            ],
            "Cmd": [
                "/bin/sh",
                "-c",
                "#(nop) ",
                "ENV ASPNETCORE_URLS=http://+:80 DOTNET_RUNNING_IN_CONTAINER=true"
            ],
            "Image": "sha256:1b869bb0bbfb8680c1b72689cfbef8d84eff5bc63f289b7038e1991506c2122f",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {}
        },
        "DockerVersion": "20.10.17",
        "Author": "",
        "Config": {
            "Hostname": "",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "ASPNETCORE_URLS=http://+:80",
                "DOTNET_RUNNING_IN_CONTAINER=true"
            ],
            "Cmd": [
                "bash"
            ],
            "Image": "sha256:1b869bb0bbfb8680c1b72689cfbef8d84eff5bc63f289b7038e1991506c2122f",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": null
        },
        "Architecture": "amd64",
        "Os": "linux",
        "Size": 116760754,
        "VirtualSize": 116760754,
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/0391c998bfdda0d14df4e3bdfbcb12ac4ee6432650f64a7e01c115ba32c6ce2a/diff",
                "MergedDir": "/var/lib/docker/overlay2/6b7df02ff02ff0ee2239f98b246ff4eadba62996ce1ec8c9bfa976a06199aa90/merged",
                "UpperDir": "/var/lib/docker/overlay2/6b7df02ff02ff0ee2239f98b246ff4eadba62996ce1ec8c9bfa976a06199aa90/diff",
                "WorkDir": "/var/lib/docker/overlay2/6b7df02ff02ff0ee2239f98b246ff4eadba62996ce1ec8c9bfa976a06199aa90/work"
            },
            "Name": "overlay2"
        },
        "RootFS": {
            "Type": "layers",
            "Layers": [
                "sha256:a12586ed027fafddcddcc63b31671f406c25e43342479fc92a330e7e30d65f2e",
                "sha256:55125ebb892069bd16e8dedc05e382be6a818ed99026f2e5f8578852b7c6d1cb"
            ]
        },
        "Metadata": {
            "LastTagTime": "0001-01-01T00:00:00Z"
        }
    }
]

@alexeagle
Copy link
Collaborator

Thanks @njlr for pasting those bits, I didn't have time to remember the commands to gather that.

@thesayyn I'm out of my depth on this one, WDYT?

@thesayyn
Copy link
Collaborator

thesayyn commented Dec 1, 2023

hmm it's weird. looks like the blobs directory created by is missing. i wonder if the image is using different hash algo than sha256

@diedoman
Copy link

We are running into the same issue, but using a different base image:

bazel_dep(name = "rules_oci", version = "1.4.3")
oci = use_extension("@rules_oci//oci:extensions.bzl", "oci")
oci.pull(
    name = "distroless_base",
    digest = "sha256:d64f5483d2fd0cec2260941c443cb2947102e46e1a9fe36a321d0a788c1a49e0",
    image = "gcr.io/distroless/base-debian12",
    platforms = [
        "linux/amd64",
        "linux/arm64",
    ],
)
use_repo(oci, "distroless_base")

The odd thing is that it works with version 1.4.0, but 1.4.2 and 1.4.3 fail.

ERROR: /home/diederik/.cache/bazel/_bazel_diederik/c8b45a952eed86141685c815fee95aff/external/rules_oci~1.4.3~oci~distroless_base_linux_amd64/BUILD.bazel:16:18: Error while validating output TreeArtifact File:[[<execution_root>]bazel-out/k8-fastbuild/bin]external/rules_oci~1.4.3~oci~distroless_base_linux_amd64/blobs/sha256 : Failed to resolve relative path ee5d155830c29fbb37ff1a8eae4a72f3efe12975e76069792be56f03294a4397 inside TreeArtifact /home/diederik/.cache/bazel/_bazel_diederik/c8b45a952eed86141685c815fee95aff/execroot/_main/bazel-out/k8-fastbuild/bin/external/rules_oci~1.4.3~oci~distroless_base_linux_amd64/blobs/sha256. The associated file is either missing or is an invalid symlink.
ERROR: /home/diederik/.cache/bazel/_bazel_diederik/c8b45a952eed86141685c815fee95aff/external/rules_oci~1.4.3~oci~distroless_base_linux_amd64/BUILD.bazel:16:18: Copying files to directory rules_oci~1.4.3~oci~distroless_base_linux_amd64/blobs/sha256 failed: not all outputs were created or valid

Not sure if it helps, but the generated file by oci_pul mentions that same shasum as being the 'manifest.json' being added to the container image. Could it be that that file is not present in the container image yet?


"Generated by oci_pull"

load("@aspect_bazel_lib//lib:copy_to_directory.bzl", "copy_to_directory")
load("@aspect_bazel_lib//lib:copy_file.bzl", "copy_file")
load("@aspect_bazel_lib//lib:jq.bzl", "jq")
load("@bazel_skylib//rules:write_file.bzl", "write_file")

package(default_visibility = ["//visibility:public"])

copy_file(
    name = "manifest",
    src = "manifest.json",
    out = "ee5d155830c29fbb37ff1a8eae4a72f3efe12975e76069792be56f03294a4397"
)

copy_to_directory(
    name = "blobs",
    # TODO(https://github.com/bazel-contrib/rules_oci/issues/73): other hash algorithms
    out = "blobs/sha256",
    include_external_repositories = ["*"],
    srcs = ["98478ba62ec6d8c6818a38f4c9246b02a4447bd97bcf79f27e2a8ccac6bb09ba", "2b776ada03417eaa87102a617f964324df1de8967698fc4209dc1a1fbdfae8cd", "66d6209d01f4b895b53674f28af3144788193cbde0f1e40de48294207137d677", "fcb6f6d2c9986d9cd6a2ea3cc2936e5fc613e09f1af9042329011e43057f3265", "e8c73c638ae9ec5ad70c49df7e484040d889cca6b4a9af056579c3d058ea93f0", "1e3d9b7d145208fa8fa3ee1c9612d0adaac7255f1bbc9ddea7e461e0b317805c", "4aa0ea1413d37a58615488592a0b827ea4b2e48fa5a77cf707d0e35f025e613f", "2fa82a9c76b2292e1c056fb1ed61bd0d29ddb196bbd3ac1a60d29d5eecc9e553", "672354a91bfa8da293349f3384c1a32f35a0791ae4658a17967e3b4aedd3554b", "7eededbe27f6301541784b15dda688da1051b13fa0a1da9a6e85163b03e1c1dd", "18e56fcf1c27e79f8624f55a3d3c923a9810cb49ec6e73342c13edd427a74f4d"] + [
        ":ee5d155830c29fbb37ff1a8eae4a72f3efe12975e76069792be56f03294a4397",
        ":115fdab283b6c58ad93a88122b337f2ac514455bd472bf50070f0d2cd8e6ea71",
    ],
)

@JRBANCEL
Copy link

I am migrating from rules_docker to rules_oci. Facing the same issue in 1.4.3 and 1.4.2.
Works fine in 1.4.0.

@thesayyn
Copy link
Collaborator

@diedoman i am able to successfully build what you pasted above.

Note that your platforms definition was incorrect. you needed linux/arm64/v8 instead of linux/arm64

oci = use_extension("@rules_oci//oci:extensions.bzl", "oci")
oci.pull(
    name = "distroless_base",
    digest = "sha256:d64f5483d2fd0cec2260941c443cb2947102e46e1a9fe36a321d0a788c1a49e0",
    image = "gcr.io/distroless/base-debian12",
    platforms = [
        "linux/amd64",
        "linux/arm64/v8",
    ],
)
use_repo(oci, "distroless_base")
use_repo(oci, "distroless_base_linux_arm64_v8")

@thesayyn
Copy link
Collaborator

I am not able to reproduce this...

@uhlajs
Copy link
Contributor

uhlajs commented Dec 14, 2023

Same issue on my side. I will try to provide logs later on, but I guess this could be problem with bazel6 -> bazel7 transition.

@jrockway
Copy link

jrockway commented Dec 15, 2023

Yes, this seems to be a bazel 7 thing.

Example MODULE.bazel:

module(
    name = "bazel_test_area",
)

bazel_dep(name = "rules_oci", version = "1.4.3")

oci = use_extension("@rules_oci//oci:extensions.bzl", "oci")

oci.pull(
    name = "distroless_base",
    digest = "sha256:b31a6e02605827e77b7ebb82a0ac9669ec51091edd62c2c076175e05556f4ab9",
    image = "gcr.io/distroless/base",
    platforms = [
        "linux/amd64",
        "linux/arm/v7",
        "linux/arm64/v8",
        "linux/ppc64le",
        "linux/s390x",
    ],
)

use_repo(oci, "distroless_base")

With 7.0.0:

$ bazel build @distroless_base//:distroless_base
INFO: Analyzed target @@rules_oci~1.4.3~oci~distroless_base//:distroless_base (50 packages loaded, 247 targets configured).
ERROR: /home/jrockway/.cache/bazel/_bazel_jrockway/73bbccb2c6bf9ab4d70b0ba8478635bc/external/rules_oci~1.4.3~oci~distroless_base_linux_amd64/BUILD.bazel:16:18: Error while validating output TreeArtifact File:[[<execution_root>]bazel-out/k8-fastbuild/bin]external/rules_oci~1.4.3~oci~distroless_base_linux_amd64/blobs/sha256 : Failed to resolve relative path 6c871aa3c9019984dfd7f520635bd658d740ad20c6268a82faa433f69dfc9a0b inside TreeArtifact /home/jrockway/.cache/bazel/_bazel_jrockway/73bbccb2c6bf9ab4d70b0ba8478635bc/execroot/_main/bazel-out/k8-fastbuild/bin/external/rules_oci~1.4.3~oci~distroless_base_linux_amd64/blobs/sha256. The associated file is either missing or is an invalid symlink.
ERROR: /home/jrockway/.cache/bazel/_bazel_jrockway/73bbccb2c6bf9ab4d70b0ba8478635bc/external/rules_oci~1.4.3~oci~distroless_base_linux_amd64/BUILD.bazel:16:18: Copying files to directory rules_oci~1.4.3~oci~distroless_base_linux_amd64/blobs/sha256 failed: not all outputs were created or valid
Target @@rules_oci~1.4.3~oci~distroless_base_linux_amd64//:distroless_base_linux_amd64 failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 3.632s, Critical Path: 0.49s
INFO: 5 processes: 3 internal, 2 linux-sandbox.
ERROR: Build did NOT complete successfully

With 6.4.0:

$ bazel build --enable_bzlmod @distroless_base//:distroless_base
INFO: Analyzed target @rules_oci~1.4.3~oci~distroless_base//:distroless_base (43 packages loaded, 207 targets configured).
INFO: Found 1 target...
Target @rules_oci~1.4.3~oci~distroless_base_linux_amd64//:distroless_base_linux_amd64 up-to-date:
  bazel-bin/external/rules_oci~1.4.3~oci~distroless_base_linux_amd64/layout
INFO: Elapsed time: 4.136s, Critical Path: 0.10s
INFO: 6 processes: 3 internal, 3 linux-sandbox.
INFO: Build completed successfully, 6 total actions

Oddly, despite the message that /home/jrockway/.cache/bazel/_bazel_jrockway/73bbccb2c6bf9ab4d70b0ba8478635bc/execroot/_main/bazel-out/k8-fastbuild/bin/external/rules_oci~1.4.3~oci~distroless_base_linux_amd64/blobs/sha256/6c871aa3c9019984dfd7f520635bd658d740ad20c6268a82faa433f69dfc9a0b doesn't exist, it... does:

cat /home/jrockway/.cache/bazel/_bazel_jrockway/73bbccb2c6bf9ab4d70b0ba8478635bc/execroot/_main/bazel-out/k8-fastbuild/bin/external/rules_oci~1.4.3~oci~distroless_base_linux_amd64/blobs/sha256/6c871aa3c9019984dfd7f520635bd658d740ad20c6268a82faa433f69dfc9a0b
{"schemaVersion":2,"mediaType":"application/vnd.oci.image.manifest.v1+json","config":{"mediaType":"application/vnd.oci.image.config.v1+json","size":1596,"digest":"sha256:2e46274151...

@alexeagle
Copy link
Collaborator

@jrockway since you have that repro handy, do you mind trying the 7.0.0rcX releases to see if there's a value of X where it's introduced - that would help us bisect

@jrockway
Copy link

jrockway commented Dec 15, 2023

Good idea! 7.0.0rc3: good. 7.0.0rc4: bad.

Full transcript:

$ bazel clean
INFO: Starting clean (this may take a while). Consider using --async if the clean takes more than several minutes.

$ bazel version
Bazelisk version: development
Build label: 7.0.0rc3
Build target: @@//src/main/java/com/google/devtools/build/lib/bazel:BazelServer
Build time: Wed Nov 8 17:29:37 2023 (1699464577)
Build timestamp: 1699464577
Build timestamp as int: 1699464577

$ bazel build @distroless_base//:distroless_base
INFO: Analyzed target @rules_oci~1.4.3~oci~distroless_base//:distroless_base (50 packages loaded, 247 targets configured).
INFO: Found 1 target...
Target @rules_oci~1.4.3~oci~distroless_base_linux_amd64//:distroless_base_linux_amd64 up-to-date:
  bazel-bin/external/rules_oci~1.4.3~oci~distroless_base_linux_amd64/layout
INFO: Elapsed time: 0.399s, Critical Path: 0.07s
INFO: 6 processes: 3 internal, 3 linux-sandbox.
INFO: Build completed successfully, 6 total actions

$ bazel clean
Starting local Bazel server and connecting to it...
INFO: Starting clean (this may take a while). Consider using --async if the clean takes more than several minutes.

$ bazel version
Bazelisk version: development
Build label: 7.0.0rc4
Build target: @@//src/main/java/com/google/devtools/build/lib/bazel:BazelServer
Build time: Thu Nov 16 20:34:43 2023 (1700166883)
Build timestamp: 1700166883
Build timestamp as int: 1700166883

$ bazel build @distroless_base//:distroless_base
INFO: Analyzed target @@rules_oci~1.4.3~oci~distroless_base//:distroless_base (50 packages loaded, 247 targets configured).
ERROR: /home/jrockway/.cache/bazel/_bazel_jrockway/73bbccb2c6bf9ab4d70b0ba8478635bc/external/rules_oci~1.4.3~oci~distroless_base_linux_amd64/BUILD.bazel:16:18: Error while validating output TreeArtifact File:[[<execution_root>]bazel-out/k8-fastbuild/bin]external/rules_oci~1.4.3~oci~distroless_base_linux_amd64/blobs/sha256 : Failed to resolve relative path 6c871aa3c9019984dfd7f520635bd658d740ad20c6268a82faa433f69dfc9a0b inside TreeArtifact /home/jrockway/.cache/bazel/_bazel_jrockway/73bbccb2c6bf9ab4d70b0ba8478635bc/execroot/_main/bazel-out/k8-fastbuild/bin/external/rules_oci~1.4.3~oci~distroless_base_linux_amd64/blobs/sha256. The associated file is either missing or is an invalid symlink.
ERROR: /home/jrockway/.cache/bazel/_bazel_jrockway/73bbccb2c6bf9ab4d70b0ba8478635bc/external/rules_oci~1.4.3~oci~distroless_base_linux_amd64/BUILD.bazel:16:18: Copying files to directory rules_oci~1.4.3~oci~distroless_base_linux_amd64/blobs/sha256 failed: not all outputs were created or valid
Target @@rules_oci~1.4.3~oci~distroless_base_linux_amd64//:distroless_base_linux_amd64 failed to build
Use --verbose_failures to see the command lines of failed build steps.                                                                                                              INFO: Elapsed time: 2.918s, Critical Path: 0.05s
INFO: 5 processes: 3 internal, 2 linux-sandbox.
ERROR: Build did NOT complete successfully

(I don't think the bazel clean is necessary for the repro but seemed like it wouldn't hurt.)

@debkanchan
Copy link

Using bazel 7 stable release and facing this same issue

MODULE.bazel

bazel_dep(name = "rules_oci", version = "1.4.3")

oci = use_extension("@rules_oci//oci:extensions.bzl", "oci")

oci.pull(
    name = "distroless",
    digest = "sha256:6706c73aae2afaa8201d63cc3dda48753c09bcd6c300762251065c0f7e602b25",
    image = "gcr.io/distroless/static",
    platforms = [
        "linux/amd64",
        "linux/arm64/v8",
    ],
)

# For each oci.pull call, repeat the "name" here to expose them as dependencies.
use_repo(oci, "distroless")

WORKSPACE

# Declares that this directory is the root of a Bazel workspace.
# See https://docs.bazel.build/versions/main/build-ref.html#workspace
workspace(
    # How this workspace would be referenced with absolute labels from another workspace
    name = "driver-service",
)

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

## GO
http_archive(
    name = "io_bazel_rules_go",
    sha256 = "d6ab6b57e48c09523e93050f13698f708428cfd5e619252e369d377af6597707",
    urls = [
        "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.43.0/rules_go-v0.43.0.zip",
        "https://github.com/bazelbuild/rules_go/releases/download/v0.43.0/rules_go-v0.43.0.zip",
    ],
)

http_archive(
    name = "bazel_gazelle",
    sha256 = "b7387f72efb59f876e4daae42f1d3912d0d45563eac7cb23d1de0b094ab588cf",
    urls = [
        "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.34.0/bazel-gazelle-v0.34.0.tar.gz",
        "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.34.0/bazel-gazelle-v0.34.0.tar.gz",
    ],
)

load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")

############################################################
# Define your own dependencies here using go_repository.
# Else, dependencies declared by rules_go/gazelle will be used.
# The first declaration of an external repository "wins".
############################################################

load("//:go_deps.bzl", "go_dependencies")

# gazelle:repository_macro go_deps.bzl%go_dependencies
go_dependencies()

go_rules_dependencies()

go_register_toolchains(version = "1.20.5")

gazelle_dependencies()

gazelle_dependencies(go_repository_default_config = "//:WORKSPACE")

# ## Buf.build

http_archive(
    name = "rules_buf",
    sha256 = "523a4e06f0746661e092d083757263a249fedca535bd6dd819a8c50de074731a",
    strip_prefix = "rules_buf-0.1.1",
    urls = [
        "https://github.com/bufbuild/rules_buf/archive/refs/tags/v0.1.1.zip",
    ],
)

load("@rules_buf//buf:repositories.bzl", "rules_buf_dependencies", "rules_buf_toolchains")

rules_buf_dependencies()

rules_buf_toolchains(version = "v1.27.0")

load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
load("//:buf_deps.bzl", "buf_deps")

# gazelle:repository_macro buf_deps.bzl%buf_deps
buf_deps()

rules_proto_dependencies()

rules_proto_toolchains()

load("@rules_buf//gazelle/buf:repositories.bzl", "gazelle_buf_dependencies")

gazelle_buf_dependencies()

Error:

ERROR: /home/runner/.cache/bazel/_bazel_runner/83ec04a7f9edb0d4347368d686832579/external/rules_oci~1.4.3~oci~distroless_linux_amd64/BUILD.bazel:16:18: Error while validating output TreeArtifact File:[[<execution_root>]bazel-out/k8-fastbuild/bin]external/rules_oci~1.4.3~oci~distroless_linux_amd64/blobs/sha256 : Failed to resolve relative path d49f214e6f1bae819e24f651156552b073725592cae128a66eade0c6280f02e1 inside TreeArtifact /home/runner/.cache/bazel/_bazel_runner/83ec04a7f9edb0d4347368d686832579/execroot/_main/bazel-out/k8-fastbuild/bin/external/rules_oci~1.4.3~oci~distroless_linux_amd64/blobs/sha256. The associated file is either missing or is an invalid symlink.
ERROR: /home/runner/.cache/bazel/_bazel_runner/83ec04a7f9edb0d4347368d686832579/external/rules_oci~1.4.3~oci~distroless_linux_amd64/BUILD.bazel:16:18: Copying files to directory rules_oci~1.4.3~oci~distroless_linux_amd64/blobs/sha256 failed: not all outputs were created or valid

Although the notable aspect is it's only happening in github action runner and not on local macOS machine even after bazel clean --expunge

I was able to retrieve the BUILD.bazel file causing this error

"Generated by oci_pull"

load("@aspect_bazel_lib//lib:copy_to_directory.bzl", "copy_to_directory")
load("@aspect_bazel_lib//lib:copy_file.bzl", "copy_file")
load("@aspect_bazel_lib//lib:jq.bzl", "jq")
load("@bazel_skylib//rules:write_file.bzl", "write_file")

package(default_visibility = ["//visibility:public"])

copy_file(
    name = "manifest",
    src = "manifest.json",
    out = "d49f214e6f1bae819e24f651156552b073725592cae128a66eade0c6280f02e1"
)

copy_to_directory(
    name = "blobs",
    # TODO(https://github.com/bazel-contrib/rules_oci/issues/73): other hash algorithms
    out = "blobs/sha256",
    include_external_repositories = ["*"],
    srcs = ["07a64a71e01156f8f99039bc246149925c6d1480d3957de78510bbec6ec68f7a", "fe5ca62666f04366c8e7f605aa82997d71320183e99962fa76b3209fdfbb8b58", "b02a7525f878e61fc1ef8a7405a2cc17f866e8de222c1c98fd6681aff6e509db", "fcb6f6d2c9986d9cd6a2ea3cc2936e5fc613e09f1af9042329011e43057f3265", "e8c73c638ae9ec5ad70c49df7e484040d889cca6b4a9af056579c3d058ea93f0", "1e3d9b7d145208fa8fa3ee1c9612d0adaac7255f1bbc9ddea7e461e0b317805c", "4aa0ea1413d37a58615488592a0b827ea4b2e48fa5a77cf707d0e35f025e613f", "7c881f9ab25e0d86562a123b5fb56aebf8aa0ddd7d48ef602faf8d1e7cf43d8c", "5627a970d25e752d971a501ec7e35d0d6fdcd4a3ce9e958715a686853024794a"] + [
        ":d49f214e6f1bae819e24f651156552b073725592cae128a66eade0c6280f02e1",
        ":121a1df34efd36214f556caf5b11c7ec97a53f64285708d860aa175109bf7e6c",
    ],
)

copy_to_directory(
    name = "distroless_linux_amd64",
    out = "layout",
    include_external_repositories = ["*"],
    srcs = [
        "blobs",
        "oci-layout",
        "index.json",
    ],
)

@bluec0re
Copy link

bluec0re commented Dec 18, 2023

Was able to identify the breaking commit (for our code base at least):
bazelbuild/bazel@fe85936 (bisect output: https://gist.github.com/bluec0re/8e23e5526b5edb923b0d610ba9e862dc)

$ bazel build @distroless_base_linux_amd64//:blobs
INFO: Invocation ID: f48ad36e-33ff-4ffc-ad03-50fd559e7415
INFO: Analyzed target @@distroless_base_linux_amd64//:blobs (73 packages loaded, 420 targets configured).
ERROR: /home/user/.cache/bazel/_bazel_user/6c109061545dd338362c45d6f901ff54/external/distroless_base_linux_amd64/BUILD.bazel:16:18: Error while validating output TreeArtifact File:[[<execution_root>]bazel-out/k8-fastbuild/bin]external/distroless_base_linux_amd64/blobs/sha256 : Failed to resolve relative path 6c871aa3c9019984dfd7f520635bd658d740ad20c6268a82faa433f69dfc9a0b inside TreeArtifact /home/user/.cache/bazel/_bazel_user/6c109061545dd338362c45d6f901ff54/execroot/_main/bazel-out/k8-fastbuild/bin/external/distroless_base_linux_amd64/blobs/sha256. The associated file is either missing or is an invalid symlink.
ERROR: /home/user/.cache/bazel/_bazel_user/6c109061545dd338362c45d6f901ff54/external/distroless_base_linux_amd64/BUILD.bazel:16:18: Copying files to directory distroless_base_linux_amd64/blobs/sha256 failed: not all outputs were created or valid
Target @@distroless_base_linux_amd64//:blobs failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.525s, Critical Path: 0.06s
INFO: 4 processes: 2 internal, 2 linux-sandbox.
ERROR: Build did NOT complete successfully
zsh: exit 1     bazel build @distroless_base_linux_amd64//:blobs

$ bazel build --noincompatible_sandbox_hermetic_tmp @distroless_base_linux_amd64//:blobs
INFO: Invocation ID: a4c54efb-4945-407b-81bc-c6fc2ed16fbd
INFO: Analyzed target @@distroless_base_linux_amd64//:blobs (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target @@distroless_base_linux_amd64//:blobs up-to-date:
  bazel-bin/external/distroless_base_linux_amd64/blobs/sha256
INFO: Elapsed time: 0.117s, Critical Path: 0.04s
INFO: 2 processes: 1 internal, 1 linux-sandbox.
INFO: Build completed successfully, 2 total actions

@bluec0re
Copy link

bluec0re commented Dec 18, 2023

Boiled it down to the aspect_bazel_lib dependency of rules_oci. The version used by default (1.35.0) fails, but everything works with 1.36.0 and higher.

Adding this to the WORKSPACE.bazel file to override the old dependency fixes it:

http_archive(
    name = "aspect_bazel_lib",
    sha256 = "cbf473d630ab67b36461d83b38fdc44e56f45b78d03c405e4958280211124d79",
    strip_prefix = "bazel-lib-1.36.0",
    url = "https://github.com/aspect-build/bazel-lib/releases/download/v1.36.0/bazel-lib-v1.36.0.tar.gz",
)

@alexeagle
Copy link
Collaborator

Here's that delta bazel-contrib/bazel-lib@v1.35.0...v1.36.0 - I would guess bazel-contrib/bazel-lib#594 is the one that fixed it.

@riking
Copy link

riking commented Dec 18, 2023

I'm getting a similar issue:

ERROR: /usr/local/google/home/kanepyork/.cache/bazel/_bazel_kanepyork/1e43355b350cd1d687555583f520a721/external/rules_oci~1.4.3~oci~distroless_static_linux_amd64_single/BUILD.bazel:16:18: Error while validating output TreeArtifact File:[[<execution_root>]bazel-out/k8-fastbuild/bin]external/rules_oci~1.4.3~oci~distroless_static_linux_amd64_single/blobs/sha256 : Failed to resolve relative path 30c679764948df7b86cfb4a09f8f5baf6243849fe96cd97ea700f8319803e941 inside TreeArtifact /usr/local/google/home/kanepyork/.cache/bazel/_bazel_kanepyork/1e43355b350cd1d687555583f520a721/execroot/_main/bazel-out/k8-fastbuild/bin/external/rules_oci~1.4.3~oci~distroless_static_linux_amd64_single/blobs/sha256. The associated file is either missing or is an invalid symlink.

The problem is a symlink pointing to the wrong place:

$ ls -l /usr/local/google/home/kanepyork/.cache/bazel/_bazel_kanepyork/1e43355b350cd1d687555583f520a721/execroot/_main/bazel-out/k8-fastbuild/bin/external/rules_oci~1.4.3~oci~distroless_static_linux_amd64_single/blobs/sha256
...
...
lrwxrwxrwx 2 kanepyork primarygroup    183 Dec 18 18:56 30c679764948df7b86cfb4a09f8f5baf6243849fe96cd97ea700f8319803e941 -> /tmp/bazel-execroot/_main/bazel-out/k8-fastbuild/bin/external/rules_oci~1.4.3~oci~distroless_static_linux_amd64_single/30c679764948df7b86cfb4a09f8f5baf6243849fe96cd97ea700f8319803e941
...
...
# correct destination of the symlink
$ ls -l /usr/local/google/home/kanepyork/.cache/bazel/_bazel_kanepyork/1e43355b350cd1d687555583f520a721/execroot/_main/bazel-out/k8-fastbuild/bin/external/rules_oci~1.4.3~oci~distroless_static_linux_amd64_single/
total 20
-r-xr-xr-x 1 kanepyork primarygroup 1645 Dec 18 18:56 30c679764948df7b86cfb4a09f8f5baf6243849fe96cd97ea700f8319803e941
drwxr-xr-x 3 kanepyork primarygroup 4096 Dec 18 18:56 blobs
-r-xr-xr-x 1 kanepyork primarygroup 6221 Dec 18 18:56 blobs_config.json
-r-xr-xr-x 1 kanepyork primarygroup 1551 Dec 18 18:56 distroless_static_linux_amd64_single_config.json

In particular, /tmp/bazel-execroot/_main/ does not exist.

@riking
Copy link

riking commented Dec 18, 2023

Yes, the 1.36.0 upgrade solves the issue. bazel_dep(name = "aspect_bazel_lib", version = "1.36.0")

alexeagle added a commit that referenced this issue Dec 22, 2023
Pick up the change to execution requirements.
Fixes #425
alexeagle added a commit that referenced this issue Dec 22, 2023
Pick up the change to execution requirements.
Fixes #425
alexeagle added a commit that referenced this issue Jan 12, 2024
Pick up the change to execution requirements.
Fixes #425
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need: investigation A potential issue which we need to investigate first
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants