mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2025-02-17 03:51:02 +03:00
Replaced copying python package directories with wheel files which are then used to install all requirements. This way the generated images would be a lot more stable as well. Size increases by 2-3mb though
This commit is contained in:
parent
079db28661
commit
4a52845a26
|
@ -7,19 +7,18 @@ RUN apt-get update && apt-get install --no-install-recommends -y \
|
||||||
build-essential \
|
build-essential \
|
||||||
# psycopg2 dependencies
|
# psycopg2 dependencies
|
||||||
libpq-dev \
|
libpq-dev \
|
||||||
# Translations dependencies
|
|
||||||
gettext \
|
|
||||||
# cleaning up unused files
|
# cleaning up unused files
|
||||||
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
|
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
|
||||||
# Requirements are installed here to ensure they will be cached.
|
# Requirements are installed here to ensure they will be cached.
|
||||||
COPY ./requirements /requirements
|
COPY ./requirements /requirements
|
||||||
|
|
||||||
# install python dependencies
|
# create python dependency wheels
|
||||||
RUN pip install --no-cache-dir --use-feature=2020-resolver -r /requirements/local.txt \
|
RUN pip wheel --no-cache-dir --no-deps --use-feature=2020-resolver --wheel-dir /usr/src/app/wheels \
|
||||||
&& rm -rf /requirements
|
-r /requirements/local.txt \
|
||||||
|
&& rm -rf /requirements
|
||||||
|
|
||||||
|
|
||||||
# Python 'run' stage
|
# Python 'run' stage
|
||||||
|
@ -62,11 +61,12 @@ RUN apt-get update && apt-get install --no-install-recommends -y \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
|
||||||
|
# copy python dependency wheels from python-build-stage
|
||||||
|
COPY --from=python-build-stage /usr/src/app/wheels /wheels
|
||||||
|
|
||||||
# copy python dependencies from python-build-stage
|
# use wheels to install python dependencies
|
||||||
COPY --from=python-build-stage /usr/local/lib/python3.8/site-packages/ /usr/local/lib/python3.8/site-packages/
|
RUN pip install --no-cache /wheels/* \
|
||||||
COPY --from=python-build-stage /usr/local/bin/ /usr/local/bin/
|
&& rm -rf /wheels
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
|
@ -11,25 +11,28 @@ RUN npm run build
|
||||||
|
|
||||||
# Python build stage
|
# Python build stage
|
||||||
FROM python:3.8-slim-buster as python-build-stage
|
FROM python:3.8-slim-buster as python-build-stage
|
||||||
|
|
||||||
ENV PYTHONDONTWRITEBYTECODE 1
|
ENV PYTHONDONTWRITEBYTECODE 1
|
||||||
|
ARG BUILD_ENVIRONMENT
|
||||||
|
|
||||||
|
|
||||||
RUN apt-get update && apt-get install --no-install-recommends -y \
|
RUN apt-get update && apt-get install --no-install-recommends -y \
|
||||||
# dependencies for building Python packages
|
# dependencies for building Python packages
|
||||||
build-essential \
|
build-essential \
|
||||||
# psycopg2 dependencies
|
# psycopg2 dependencies
|
||||||
libpq-dev \
|
libpq-dev \
|
||||||
# Translations dependencies
|
|
||||||
gettext \
|
|
||||||
# cleaning up unused files
|
# cleaning up unused files
|
||||||
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
|
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
|
||||||
# Requirements are installed here to ensure they will be cached.
|
# Requirements are installed here to ensure they will be cached.
|
||||||
COPY ./requirements /requirements
|
COPY ./requirements /requirements
|
||||||
|
|
||||||
# install python dependencies
|
# create python dependency wheels
|
||||||
Run pip install --no-cache-dir --use-feature=2020-resolver -r /requirements/production.txt \
|
RUN pip wheel --no-cache-dir --no-deps --use-feature=2020-resolver --wheel-dir /usr/src/app/wheels \
|
||||||
&& rm -rf /requirements
|
-r /requirements/production.txt \
|
||||||
|
&& rm -rf /requirements
|
||||||
|
|
||||||
# Python 'run' stage
|
# Python 'run' stage
|
||||||
FROM python:3.8-slim-buster as python-run-stage
|
FROM python:3.8-slim-buster as python-run-stage
|
||||||
|
@ -77,9 +80,12 @@ RUN apt-get update && apt-get install --no-install-recommends -y \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
|
||||||
# copy python dependencies from python-build-stage
|
# copy python dependency wheels from python-build-stage
|
||||||
COPY --from=python-build-stage /usr/local/lib/python3.8/site-packages/ /usr/local/lib/python3.8/site-packages/
|
COPY --from=python-build-stage /usr/src/app/wheels /wheels
|
||||||
COPY --from=python-build-stage /usr/local/bin/ /usr/local/bin/
|
|
||||||
|
# use wheels to install python dependencies
|
||||||
|
RUN pip install --no-cache /wheels/* \
|
||||||
|
&& rm -rf /wheels
|
||||||
|
|
||||||
{%- if cookiecutter.js_task_runner == 'Gulp' %}
|
{%- if cookiecutter.js_task_runner == 'Gulp' %}
|
||||||
COPY --from=client-builder --chown=django:django /app /app
|
COPY --from=client-builder --chown=django:django /app /app
|
||||||
|
|
Loading…
Reference in New Issue
Block a user