diff options
author | 2025-07-15 16:53:30 -0700 | |
---|---|---|
committer | 2025-07-17 18:41:45 -0700 | |
commit | 97a9d85678605bd3720dc6a85fd2d6ff8b5ad379 (patch) | |
tree | d3ab537f233d6538190f53311a92a94e897dbed5 /Dockerfile | |
parent | Merge pull request #1547 from python-discord/resources-category-update (diff) |
Dependencies/docker to uv
Corrected dockerfile to copy uv over from build step
Probably fine, right? (I forgot how to dockerfile, please forgive me)
Diffstat (limited to 'Dockerfile')
-rw-r--r-- | Dockerfile | 42 |
1 files changed, 31 insertions, 11 deletions
@@ -2,23 +2,43 @@ # update the contributor guide, which can be found at # pydis_site/apps/content/resources/guides/pydis-guides/contributing/site.md # Thank you! -FROM ghcr.io/owl-corp/python-poetry-base:3.11-slim +ARG python_version=3.13-slim -# Allow service to handle stops gracefully -STOPSIGNAL SIGQUIT +FROM python:$python_version AS builder +COPY --from=ghcr.io/astral-sh/uv:0.7 /uv /bin/ -# Copy the project files into working directory -WORKDIR /app +ENV UV_COMPILE_BYTECODE=1 \ + UV_LINK_MODE=copy + +# Install project dependencies with build tools available +WORKDIR /build + +RUN pip install --no-cache-dir --upgrade pip setuptools wheel \ + && python -m venv .venv + +RUN --mount=type=cache,target=/root/.cache/uv \ + --mount=type=bind,source=uv.lock,target=uv.lock \ + --mount=type=bind,source=pyproject.toml,target=pyproject.toml \ + uv sync --frozen --no-dev -# Install project dependencies -COPY pyproject.toml poetry.lock ./ -RUN poetry install --only main +FROM python:$python_version + +# Allow service to handle stops gracefully +STOPSIGNAL SIGQUIT # Set Git SHA environment variable ARG git_sha="development" ENV GIT_SHA=$git_sha +# Install dependencies from build cache +# .venv not put in /app so that it doesn't conflict with the dev +# volume we use to avoid rebuilding image every code change locally +COPY --from=builder /build /build +COPY --from=builder /bin/uv /bin/uv +ENV PATH="/build/.venv/bin:$PATH" + # Copy the source code in last to optimize rebuilding the image +WORKDIR /app COPY . . # Set dummy variables so collectstatic can load settings.py @@ -31,15 +51,15 @@ RUN \ SECRET_KEY=dummy_value \ DATABASE_URL=postgres://localhost \ METRICITY_DB_URL=postgres://localhost \ - poetry run python manage.py collectstatic --noinput --clear + uv run python manage.py collectstatic --noinput --clear # Build static files if we are doing a static build ARG STATIC_BUILD=false RUN if [ $STATIC_BUILD = "TRUE" ] ; \ - then SECRET_KEY=dummy_value poetry run python manage.py distill-local build --traceback --force ; \ + then SECRET_KEY=dummy_value uv run python manage.py distill-local build --traceback --force ; \ fi -ENTRYPOINT ["poetry", "run"] +ENTRYPOINT ["uv", "run"] CMD ["gunicorn", "--preload", "-b", "0.0.0.0:8000", \ "pydis_site.wsgi:application", "-w", "2", "--statsd-host", \ "graphite.default.svc.cluster.local:8125", "--statsd-prefix", "site", \ |