Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new py-dev Docker stage and use in all later stages #276

Merged
merged 2 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Added `django-perf-rec` to `dev` extras in `pyproject.toml`.
- Added `pip` and `uv` to `dev` extras in `pyproject.toml`.

### Fixed

- Added a new `py-dev` stage to the `Dockerfile` for installation of development dependencies. All intermediate stages afterwards now rely on the Python packages installed in this stage, with the exception of the final stage which only copies the production dependencies from the `py` stage.

## [2024.41]

### Changed
Expand Down
17 changes: 11 additions & 6 deletions src/django_twc_project/Dockerfile.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,15 @@ RUN --mount=type=cache,target=/root/.cache/pip --mount=type=cache,target=/root/.
&& uv pip install -r requirements.txt


FROM node-base as node
FROM py as py-dev
COPY --from=py --link /usr/local /usr/local
COPY --link requirements.dev.txt ./
RUN --mount=type=cache,target=/root/.cache/pip --mount=type=cache,target=/root/.cache/uv \
uv pip install -r requirements.dev.txt


FROM node-base as node
COPY --from=py-dev --link /usr/local /usr/local
COPY --link package*.json /app
RUN --mount=type=cache,target=/root/.npm npm install

Expand All @@ -96,7 +103,6 @@ RUN case ${BUILDARCH} in \


FROM base as app
COPY --from=py --link /usr/local /usr/local
COPY --link manage.py package.json /app/
COPY --link {{ module_name }} /app/{{ module_name }}
COPY --link templates /app/templates
Expand All @@ -105,7 +111,7 @@ COPY --link templates /app/templates
FROM mcr.microsoft.com/playwright/python:v{{ playwright_version }} as dev
ENV DEBIAN_FRONTEND noninteractive
ENV UV_SYSTEM_PYTHON true
COPY --from=py --link /usr/local /usr/local
COPY --from=py-dev --link /usr/local /usr/local
COPY --from=app --link /app /app
COPY --link requirements.dev.txt ./
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked --mount=type=cache,target=/var/lib/apt,sharing=locked \
Expand All @@ -116,8 +122,7 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked --mount=type=cache,t
# (it's normally included in the Python based images)
tzdata \
# cleanup
&& apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* \
&& uv pip install -r requirements.dev.txt
&& apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/*


FROM node as node-final
Expand All @@ -137,7 +142,7 @@ RUN python manage.py tailwind --skip-checks build

FROM app as static
ENV DATABASE_URL sqlite://:memory:
COPY --from=py --link /usr/local /usr/local
COPY --from=py-dev --link /usr/local /usr/local
COPY --from=node-final --link /app/static/dist /app/static/dist
COPY --from=node-final --link /app/package*.json /app/
COPY --link static/public /app/static/public
Expand Down