Docker build failing -
jithin77 opened this issue · 1 comments
System Info
Latest code from repo
🐛 Describe the bug
RUN poetry install --no-root
Installing dependencies from lock file
Package operations: 81 installs, 1 update, 0 removals
- Installing idna (3.7)
- Installing sniffio (1.3.1)
- Installing anyio (4.4.0)
- Installing certifi (2024.7.4)
- Installing h11 (0.14.0)
- Installing httpcore (0.16.3)
- Installing numpy (1.26.4)
- Installing rfc3986 (1.5.0)
- Installing six (1.16.0)
- Installing typing-extensions (4.12.2)
- Installing charset-normalizer (3.3.2)
- Installing contourpy (1.2.1)
- Installing cycler (0.12.1)
- Installing fonttools (4.53.1)
- Installing distro (1.9.0)
- Installing httpx (0.23.3)
- Installing kiwisolver (1.4.5)
- Installing markupsafe (2.1.5)
- Installing greenlet (3.0.3)
- Installing iniconfig (2.0.0)
- Installing packaging (24.1)
- Installing parse (1.20.2)
- Installing pillow (10.4.0)
- Installing pluggy (1.5.0)
- Installing pyasn1 (0.6.0)
- Installing pycparser (2.22)
- Installing pydantic (1.10.17)
- Installing pyparsing (3.1.2)
- Installing python-dateutil (2.9.0.post0)
- Installing pytz (2024.1)
- Installing sqlglotrs (0.2.8)
- Installing starlette (0.25.0)
- Installing tqdm (4.66.4)
- Installing urllib3 (2.2.2)
- Installing astor (0.8.1)
- Installing astroid (3.2.2)
- Installing async-timeout (4.0.3)
- Installing cffi (1.16.0)
- Installing click (8.1.7)
- Installing dnspython (2.6.1)
- Installing duckdb (0.10.3)
- Installing faker (19.13.0)
- Installing isort (5.13.2)
- Installing ecdsa (0.19.0)
- Installing dill (0.3.8)
- Installing fastapi (0.92.0)
- Installing jinja2 (3.1.4)
- Installing mako (1.3.5)
- Installing matplotlib (3.9.1)
- Installing mccabe (0.7.0)
- Installing mypy-extensions (1.0.0)
- Installing openai (1.35.12)
- Installing pandas (1.5.3)
- Installing parse-type (0.6.2)
- Installing pathspec (0.12.1)
- Installing platformdirs (4.2.2)
- Installing pytest (7.4.4)
- Installing python-dotenv (1.0.1)
- Installing requests (2.32.3)
- Installing rsa (4.9)
- Installing scipy (1.14.0)
- Updating setuptools (70.1.0 -> 70.3.0)
- Installing sqlalchemy (2.0.31)
- Installing sqlglot (25.5.1)
- Installing tomlkit (0.12.5)
- Installing alembic (1.13.2)
- Installing asyncpg (0.29.0)
- Installing bcrypt (3.1.7)
- Installing black (23.12.1)
- Installing behave (1.2.6)
- Installing fastapi-event (0.1.3)
- Installing email-validator (1.3.1)
- Installing passlib (1.7.4)
- Installing gunicorn (20.1.0)
- Installing pandasai (2.2.10)
- Installing pylint (3.2.5)
- Installing psycopg2 (2.9.9)
- Installing pytest-asyncio (0.20.3)
- Installing python-jose (3.3.0)
- Installing python-multipart (0.0.9)
- Installing pyyaml (6.0.1)
- Installing uvicorn (0.20.0)
ChefBuildError
Backend subprocess exited when trying to invoke get_requires_for_build_wheel
running egg_info
writing psycopg2.egg-info/PKG-INFO
writing dependency_links to psycopg2.egg-info/dependency_links.txt
writing top-level names to psycopg2.egg-info/top_level.txt
Error: pg_config executable not found.
pg_config is required to build psycopg2 from source. Please add the directory
containing pg_config to the $PATH or specify the full executable path with the
option:
python setup.py build_ext --pg-config /path/to/pg_config build ...
or with the pg_config option in 'setup.cfg'.
If you prefer to avoid building psycopg2 from source, please install the PyPI
'psycopg2-binary' package instead.
For further information please check the 'doc/src/install.rst' file (also at
https://www.psycopg.org/docs/install.html).
at ~/.local/share/pypoetry/venv/lib/python3.11/site-packages/poetry/installation/chef.py:164 in _prepare
160�
161� error = ChefBuildError("\n\n".join(message_parts))
162�
163� if error is not None:
� 164� raise error from None
165�
166� return path
167�
168� def _prepare_sdist(self, archive: Path, destination: Path | None = None) -> Path:
Note: This error originates from the build backend, and is likely not a problem with poetry but with psycopg2 (2.9.9) not supporting PEP 517 builds. You can verify this by running 'pip wheel --no-cache-dir --use-pep517 "psycopg2 (==2.9.9)"'.
To resolve the issue with the Docker build process failing during the RUN poetry install --no-root
step due to the pg_config
executable not being found when trying to install psycopg2
, you need to install the libpq-dev
package, which provides the pg_config
executable.
You can modify your Dockerfile to include the installation of libpq-dev
as follows:
# Use an official Python runtime as a parent image
FROM python:3.11-slim
# Set the working directory in the container
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
curl \
make \
libpq-dev \ # Add this line to install libpq-dev
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Install Poetry
RUN curl -sSL https://install.python-poetry.org | python3 -
RUN apt-get update && apt-get install netcat-openbsd -y
# Add Poetry to PATH
ENV PATH="/root/.local/bin:$PATH"
# Copy the current directory contents into the container at /app
COPY . /app
RUN poetry lock --no-update
# Install Python dependencies
RUN poetry install --no-root
# Add wait-for-it.sh script to the container
COPY wait-for-it.sh /wait-for-it.sh
RUN chmod +x /wait-for-it.sh
# Make port 8000 available to the world outside this container
EXPOSE 8000
# Copy entrypoint script to the container
COPY startup.sh /startup.sh
RUN chmod +x /startup.sh
# RUN dos2unix startup.sh
# Run the entrypoint script
CMD ["/startup.sh"]
By adding libpq-dev
to the list of system dependencies, the pg_config
executable will be available, and the psycopg2
installation should proceed without issues [1].