bazel-contrib / rules_oci

Bazel rules for building OCI containers
Apache License 2.0
302 stars 158 forks source link

[v2.0.0-alpha2] Fail to use the platform transition group and the filegroup to get the tarball #607

Closed aignas closed 5 months ago

aignas commented 5 months ago

With the following MODULE.bazel:

module(name = "repro")

bazel_dep(name = "rules_oci", version = "2.0.0-alpha2")
bazel_dep(name = "aspect_bazel_lib", version = "2.7.7")

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

# Declare external images you need to pull, for example:
oci.pull(
    name = "alpine",
    digest = "sha256:c5b1261d6d3e43071626931fc004f70149baeba2c8ec672bd4f27761f8e1ad6b",
    image = "alpine",
    platforms = [
        "linux/386",
        "linux/amd64",
        "linux/arm/v6",
        "linux/arm/v7",
        "linux/arm64/v8",
        "linux/ppc64le",
        "linux/s390x",
    ],
)
use_repo(oci, "alpine")

And a BUILD.bazel:

load("@aspect_bazel_lib//lib:transitions.bzl", "platform_transition_filegroup")
load("@rules_oci//oci:defs.bzl", "oci_tarball")

platform(
    name = "linux_x86_64",
    constraint_values = [
        "@platforms//os:linux",
        "@platforms//cpu:x86_64",
    ],
)

platform_transition_filegroup(
    name = "transitioned",
    srcs = ["@alpine"],
    target_platform = "//:linux_x86_64",
)

oci_tarball(
    name = "tarball",
    image = "transitioned",
    repo_tags = ["rules_oci_repro_alpine"],
)

filegroup(
    name = "tarball_filegroup",
    srcs = [":tarball"],
    output_group = "tarball",
)

The building of tarball_filegroup will fail with:

$ bazel build :tarball_filegroup
INFO: Analyzed target //:tarball_filegroup (82 packages loaded, 788 targets configured).
ERROR: /Users/ignas.anikevicius/src/github/aignas/rules_oci_2_alpha_tarball_repro/BUILD.bazel:18:12: OCITarball tarball/tarball.tar failed: (Exit 1): tar failed: error executing OCITarball command (from target //:tarball) external/aspect_bazel_lib~~toolchains~bsd_tar_darwin_amd64/tar --create --no-xattr --no-mac-metadata --cd bazel-out/darwin_x86_64-fastbuild/bin --file ... (remaining 2 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
tar: Error reading archive ../../../bazel-out/darwin_x86_64-fastbuild/bin/tarball/tarball.spec: Can't open bazel-out/darwin_x86_64-fastbuild-ST-a5417e5bb688/bin/external/rules_oci~~oci~alpine_linux_amd64/layout/blobs/sha256/05455a08881ea9cf0e752bc48e61bbd71a34c029bb13df01e40e3e70e0d007bd
tar: Error exit delayed from previous errors.
Target //:tarball_filegroup failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 9.920s, Critical Path: 1.19s
INFO: 8 processes: 6 internal, 1 darwin-sandbox, 1 local.
ERROR: Build did NOT complete successfully

I have a small repro: https://github.com/aignas/rules_oci_2_alpha_tarball_repro

It seems that the tarball.spec has non-transitioned paths and thus it is failing to build a tar file. Is there something that I have missed here? How would I create a tarball of an image for a particular platform when it is not equal to the host platform? I don't see any mention of it in #548.

thesayyn commented 5 months ago

This will be fixed by https://github.com/bazel-contrib/rules_oci/pull/614

thesayyn commented 5 months ago

fixed by https://github.com/bazel-contrib/rules_oci/pull/614