Skip to content

Commit

Permalink
build(notifications-api): Switch to psycopg2
Browse files Browse the repository at this point in the history
The previously used "psycopg2-binary" has been used as a workaround initially,
because it was difficult to build psycopg2.

Now the usage with very recent PostgreSQL databases unveiled issues of the
binary package at least on aarch64 architectures.

Issue: #640
See-Also: psycopg/psycopg2#1360
  • Loading branch information
Johannes Bornhold authored and d3vv3 committed Nov 8, 2024
1 parent 3d41500 commit 09dc2e6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
32 changes: 27 additions & 5 deletions notifications-api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,36 @@ ARG WORKDIR=/app
ARG USER=fastapi
RUN useradd -m "$USER"
WORKDIR "$WORKDIR"
RUN chown "$USER":"$USER" "$WORKDIR" && \
mkdir -p /var/local/notifications-api && \
chown "$USER":"$USER" /var/local/notifications-api
RUN chown "$USER":"$USER" "$WORKDIR" \
&& mkdir -p /var/local/notifications-api \
&& chown "$USER":"$USER" /var/local/notifications-api \
&& apt-get -qq update \
&& apt-get --assume-yes --verbose-versions --no-install-recommends install \
libpq5=13.* \
&& rm -fr /var/lib/apt/lists/* /var/cache/apt/archives/*
USER "$USER"
ENV PATH="/home/${USER}/.local/bin:${PATH}"
ENV PYTHONPATH="."
ENV WEB_CONCURRENCY=1


FROM base as builder
USER root
RUN apt-get -qq update \
&& apt-get --assume-yes --verbose-versions --no-install-recommends install \
libpq-dev=13.* \
build-essential=12.* \
gcc=4:10.* \
&& rm -fr /var/lib/apt/lists/* /var/cache/apt/archives/*
USER "$USER"
COPY ./requirements.txt .
RUN pip wheel --no-cache-dir --wheel-dir=./wheels -c requirements.txt psycopg2


FROM base as test
COPY ./requirements-dev.txt .
RUN pip install --no-cache-dir -r requirements-dev.txt
COPY --from=builder /app/wheels ./wheels
RUN pip install --no-cache-dir --find-links=./wheels -r requirements-dev.txt
CMD ["pytest"]


Expand All @@ -31,7 +49,11 @@ FROM base as final
ENV PYTHONPATH="$WORKDIR"

COPY ./requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# TODO: RUN --mount is not yet supported in kaniko,
# See https://github.com/GoogleContainerTools/kaniko/issues/1568
# RUN --mount=type=bind,from=builder,source=/app/wheels,target=/app/wheels \
COPY --from=builder /app/wheels ./wheels
RUN pip install --no-cache-dir --find-links=./wheels -r requirements.txt

COPY ./ ./
EXPOSE 8080
Expand Down
2 changes: 1 addition & 1 deletion notifications-api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dependencies = [
'pydantic >= 1.10.2',
'sse-starlette >= 1.2.1',
# TODO: Replace with psycopg2
'psycopg2-binary',
'psycopg2',
'pyzmq',
]

Expand Down
2 changes: 1 addition & 1 deletion notifications-api/requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pexpect==4.8.0
pickleshare==0.7.5
pluggy==1.0.0
prompt-toolkit==3.0.36
psycopg2-binary==2.9.5
psycopg2==2.9.5
ptyprocess==0.7.0
pure-eval==0.2.2
pydantic==1.10.4
Expand Down
2 changes: 1 addition & 1 deletion notifications-api/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ httptools==0.5.0
idna==3.4
Mako==1.2.4
MarkupSafe==2.1.1
psycopg2-binary==2.9.5
pydantic==1.10.4
pydash==5.1.2
python-dotenv==0.21.0
psycopg2==2.9.5
PyYAML==6.0
pyzmq==24.0.1
sniffio==1.3.0
Expand Down

0 comments on commit 09dc2e6

Please sign in to comment.