From df11823eaa22d207ffe7a74d2c8c11137a1233a3 Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Tue, 12 Nov 2024 14:27:38 +0000 Subject: [PATCH] Standardise Dockerfile for local dev --- Dockerfile | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 230c4d04..176ca4b2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,23 @@ FROM python:3.10-bullseye -# install git as pip needs to clone fsd_utils -RUN apt update && apt -yq install git -# install manually to workaround issue in psycopg2-binary 2.9.5 -RUN pip3 install psycopg2-binary --no-binary psycopg2-binary - WORKDIR /app -COPY requirements-dev.txt requirements-dev.txt -RUN python3 -m pip install --upgrade pip && pip install -r requirements-dev.txt + +COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ + +# Install the project's dependencies using the lockfile and settings +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-install-project + +# Then, add the rest of the project source code and install it +# Installing separately from its dependencies allows optimal layer caching COPY . . +RUN --mount=type=cache,target=/root/.cache/uv \ + uv sync --frozen +# Place executables in the environment at the front of the path +ENV PATH="/app/.venv/bin:$PATH" EXPOSE 8080 -ENV FLASK_ENV=development CMD ["gunicorn", "--worker-class", "uvicorn.workers.UvicornWorker", "wsgi:app", "-b", "0.0.0.0:8080"]