aspect-build / aspect-build/bazel-examples

[Bug]: oci_python_image example does not copy correct prebuilt binaries

Open
#351 3 comments 2 reactions 0 assignees View on GitHub
bug help wanted need: investigation
Dominant language
Starlark
Stars
149
Forks
87
PR merge metrics
No merged PRs in 30d

Description

### What happened?

See https://github.com/aspect-build/bazel-examples/compare/main...chulkilee:bazel-examples:oci-py-target?expand=1

This is to show how the current oci_python_image example does not work when building on macos.

```sh
cd oci_python_image
bazel run //hello_world:tarball

docker run --rm gcr.io/oci_python_hello_world:latest
```

```
Traceback (most recent call last):
File "/hello_world/hello_world.runfiles/_main/hello_world/__main__.py", line 1, in
from hello_world.app import Cow
File "/hello_world/hello_world.runfiles/_main/hello_world/app.py", line 2, in
from pydantic import BaseModel
File "/hello_world/hello_world.runfiles/.hello_world.venv/lib/python3.9/site-packages/pydantic/__init__.py", line 404, in __getattr__
module = import_module(module_name, package=package)
File "/hello_world/hello_world.runfiles/rules_python~~python~python_3_9_aarch64-unknown-linux-gnu/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/hello_world/hello_world.runfiles/.hello_world.venv/lib/python3.9/site-packages/pydantic/main.py", line 27, in
import pydantic_core
File "/hello_world/hello_world.runfiles/.hello_world.venv/lib/python3.9/site-packages/pydantic_core/__init__.py", line 6, in
from ._pydantic_core import (
ModuleNotFoundError: No module named 'pydantic_core._pydantic_core'
```

This is because pydantic_core's prebuilt is copied from host (macos), not for target. See the following output having darwin, not linux.

```shell
docker run --rm gcr.io/oci_python_hello_world:latest ls /hello_world/hello_world.runfiles/rules_python~~pip~pip_39_pydantic_core/site-packages/pydantic_core/
```

Output:

```
__init__.py
_pydantic_core.cpython-39-darwin.so
_pydantic_core.pyi
core_schema.py
py.typed
```

Interestingly, it actually did use the right python

```shell
docker run --rm gcr.io/oci_python_hello_world:latest ls /hello_world/hello_world.runfiles
```

Output:

```
_main
aspect_rules_py~~py_tools~rules_py_tools.linux_arm64
bazel_tools
rules_python~~pip~pip_39_annotated_types
rules_python~~pip~pip_39_cowsay
rules_python~~pip~pip_39_pydantic
rules_python~~pip~pip_39_pydantic_core
rules_python~~pip~pip_39_typing_extensions
rules_python~~python~python_3_9_aarch64-unknown-linux-gnu
```

See `aarch64-unknown-linux-gnu` there.

### Version

Development (host) and target OS/architectures:

Output of `bazel --version`: 7.3.0

Version of the Aspect rules, or other relevant rules from your
`WORKSPACE` or `MODULE.bazel` file: did not change from oci_python_image

Language(s) and/or frameworks involved: python

### How to reproduce

```shell
See https://github.com/aspect-build/bazel-examples/compare/main...chulkilee:bazel-examples:oci-py-target?expand=1
```

### Any other information?

It doesn't fail the test since apparently tests are running on linux machine.

Contributor guide

Open the contributing guide

Research direction

The reproduction is in oci_python_image and uses the //hello_world:tarball target; start by reviewing the linked oci-py-target comparison and running the Bazel command on macOS. Verify that the resulting container contains the target Linux aarch64 pydantic_core binary and that docker run completes successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, python
Domain
build-system, devops
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.