@@ -9,6 +9,13 @@ LABEL maintainer="https://github.com/sandiegopython"
99ENV PYTHONDONTWRITEBYTECODE 1
1010ENV PYTHONUNBUFFERED 1
1111
12+ # uv environment variables
13+ # Copy (don't hardlink) files into /.venv. Avoid issues with Docker's FS
14+ # https://docs.astral.sh/uv/reference/environment/
15+ ENV UV_LINK_MODE=copy
16+ ENV UV_PYTHON_DOWNLOADS=never
17+ ENV UV_PROJECT_ENVIRONMENT=/.venv
18+
1219RUN apt-get update
1320RUN apt-get install -y --no-install-recommends curl
1421
@@ -25,28 +32,40 @@ RUN apt-get install -y --no-install-recommends \
2532 postgresql-client libpq-dev \
2633 git
2734
28- RUN mkdir -p /code
29-
35+ RUN mkdir -p /code /home/www/
3036WORKDIR /code
3137
32- # Requirements are installed here to ensure they will be cached.
33- # https://docs.docker.com/build/cache/#use-the-dedicated-run-cache
34- COPY ./requirements /requirements
35- RUN pip install --upgrade pip
36- RUN --mount=type=cache,target=/root/.cache/pip pip install -r /requirements/deployment.txt
37- RUN --mount=type=cache,target=/root/.cache/pip pip install -r /requirements/local.txt
38+ # Install uv for fast package management
39+ # https://docs.astral.sh/uv/guides/integration/docker/#installing-uv
40+ COPY --from=ghcr.io/astral-sh/uv:0.9.11 /uv /uvx /bin/
41+
42+ # Copy project files for dependency resolution
43+ # uv.lock ensures reproducible builds
44+ COPY pyproject.toml uv.lock ./
45+ RUN --mount=type=cache,target=/root/.cache/uv \
46+ uv sync --frozen --no-install-project --all-extras
3847
3948COPY . /code/
4049
4150# Build JS/static assets
4251RUN --mount=type=cache,target=/root/.npm npm install
4352RUN npm run dist
4453
45- RUN python manage.py collectstatic --noinput --clear
54+ RUN uv run python manage.py collectstatic --noinput --clear
55+
56+ # Launches the application (gunicorn) with this script
57+ COPY ./docker/start /start
58+ RUN chmod +x /start
59+
60+ # Launch a shell within the container with this script
61+ COPY ./docker/shell /shell
62+ RUN chmod +x /shell
4663
4764# Run the container unprivileged
4865RUN addgroup www && useradd -g www www
4966RUN chown -R www:www /code
67+ # Needed for the uv cache
68+ RUN chown -R www:www /home/www
5069USER www
5170
5271# Output information about the build
@@ -56,4 +75,4 @@ RUN date -u +'%Y-%m-%dT%H:%M:%SZ' > BUILD_DATE
5675
5776EXPOSE 8000
5877
59- CMD ["gunicorn" , "--timeout" , "15" , "--bind" , ":8000" , "--workers" , "2" , "--max-requests" , "10000" , "--max-requests-jitter" , "100" , "--log-file" , "-" , "--access-logfile" , "-" , "config.wsgi " ]
78+ CMD ["/start " ]
0 commit comments