Hello! This concerns one of <@U04468GC7ED>’s nice ...
# general
b
Hello! This concerns one of @gorgeous-winter-99296’s nice plugins for building OCI images. I’m trying to do something like this:
Copy code
oci_pull_images(
    name="python",
    repository="docker.io/library/python",
    variants=
        {
            "3.11.10-slim": "459ee2a00675825a5cf39a34d0c4a3f7cb994c76b647c88c1605ed9aca05b97e",
        },
    architecture="amd64",
    os="linux",
)

python_requirements(
    name="lib",
    source="pyproject.toml",
)

file(name="start", source="start.sh")

pex_binary(
    name="pex",
    dependencies=[":lib"],
    execution_mode="venv",
    output_path="pex.pex",
)

oci_layer(
    name="layer",
    packages=[":pex"],
)

oci_image_build(
    name="image",
    base=[":python#3.11.10-slim"],
    repository=(repo)
    tag="latest",
    entrypoint="./start.sh",
    layers=[":layer", ":start"],
)
where
start.sh
simply contains
Copy code
#!/bin/bash

./pex.pex -m "$@"
But I get this error when trying to
pants package (path):image
Copy code
/Users/[me]/.cache/pants/named_caches/pex_root/venvs/s/66d63bf8/venv/lib/python3.9/site-packages/pants_backend_oci/util_rules/layer.py", line 153, in build_image_layer
    raw_layer_digest, layer_name = real_layers[0]
IndexError: list index out of range
The end goal is to get an image that can accept some arguments like
python_module_name arg1 arg2 ...
, which in reality would be like doing
./pex.pex -m python_module_name arg1 arg2 ...
, or the like. Am I approaching the problem the wrong way? Super grateful for any help 🙏
g
Don't have time to repro right now, but I have an inkling one of your layers ends up empty. Are you on the latest version? Also, stupid test but can you convert the file to a resource?
b
Latest version:
pants-backend-oci==0.7.0
Yes, turning it to a resource results in the same error.
Doing something intermediary results in no error code, but no file to be found.
Copy code
file(name="start_file", source="start.sh")
...
oci_layer(
    name="start",
    packages=[":start_file"],
)
...
g
I guess it prints out "Did not build any files" for both layers, as well?
1
Ok; weird. It looks like it should be picked up, I'll take a quick peek.
🙏 1
Ah dumb stuff. Change the
file
to
files
, that seems to work when I repro it.
b
No luck for me! Did you do with or without the additional
oci_layer
with only the file?
g
Oh yeah the layer is definitely needed! Yes
b
This feels unrelated but I’m getting the strangest error now when I package it, tar it and then try to build it. (I can’t do
pants run (path):image
because I’m on Mac). This has never happened before 😄
Copy code
podman build -f image.tar                                                                  
Error: no FROM statement found
g
Wait, is that supposed to work?
Copy code
podman run oci:dist/examples.oci.file/image.d
That's the method I'd suggest if possible.
(are you mixing it with
podman load
or
podman import
? But I've never seen those used with
-f
either... You can podman pull or run the oci dir directly, or you can tar it and load/import...)
(Interestingly, I now cannot repro the issue with
file
... will have to investigate more. I'm wondering if changing the type of
start
led to some weird cache mismatch.)
b
I was able to find another solution that didn’t rely on placing a file in a layer. Instead, I used
makeself_archive
to do exactly what I wanted, and then created an
oci_layer
out of that. Basically did what is stated here: https://www.pantsbuild.org/stable/docs/shell/self-extractable-archives#bundling-packages-like-pex_binary
Thanks for the help anyway, Tom! And yes, it does work to run images that way!
podman run oci:dist/examples.oci.file/image.d
doesn’t work for me at all 😞
g
Interesting. Will have to try that, never seen that in the documentation. Which version of podman are you using?
b
v5.2.1