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

fix: #120 (and #115?) in MacOS #136

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jjmaestro
Copy link
Contributor

@jjmaestro jjmaestro commented Dec 11, 2024

fix: #120 (and #115?) in MacOS

Bazel was throwing an error when running the tests in MacOS even when the Linux tests were guarded with a target_compatible_with that was restricted to Linux.

As far as I could tell, this was because running bazel test with //... was recursively evaluating other targets like //examples/ubuntu_snapshot:_noble_index_json from oci_image and oci_load. When I guard those rules with a target_compatible_with everything works.

Also, seeing that e5f7dc0 also manually commented a test to fix CI for macos so I guess #120 didn't break this, it was probably happening since #115 added the new convenience targets.

Finally, maybe this is something that should be fixed in rules_oci, the "inner targets" that it creates should probably be restricted to only run in the os and architecture given for the image :-?

@jjmaestro
Copy link
Contributor Author

@thesayyn here's the fix!

BTW do you think it would be worth it to let the checks run without needing a review? I think it would make it easier to see if everything is green much faster, without having to bother you with it :-?

@thesayyn
Copy link
Collaborator

Hmm, i don't think is what we want, either a transition or disabling those tests on macos.

@jjmaestro
Copy link
Contributor Author

@thesayyn but I thought the tests that fail were already guarded, as I mentioned in some checks I ran here.

What am I missing? :-? If I'm understanding correctly what's going on, the tests are already guarded by the target_compatible_with so they are SKIPPED, but somehow, the code in the repos is being evaluated.

I'm too much of a Bazel n00b, if you can explain it further, I'm happy to check and change "the fix". I agree it definitely looks bad, because it's adding a default state that shouldn't be there, that code should never be executed in the first place, agreed.

@thesayyn
Copy link
Collaborator

BTW do you think it would be worth it to let the checks run without needing a review

Sorry can’t do that, it’s against the security rules set in place, plus I don’t have permissions to do that.

@thesayyn
Copy link
Collaborator

Weird, I’ll check later

@jjmaestro
Copy link
Contributor Author

Yeah, I've checked again, if I remove

% git diff examples/ubuntu_snapshot/BUILD.bazel
diff --git a/examples/ubuntu_snapshot/BUILD.bazel b/examples/ubuntu_snapshot/BUILD.bazel
index 2cb6a91..9856501 100644
--- a/examples/ubuntu_snapshot/BUILD.bazel
+++ b/examples/ubuntu_snapshot/BUILD.bazel
@@ -75,10 +75,4 @@ container_structure_test(
         "@platforms//cpu:x86_64": ["test_linux_amd64.yaml"],
     }),
     image = ":noble",
-    target_compatible_with = select({
-        "@platforms//cpu:x86_64": ["@platforms//cpu:x86_64"],
-        "@platforms//cpu:arm64": ["@platforms//cpu:arm64"],
-    }) + [
-        "@platforms//os:linux",
-    ],
 )

And I run it manually with bazel test //examples/ubuntu_snapshot:test now I do get the failure. But with the target_compatible_with in place, Bazel stops with:

% bazel test //examples/ubuntu_snapshot:test   
WARNING: Ignoring JAVA_HOME, because it must point to a JDK, not a JRE.
Target //examples/ubuntu_snapshot:test failed to build
Use --verbose_failures to see the command lines of failed build steps.
ERROR: Analysis of target '//examples/ubuntu_snapshot:test' failed; build aborted: Target //examples/ubuntu_snapshot:test is incompatible and cannot be built, but was explicitly requested.
Dependency chain:
   //examples/ubuntu_snapshot:test (d0cdca)   <-- target platform (@@platforms//host:host) didn't satisfy constraint @@platforms//os:linux
INFO: Elapsed time: 0.110s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
ERROR: Build did NOT complete successfully
ERROR: No test targets were found, yet testing was requested

@jjmaestro
Copy link
Contributor Author

Weird, I’ll check later

Cool, thanks!!

@jjmaestro
Copy link
Contributor Author

Maybe what's happening is that bazel test //... is evaluating targets that are not tests but that fail / trigger the error when they run, e.g.

% bazel query 'kind(".*_test", //examples/ubuntu_snapshot/...)'
//examples/ubuntu_snapshot:test

% bazel query //examples/ubuntu_snapshot/...
//examples/ubuntu_snapshot:__group.mtree.tmpl
//examples/ubuntu_snapshot:__passwd.mtree.tmpl
//examples/ubuntu_snapshot:__sh.mtree.tmpl
//examples/ubuntu_snapshot:_group.mtree
//examples/ubuntu_snapshot:_noble_index_json
//examples/ubuntu_snapshot:_noble_index_json_cp
//examples/ubuntu_snapshot:_passwd.mtree
//examples/ubuntu_snapshot:_sh.mtree
//examples/ubuntu_snapshot:_tarball_write_tags
//examples/ubuntu_snapshot:group
//examples/ubuntu_snapshot:group_content
//examples/ubuntu_snapshot:noble
//examples/ubuntu_snapshot:noble.digest
//examples/ubuntu_snapshot:passwd
//examples/ubuntu_snapshot:passwd_content
//examples/ubuntu_snapshot:sh
//examples/ubuntu_snapshot:tarball
//examples/ubuntu_snapshot:test
% bazel test //examples/ubuntu_snapshot:_noble_index_json
WARNING: Ignoring JAVA_HOME, because it must point to a JDK, not a JRE.
WARNING: /Users/jjmaestro/Work/BAZEL/rules_distroless/MODULE.bazel:59:20: The module extension apt defined in @rules_distroless//apt:extensions.bzl reported incorrect imports of repositories via use_repo():

