https://pantsbuild.org/ logo
#general
Title
# general
l

limited-insurance-37393

05/31/2022, 6:04 PM
I'm going to be building various docker images based on an entry point of a given module in a Python project, but I also need to build a pair of images that only rely on third party dependencies. I could just write a Dockerfile that does that, but I would prefer to rely on the poetry lock file in the repo, so I was going to try to have Pants handle that build as well. How do I tell it to install those third-party requirements? What I've got so far (doesn't do what I need yet) is this:
Copy code
docker_image(
    name="ol-dagster-daemon",
    dependencies=[
        "//:requirements#dagster",
        "//:requirements#dagster-postgres",
    ],
    instructions=[
        "FROM python:3.9-slim",
        "WORKDIR /opt",
        "COPY . .",
    ]
)
@curved-television-6568 you might know the answer to this one ^ (or @witty-crayon-22786)
🙂 1
w

witty-crayon-22786

05/31/2022, 7:23 PM
hey @limited-insurance-37393
l

limited-insurance-37393

05/31/2022, 7:26 PM
Greetings
w

witty-crayon-22786

05/31/2022, 7:26 PM
to put requirements in a docker container, you’ll need to choose a packaging format (most likely, that would be a
pex_binary
currently), and then make the package a direct dependency of the docker image. you might have been expecting that these deps would be installed in a virtualenv inside the image, perhaps? but currently, you’d need to package, and then extract into a virtualenv inside the image
l

limited-insurance-37393

05/31/2022, 7:27 PM
It doesn't need to be a virtualenv, I was just trying to think of how to re-use the version locks from the repository for pinning the dependencies in the image
👍 1
So, just to make sure I'm understanding the steps here, I would add a
pex_binary
target that relies on those third party dependencies and give it the entrypoint that I would use for the Docker execution?
1
h

hundreds-father-404

05/31/2022, 8:06 PM
yes, I believe so. Example project https://github.com/pantsbuild/example-docker
l

limited-insurance-37393

05/31/2022, 8:07 PM
👍 thanks
c

curved-television-6568

05/31/2022, 8:56 PM
Stu and Eric beat me to it :)
❤️ 1
6 Views