https://pantsbuild.org/ logo
r

rhythmic-glass-66959

07/27/2022, 1:36 PM
Hi, what is the syntax for copying a
python_distribution
(wheel) into a Dockerfile built by pants?
The doc says: ā€¢ The artifacts of any packageable targets are built, as if by running
./pants package
, and placed in the context using the artifact's
output_path
field. ā—¦ The
output_path
defaults to the scheme
<http://path.to|path.to>.directory/tgt_name.ext
, e.g.
src.python.helloworld/bin.pex
.
n

nutritious-minister-3808

07/27/2022, 1:44 PM
I believe the correct Dockerfile instruction would be
COPY <http://path.to|path.to>.directory/tgt_name.whl /opt/destination/directory
.
r

rhythmic-glass-66959

07/27/2022, 1:45 PM
In my package build file, my target is defined as follow:
Copy code
python_distribution(
    name="dist",
    provides=python_artifact(
        name="my_package",
        version="0.1.0",
    ),
)
COPY <http://src.python.my|src.python.my>_package/dist.whl /tmp
failed (file does not exist).
n

nutritious-minister-3808

07/27/2022, 1:47 PM
Sorry. For wheels it might be a little different. Maybe try
COPY <http://src.python.my|src.python.my>_package/my-package-0.1.0.whl /tmp
r

rhythmic-glass-66959

07/27/2022, 1:48 PM
Nope, still failing....
I tried a bunch of combinaisons, but none worked.
n

nutritious-minister-3808

07/27/2022, 1:51 PM
What's the output when you package the whl directly.
./pants package src/python:dist
And are you including
":dist"
as a dependency on the docker_image target?
r

rhythmic-glass-66959

07/27/2022, 1:52 PM
Yes
Copy code
docker_image(
    name="my_docker_image",
    dependencies=[
        ...
        "src/python/my_package:dist",
    ],
)
Copy code
./pants package src/python/my_package:dist
09:56:17.93 [INFO] Wrote dist/my_package-0.1.0-py3-none-any.whl
09:56:17.93 [INFO] Wrote dist/my_package-0.1.0.tar.gz
n

nutritious-minister-3808

07/27/2022, 1:59 PM
Ahh
COPY my_package-0.1.0-py3-none-any.whl /tmp
should do it
šŸ™Œ 1
Weird how wheels and sdists don't get put into the same path.to.directory patterns
ā— 2
r

rhythmic-glass-66959

07/27/2022, 2:00 PM
Thank you very much, it worked!
b

bitter-ability-32190

07/27/2022, 2:05 PM
@hundreds-father-404 here's another case we might consider adding
output_path
field to
python_distribution
.
r

rhythmic-glass-66959

07/27/2022, 2:05 PM
But yes, I agree with you. It's weird that
python_distribution
doesn't follow the documented scheme...
b

bitter-ability-32190

07/27/2022, 2:06 PM
FYI y'all two ways to help for the future: ā€¢ Use
./pants package ...
and inspect where it is located in the
dist
dir. That'll be reflected in the docker context ā€¢ Use
./pants --no-process-cleanup ...
and inspect the sandbox created for the
docker build
process
šŸ‘ 1
2 Views