billowy-cat-69904
05/25/2024, 2:53 PM.venv
and shared dependencies between projects (multiple venvs per project) and also building images per project (multiple Dockerfile
(s) per project)? Does anyone has a complete example that they could share?billowy-cat-69904
05/25/2024, 2:54 PMpants package prj/projectA/Dockerfile
seems to not copy the entire context directorysquare-psychiatrist-19087
05/25/2024, 4:11 PMbillowy-cat-69904
05/25/2024, 4:21 PMhunch/projects/followed_users_post
├── BUILD
├── Dockerfile
├── __init__.py
├── requirements.txt
└── src
├── BUILD
├── __init__.py
├── forecast.py
└── preprocessing.py
and my build file is like this
python_sources(name="src", dependencies=["hunch/libs:libs"])
python_requirements(
name="reqs",
)
docker_image(
name="docker",
context_root="./",
source="Dockerfile",
dependencies=["hunch/projects/followed_users_post:src", "hunch/libs:libs"]
)
when I do pants package hunch/projects/followed_users_post
, it complains that requirements.txt
doesn't exist with the error
The following files were not found in the Docker build context:
* requirements.txt
My dockerfile is simply
FROM python:3.11.9-slim as base
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV PIP_NO_CACHE_DIR=off
ENV PIP_DISABLE_PIP_VERSION_CHECK=on
ENV PIP_DEFAULT_TIMEOUT=100
RUN pip install --no-cache-dir --upgrade pip
COPY requirements.txt /app/requirements.txt
RUN pip install --no-cache-dir -r /app/requirements.txt
I am not sure, what I am doing wrong? I have mentioned the dependencies in the docker image target but still it complains file doesn't existbillowy-cat-69904
05/25/2024, 4:33 PMfiles(name='libs', sources=['requirements.txt'])
, and mention this as a dependency in docker image along with others, it only copies to Dockerfile
and requirements.txt
to the directory. (I also add the following line in Dockerfile COPY . /app
billowy-cat-69904
05/25/2024, 4:37 PMfiles
to files(name='libs', sources=['requirements.txt', '**/*.py'])
it adds the python files too, to the image. Not sure if this is the right approach?square-psychiatrist-19087
05/25/2024, 4:57 PMsquare-psychiatrist-19087
05/25/2024, 4:58 PMbillowy-cat-69904
05/25/2024, 6:45 PMfrom libs.liba.pyfile import someClass
this works. With binaries also, this should work?square-psychiatrist-19087
05/25/2024, 6:48 PMbillowy-cat-69904
05/26/2024, 12:10 PMBUILD
file as follows:
python_sources(
dependencies=["hunch/libs"]
)
python_requirements(
name="reqs",
)
pex_binary(
name="fp_binary",
layout="loose",
execution_mode="venv",
dependencies=["hunch/libs:libs_binary"],
include_sources=True,
include_requirements=True,
include_tools=True,
venv_site_packages_copies=True
)
docker_image(
name="docker",
instructions=[
"FROM python:3.11.9-slim as deps",
"COPY hunch.libs/libs_binary.pex /libs_binary.pex",
"RUN PEX_TOOLS=1 /usr/local/bin/python /libs_binary.pex venv --scope=deps --compile /bin/app",
"FROM python:3.11.9-slim as srcs",
"COPY hunch.projects.followed_users_post/fp_binary.pex /fp_binary.pex",
"RUN PEX_TOOLS=1 /usr/local/bin/python /fp_binary.pex venv --scope=srcs --compile /bin/app",
"FROM python:3.11.9-slim",
"COPY --from=deps /bin/app /bin/app",
"COPY --from=srcs /bin/app /bin/app",
]
)
but when I run the docker image, it throws the ModuleNotFoundError with packages mentioned in my requirements.txt
. Also when I inspect fb_binary.pex
in dist/
folder, I don't see any source fiels or third party packages, just the build in librariessquare-psychiatrist-19087
05/26/2024, 3:15 PMbillowy-cat-69904
05/26/2024, 4:21 PMlibs_binary.pex
is in another place, i.e. I am creating it in separate build file. Should I create all the binary files of dependencies in same build file?square-psychiatrist-19087
05/26/2024, 4:26 PMbillowy-cat-69904
05/26/2024, 6:40 PMsquare-psychiatrist-19087
05/26/2024, 10:18 PMIs it required to set entry_point to pass in the files?
Pex binary is designed to behave like a binary. That means 1) it has to be built 2) the result of the built process is a single executable file Since the binary is executable, it has to run some code when executed, thus you have to specify an entrypoint to run it
square-psychiatrist-19087
05/26/2024, 10:21 PMcoming from poly repo background, I am used to creating pyproject.toml
If all your libraries are in the monorepo managed by pants, then no, you don't need to create any files other that BUILD files. When you build pex binaries, pants will look at the imports and automatically include all the imported code into your binary
square-psychiatrist-19087
05/27/2024, 12:35 PMsquare-psychiatrist-19087
05/27/2024, 12:53 PMsquare-psychiatrist-19087
05/27/2024, 12:54 PMroot_patterns
and pex_binary
billowy-cat-69904
05/28/2024, 5:50 PMbillowy-cat-69904
05/28/2024, 5:51 PMforecast.py
and wanted to see if all the dependencies (including 3rd party) are actually included in the pex binaries or not.billowy-cat-69904
05/28/2024, 5:57 PMrequirements.txt
file, pants warns that it couldn't correctly identify it's owner and then the dependency is not included in the pex binary. However if I remove the package and mention it only in one requirements.txt
then it is included in pex binary. I am using python-default
lock file.
What's the recommended way of adding 3rd party dependency, when that third party dependency is required by different projects?square-psychiatrist-19087
05/28/2024, 5:57 PMnow I am able to get it working in my main repo.I'm glad it's working, you're welcome!
square-psychiatrist-19087
05/28/2024, 5:58 PMWhat's the recommended way of adding 3rd party dependency, when that third party dependency is required by different projects?If you're using a single resolve, just create a single requirements.txt with all the dependencies
billowy-cat-69904
05/28/2024, 6:08 PMpandas==2.2.2
, after few months some other team member starts another project which is using the latest version of pandas (could be pandas=2.9.0
), I think the single lock file will throw an error then. In such scenarios, should I be creating separate lock files?square-psychiatrist-19087
05/28/2024, 6:09 PMsquare-psychiatrist-19087
05/28/2024, 6:10 PM# project 1
python_requirements(name="project2-reqs", resolve="project1")
# project 2
python_requirements(name="project1-reqs", resolve="project2")
square-psychiatrist-19087
05/28/2024, 6:11 PM