Merge pull request 'Build psycopg with dependencies in solo stage' (#9) from multistage-postgresql into master

Reviewed-on: #9
This commit is contained in:
JustScreaMy 2025-02-27 11:42:39 +01:00
commit 08d25b42a8
7 changed files with 47 additions and 49 deletions

View file

@ -1,8 +1,11 @@
ARG PYTHON_VERSION=3.13
ARG CODENAME=bookworm
ARG UV_PROJECT_ENVIRONMENT=/home/runner/.venv
FROM python:${PYTHON_VERSION}-slim-${CODENAME} AS runtime
ARG POSTGRES_VERSION=17
FROM python:${PYTHON_VERSION}-slim AS base
ARG CODENAME
ENV PYTHONUNBUFFERED=1 \
PIP_DISABLE_PIP_VERSION_CHECK=on \
@ -11,35 +14,45 @@ ENV PYTHONUNBUFFERED=1 \
RUN : \
&& apt-get update \
&& apt-get install -y \
build-essential \
openssh-client \
gnupg \
wget \
lsb-release \
git \
gettext \
&& rm -rf /var/lib/apt/lists* \
&& :
RUN : \
&& echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list \
&& 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
WORKDIR /app
ENV UV_PROJECT_ENVIRONMENT=/home/runner/.venv \
ARG UV_PROJECT_ENVIRONMENT
ENV UV_PROJECT_ENVIRONMENT=${UV_PROJECT_ENVIRONMENT} \
UV_PYTHON_DOWNLOADS=never
RUN --mount=type=bind,target=/app,source=. \
@ -65,11 +78,17 @@ USER runner
CMD [ "/app/scripts/run-dev.sh" ]
FROM deps AS release
FROM runtime AS release
ARG UV_PROJECT_ENVIRONMENT
ENV UV_PROJECT_ENVIRONMENT=${UV_PROJECT_ENVIRONMENT}
ENV PATH=${UV_PROJECT_ENVIRONMENT}/bin:${PATH}
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

@ -4,4 +4,5 @@ services:
context: .
args:
- POSTGRES_VERSION=17
- PYTHON_VERSION=3.13
target: release

View file

@ -15,7 +15,7 @@ services:
backend:
build:
target: dev
target: release
extends:
file: docker-compose.build.yml
service: backend

View file

@ -10,7 +10,7 @@ dependencies = [
"django>=5.1.6",
"django-crispy-forms>=2.3",
"django-environ>=0.12.0",
"psycopg[binary]>=3.2.5",
"psycopg[c]>=3.2.5",
"uvicorn[standard]>=0.34.0",
"wait-for-it>=2.3.0",
]

View file

@ -7,8 +7,8 @@ set -o pipefail
wait-for-it \
--quiet \
--service ${DATABASE_HOST}:${DATABASE_PORT:-5432} \
--service ${DATABASE_HOST:-postgres}:${DATABASE_PORT:-5432} \
--timeout 60 \
-- echo "db is up"
-- echo "Database is running"
exec "$@";

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

35
uv.lock
View file

@ -178,7 +178,7 @@ dependencies = [
{ name = "django" },
{ name = "django-crispy-forms" },
{ name = "django-environ" },
{ name = "psycopg", extra = ["binary"] },
{ name = "psycopg", extra = ["c"] },
{ name = "uvicorn", extra = ["standard"] },
{ name = "wait-for-it" },
]
@ -195,7 +195,7 @@ requires-dist = [
{ name = "django", specifier = ">=5.1.6" },
{ name = "django-crispy-forms", specifier = ">=2.3" },
{ name = "django-environ", specifier = ">=0.12.0" },
{ name = "psycopg", extras = ["binary"], specifier = ">=3.2.5" },
{ name = "psycopg", extras = ["c"], specifier = ">=3.2.5" },
{ name = "uvicorn", extras = ["standard"], specifier = ">=0.34.0" },
{ name = "wait-for-it", specifier = ">=2.3.0" },
]
@ -309,38 +309,15 @@ wheels = [
]
[package.optional-dependencies]
binary = [
{ name = "psycopg-binary", marker = "implementation_name != 'pypy'" },
c = [
{ name = "psycopg-c", marker = "implementation_name != 'pypy'" },
]
[[package]]
name = "psycopg-binary"
name = "psycopg-c"
version = "3.2.5"
source = { registry = "https://pypi.org/simple" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/84/eb/175a81bfd26734eeaaa39b651bc44a3c5e3fce1190963ace21e428c4d2ee/psycopg_binary-3.2.5-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:a4321ee8180982d70458d3e8378e31448901bf0ee40fe0d410a87413578f4098", size = 3857964 },
{ url = "https://files.pythonhosted.org/packages/ca/2e/0d57047372c3dd31becc1a48185862d7e6714ffbdc1401742a32f2294f79/psycopg_binary-3.2.5-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:2cc86657c05e09c701e97f87132cd58e0d55381dd568520081ac1fe7580a9bbb", size = 3940056 },
{ url = "https://files.pythonhosted.org/packages/c5/2f/339a18b28787d33fe892d1ae1fbaa83739c6274327cbf9ada4158322ad9d/psycopg_binary-3.2.5-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5244bebaa9734a236b7157fb57c065b6c0f2344281916187bd73f951df1899e0", size = 4499081 },
{ url = "https://files.pythonhosted.org/packages/42/21/32d7115b2cbd87d043ad494254fd7c4c8652ac3c32f49bb571fd8111caf3/psycopg_binary-3.2.5-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:21b839f9bfd77ed074f7f71464a43f453400c57d038a0ba0716329a28e335897", size = 4307502 },
{ url = "https://files.pythonhosted.org/packages/00/67/e99b58f616dd02c5e52c179b3df047d9683a9f699993cb1795ee435db598/psycopg_binary-3.2.5-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:7376b13504396da9678b646f5338462347da01286b2a688a0d8493ec764683a2", size = 4547821 },
{ url = "https://files.pythonhosted.org/packages/0d/64/9d13ee0fed78a47c506a93d1e67ee53cc7ffd75c1f5885b59d17810fe5cd/psycopg_binary-3.2.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:473f6827cf1faf3924eb77146d1e85126a1b5e48a88053b8d8b78dd29e971d78", size = 4259849 },
{ url = "https://files.pythonhosted.org/packages/ea/f2/172b6ebcd60a1a86f5ce1a539cfb93ffbe42fc9bc7ab2e1ed79e99a75d71/psycopg_binary-3.2.5-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:28bd5cb2324567e5e70f07fe1d646398d6b0e210e28b49be0e69593590a59980", size = 3847280 },
{ url = "https://files.pythonhosted.org/packages/0f/51/9cd26c6b862d499b4b25ea173ae6e21c9d460ddce6b09cbe9501dff66211/psycopg_binary-3.2.5-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:48f97936145cb7de18b95d85670b2d3e2c257277263272be05815b74fb0ef195", size = 3320262 },
{ url = "https://files.pythonhosted.org/packages/51/7d/2dac61ff16476e77c6ce0a49a30b130e2ba6ad08c83c4950591b4bc49cf2/psycopg_binary-3.2.5-cp312-cp312-musllinux_1_2_ppc64le.whl", hash = "sha256:8e6f2bef5aed021fbdf46323d3cd8847bf960efb56394698644a8ee2306f8892", size = 3400254 },
{ url = "https://files.pythonhosted.org/packages/45/67/bd36932c24f96dc1bc21fb18b1bdebcda7b9791067f7151a1c5dc1193e6b/psycopg_binary-3.2.5-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:3d2e57a1d06f3968e49e948ba374f21a7d8dcf44f37d582a4aeddeb7c85ce239", size = 3438916 },
{ url = "https://files.pythonhosted.org/packages/00/ab/882b861cfcf83d7faffe583e1e092117cd66eacc86fb4517d27973e52f35/psycopg_binary-3.2.5-cp312-cp312-win_amd64.whl", hash = "sha256:2cbb8649cfdacbd14e17f5ab78edc52d33350013888518c73e90c5d17d7bea55", size = 2782504 },
{ url = "https://files.pythonhosted.org/packages/81/3d/26483d75e1a5daa93cbb47ee7cde96fac07a9b026058b036b00a04f5c012/psycopg_binary-3.2.5-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:2dbaf32c18c0d11c4480016b89c9c5cadb7b64c55de7f181d222b189bd13a558", size = 3852616 },
{ url = "https://files.pythonhosted.org/packages/90/cb/542bd0eab110ed2ddcc02cbe8f5df0afe3e86bd843c533fc6a795ffd7c0f/psycopg_binary-3.2.5-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:ca5e36a3e7480a5c09aed99ecdb8e6554b21485c3b064297fe77f7b1b5806106", size = 3936563 },
{ url = "https://files.pythonhosted.org/packages/e1/43/2b347816983a5b0f1cc3e608eae4650422476187e047e574981081bcf9ec/psycopg_binary-3.2.5-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:9abe093a303e25ac58774a11241150e2fe2947358d1ca12521ad03c90b131060", size = 4499166 },
{ url = "https://files.pythonhosted.org/packages/3f/0d/d7ac5289dfa1163b0fcce9aeb848a7f4499d7b3ef34f1de565d0ba9a51bd/psycopg_binary-3.2.5-cp313-cp313-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:a91b0e096fdfeb52d86bb8f5ee25dc22483d6960af9b968e6b381a8ec5bfbf82", size = 4311647 },
{ url = "https://files.pythonhosted.org/packages/7b/a2/b238d91cbbc5953ff6910737b5a598cc4d5aad84453052005891cec329b3/psycopg_binary-3.2.5-cp313-cp313-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:3eb71cfc35116e4a8e336b7e785f1fe06ca23b4516a48ea91facd577d1a1fdf6", size = 4547848 },
{ url = "https://files.pythonhosted.org/packages/d7/33/e78ae02d8f23753af2884303370b914a5d172f76fed13bfde380ec473f53/psycopg_binary-3.2.5-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:98efaedf2bf79f4d563ca039a57a025b72847bd80568f54709cc39fc1404772c", size = 4261732 },
{ url = "https://files.pythonhosted.org/packages/44/9a/1745ff5c6e4c715aa71f3da3f393022ec0c7cc972fa0ee7296df8871d6d6/psycopg_binary-3.2.5-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:ba4a610882171bdaae0779f14e0ff45f3ee271fd2dbf16cdadfc81bd67323232", size = 3850803 },
{ url = "https://files.pythonhosted.org/packages/7b/1c/933fb04560e7bcf5f24c632f9381e8700dcf8462adcd32eabd6192480d66/psycopg_binary-3.2.5-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:1494827c43265820d5dcdc6f8086521bc7dd04b9da8831310978a788cdcd2e62", size = 3320315 },
{ url = "https://files.pythonhosted.org/packages/5d/36/111e2db9c3ff5123da4ce814aa9462d242a7c393f132a4005ec427e09903/psycopg_binary-3.2.5-cp313-cp313-musllinux_1_2_ppc64le.whl", hash = "sha256:7a94020821723a6a210206ddb458001f3ed27e1e6a0555b9422bebf7ead8ff37", size = 3403225 },
{ url = "https://files.pythonhosted.org/packages/90/04/246efe587463d13b015202ab344e12e8e30ea9ba90ca952def0469b95a9e/psycopg_binary-3.2.5-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:659f2c675d478b1bc01b95a8d3ded74fa939b370e71ffbecd496f617b215eb05", size = 3440446 },
{ url = "https://files.pythonhosted.org/packages/92/75/5e15e7a6ad4c6a00fe1a28fe704310dc7f7b26dbd5e6e14c817e7899451b/psycopg_binary-3.2.5-cp313-cp313-win_amd64.whl", hash = "sha256:6b581da13126b8715c0c0585cd37ce934c9864d44b2a4019f5487c0b943275e6", size = 2783095 },
]
sdist = { url = "https://files.pythonhosted.org/packages/cf/cb/468dcca82f08b47af59af4681ef39473cf5c0ef2e09775c701ccdf7284d6/psycopg_c-3.2.5.tar.gz", hash = "sha256:57ad4cfd28de278c424aaceb1f2ad5c7910466e315dfe84e403f3c7a0a2ce81b", size = 609318 }
[[package]]
name = "python-dotenv"