Good monday everyone! Small question maybe not re...
# general
c
Good monday everyone! Small question maybe not related directly to pants but this is a first for me to use Pex and I am having an hard time to make it works with Docker, Poetry and Gunicorn for a Flask application. My Services are Flask App but I need
gunicorn gevent psycogreen
as requirements from poetry only when building my Docker Image. Currently I have added them in another poetry group which appear to include the dependencies when building the Docker image but I can't make it work with the
pex_binary
target, tested to specify the
entry_point
or the
script
in
pex_binary
but I keep getting error message. Currently my build look like this
Copy code
python_sources()

poetry_requirements(
    name="poetry"
)

pex_binary(
    name = "binary",
    entry_point = "run.py",
    layout = "packed",
    execution_mode = "venv",
)

docker_image(
    name = "img",
    registries = ["<http://docker.io|docker.io>"],
    repository = "repo/service",
    image_tags = ["{build_args.RELEASE_VERSION}"]
)
My Dockerfile looks like this
Copy code
FROM python:3.10-slim
ARG RELEASE_VERSION=latest

RUN apt-get update \
  && apt-get install -y --no-install-recommends \
    python3-dev \
    libpq-dev \
  && apt-get clean autoclean \
  && apt-get autoremove -y \
  && rm -rf /var/lib/apt/lists/* \
  && rm -f /var/cache/apt/archives/*.deb \

COPY src.services.service/binary.pex /bin/app

ENV CONSUL [h=consul-svc,t=None]
EXPOSE 5001

CMD ["python", "/bin/app"]
This is working for development purpose, but we need
gunicorn
in production I was reading this https://pex.readthedocs.io/en/v2.1.43/recipes.html#gunicorn-and-pex but I don't see how I can reproduce this through Pants! Thanks 🙂
a
I doubt this will be the entire solution but, at first glance, I wonder if you need to include dependencies in your
pex_binary
target?
Copy code
pex_binary(
    name = "binary",
    dependencies=[":poetry"],
    entry_point = "run.py",
    layout = "packed",
    execution_mode = "venv",
)
I am not familiar with Gunicorn and Flask but this seems logical to me if the poetry config references the required dependencies. You may have to adjust the entry point according to the pex reference you included.
c
I have successfully made it runs with
Copy code
pex_binary(
    name="binary-deps",
    entry_point = "gunicorn",
    dependencies = ["src/services/service","src/services/service:poetry#gevent", "src/services/service:poetry#psycogreen"],
    layout="packed",
    include_sources=False,
    include_tools=True,
)
👍🏽 1
for a weird reason, it does not include all the dep correctly for poetry, but this does the trick
¯\_(ツ)_/¯