Imported, but reported as indirect dependencies by the extension:
    arch_all_test_resolve, resolution_test_resolve

Fix the use_repo calls by running 'bazel mod tidy'.
ERROR: /private/var/tmp/_bazel_jjmaestro/be9c074a2171a3cb6c673d10113bd570/external/_main~apt~noble/BUILD.bazel:205:10: configurable attribute "srcs" in @@_main~apt~noble//:packages doesn't match this configuration. Would a default condition help?

Conditions checked:
 @@_main~apt~noble//:linux_amd64
 @@_main~apt~noble//:linux_arm64

To see a condition's definition, run: bazel query --output=build <condition label>.

This instance of @@_main~apt~noble//:packages has configuration identifier 69bb7f0. To inspect its configuration, run: bazel config 69bb7f0.

For more help, see https://bazel.build/docs/configurable-attributes#faq-select-choose-condition.

ERROR: Analysis of target '//examples/ubuntu_snapshot:_noble_index_json' failed; build aborted: Analysis failed
INFO: Elapsed time: 0.190s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
ERROR: Build did NOT complete successfully
ERROR: No test targets were found, yet testing was requested

That is, the test target is actually not even running because of the target_compatible_with but the other targets in //... are somehow being evaluated to some extent and failing.

@jjmaestro
Copy link
Contributor Author

Yup, that's it!!! If I add a target_compatible_with to oci_image and oci_load then everything works! :D Gonna make the changes now, let me know what you think.

@jjmaestro
Copy link
Contributor Author

Ah! I see you disabled oci_load for examples/debian_snapshot in e5f7dc0! I guess this is probably why? 😅 OK, going to fix it for both Debian and Ubuntu tests then!

Bazel was throwing an error when running the tests in MacOS even when
the Linux tests were guarded with a target_compatible_with that was
restricted to Linux.

As far as I could tell, this was because running the bazel test with
//... was recursively evaluating other targets like
//examples/ubuntu_snapshot:_noble_index_json from oci_image and
oci_load. When I guard those rules with a target_compatible_with
everything works.

See GoogleContainerTools#136
for more context and information.

Also, seeing that e5f7dc0 also manually commented a test to fix CI
for macos so I guess GoogleContainerTools#120 didn't break this, it was probably happening
since GoogleContainerTools#115 added the new convenience targets.

Finally, maybe this is something that should be fixed in rules_oci, the
"inner targets" that it creates should probably be restricted to only
run in the `os` and `architecture` given for the image :-?
@jjmaestro
Copy link
Contributor Author

Yup! This seems to fix it :)

% bazel test //examples/... --cache_test_results=no            
INFO: Analyzed 125 targets (0 packages loaded, 0 targets configured).
INFO: Found 106 targets and 19 test targets...
INFO: Elapsed time: 0.384s, Critical Path: 0.21s
INFO: 18 processes: 34 darwin-sandbox.
INFO: Build completed successfully, 18 total actions
//examples/debian_snapshot:test                                         SKIPPED
//examples/ubuntu_snapshot:test                                         SKIPPED
//examples/cacerts:test_cacerts                                          PASSED in 0.1s
//examples/flatten:test_flatten                                          PASSED in 0.1s
//examples/flatten:test_flatten_dedup_listing                            PASSED in 0.1s
//examples/flatten:test_flatten_dedup_mtree                              PASSED in 0.1s
//examples/group:test_group                                              PASSED in 0.1s
//examples/group:test_group_content                                      PASSED in 0.1s
//examples/home:test_home                                                PASSED in 0.1s
//examples/java_keystore:test_java_keystore                              PASSED in 0.1s
//examples/java_keystore:test_java_keystore_jks                          PASSED in 0.1s
//examples/locale:test_bookworm                                          PASSED in 0.1s
//examples/locale:test_bullseye                                          PASSED in 0.1s
//examples/os_release:test_os_release                                    PASSED in 0.1s
//examples/os_release:test_os_release_alternative_path                   PASSED in 0.1s
//examples/os_release:test_os_release_content                            PASSED in 0.1s
//examples/passwd:test_passwd                                            PASSED in 0.1s
//examples/passwd:test_passwd_content                                    PASSED in 0.1s
//examples/statusd:test_statusd                                          PASSED in 0.1s

Executed 17 out of 19 tests: 17 tests pass and 2 were skipped.

@jjmaestro jjmaestro changed the title fix: #120 broke macos fix: #120 (and #115?) in MacOS Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants