Build psycopg with dependencies in solo stage #9

Merged
JustScreaMy merged 2 commits from multistage-postgresql into master 2025-02-27 11:42:40 +01:00
2 changed files with 22 additions and 10 deletions
Showing only changes of commit aeae05d5c0 - Show all commits

View file

@ -2,7 +2,7 @@ ARG PYTHON_VERSION=3.13
ARG CODENAME=bookworm
ARG UV_PROJECT_ENVIRONMENT=/home/runner/.venv
FROM python:${PYTHON_VERSION}-slim-${CODENAME} AS base
FROM python:${PYTHON_VERSION}-slim-${CODENAME} AS runtime
ARG POSTGRES_VERSION=17
ARG CODENAME
@ -14,10 +14,8 @@ ENV PYTHONUNBUFFERED=1 \
RUN : \
&& apt-get update \
&& apt-get install -y \
build-essential \
gnupg \
wget \
# git \
gettext \
&& rm -rf /var/lib/apt/lists* \
&& :
@ -26,16 +24,27 @@ RUN : \
RUN : \
&& echo "deb https://apt.postgresql.org/pub/repos/apt ${CODENAME}-pgdg main" > /etc/apt/sources.list.d/pgdg.list \
&& wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
&& apt update \
&& apt install -y postgresql-client-${POSTGRESQL_VERSION} libpq-dev \
&& apt-get update \
&& apt-get install -y \
libpq-dev \
&& rm -rf /var/lib/apt/lists* \
&& :
RUN adduser --disabled-password runner
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/
FROM base AS deps
FROM runtime AS deps
RUN adduser --disabled-password runner
ARG POSTGRES_VERSION
RUN : \
&& apt-get update \
&& apt-get install -y \
build-essential \
postgresql-client-${POSTGRESQL_VERSION} \
&& rm -rf /var/lib/apt/lists* \
&& :
USER runner
@ -69,7 +78,7 @@ USER runner
CMD [ "/app/scripts/run-dev.sh" ]
FROM python:${PYTHON_VERSION}-slim-${CODENAME} AS release
FROM runtime AS release
ARG UV_PROJECT_ENVIRONMENT
ENV UV_PROJECT_ENVIRONMENT=${UV_PROJECT_ENVIRONMENT}
@ -80,4 +89,6 @@ WORKDIR /app
COPY --chown=runner:runner ./ ./
COPY --from=deps --chown=runner:runner ${UV_PROJECT_ENVIRONMENT} ${UV_PROJECT_ENVIRONMENT}
USER runner
CMD [ "/app/scripts/run.sh" ]

View file

@ -11,11 +11,12 @@ echo "Compiling messages..."
echo "Migrating..."
./manage.py migrate --no-input
echo "Checking for errors..."
./manage.py check --deploy --fail-level WARNING
#echo "Checking for errors..."
#./manage.py check --deploy --fail-level WARNING
uvicorn \
--host 0.0.0.0 \
--port 8000 \
--workers 4 \
--lifespan off \
facturio.asgi:application