From 079db28661a5a30066dc67da57b728741a04b986 Mon Sep 17 00:00:00 2001 From: Arnav Choudhury Date: Mon, 14 Sep 2020 01:41:33 +0530 Subject: [PATCH] Changed when Requirements are copied and installed to improve incremental image build times. The extra image layer is inconsequential since python-build-stage layers are discarded anyway. --- .../compose/local/django/Dockerfile | 17 +++++++++-------- .../compose/production/django/Dockerfile | 16 ++++++++-------- .../compose/production/traefik/Dockerfile | 2 +- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/{{cookiecutter.project_slug}}/compose/local/django/Dockerfile b/{{cookiecutter.project_slug}}/compose/local/django/Dockerfile index 11cc99784..645b04766 100644 --- a/{{cookiecutter.project_slug}}/compose/local/django/Dockerfile +++ b/{{cookiecutter.project_slug}}/compose/local/django/Dockerfile @@ -2,9 +2,6 @@ FROM python:3.8-slim-buster as python-build-stage ENV PYTHONDONTWRITEBYTECODE 1 -# Requirements are installed here to ensure they will be cached. -COPY ./requirements /requirements - RUN apt-get update && apt-get install --no-install-recommends -y \ # dependencies for building Python packages build-essential \ @@ -14,15 +11,19 @@ RUN apt-get update && apt-get install --no-install-recommends -y \ gettext \ # cleaning up unused files && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \ - && rm -rf /var/lib/apt/lists/* \ - # install python dependencies - && pip install --no-cache-dir --use-feature=2020-resolver -r /requirements/local.txt \ - && rm -rf /requirements + && rm -rf /var/lib/apt/lists/* + +# Requirements are installed here to ensure they will be cached. +COPY ./requirements /requirements + +# install python dependencies +RUN pip install --no-cache-dir --use-feature=2020-resolver -r /requirements/local.txt \ + && rm -rf /requirements # Python 'run' stage -FROM python:3.8-slim-buster +FROM python:3.8-slim-buster as python-run-stage ENV PYTHONUNBUFFERED 1 ENV PYTHONDONTWRITEBYTECODE 1 diff --git a/{{cookiecutter.project_slug}}/compose/production/django/Dockerfile b/{{cookiecutter.project_slug}}/compose/production/django/Dockerfile index 722f709fb..cc46464bb 100644 --- a/{{cookiecutter.project_slug}}/compose/production/django/Dockerfile +++ b/{{cookiecutter.project_slug}}/compose/production/django/Dockerfile @@ -13,9 +13,6 @@ RUN npm run build FROM python:3.8-slim-buster as python-build-stage ENV PYTHONDONTWRITEBYTECODE 1 -# Requirements are installed here to ensure they will be cached. -COPY ./requirements /requirements - RUN apt-get update && apt-get install --no-install-recommends -y \ # dependencies for building Python packages build-essential \ @@ -25,14 +22,17 @@ RUN apt-get update && apt-get install --no-install-recommends -y \ gettext \ # cleaning up unused files && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \ - && rm -rf /var/lib/apt/lists/* \ - # install python dependencies - && pip install --no-cache-dir --use-feature=2020-resolver -r /requirements/production.txt \ - && rm -rf /requirements + && rm -rf /var/lib/apt/lists/* +# Requirements are installed here to ensure they will be cached. +COPY ./requirements /requirements + +# install python dependencies +Run pip install --no-cache-dir --use-feature=2020-resolver -r /requirements/production.txt \ + && rm -rf /requirements # Python 'run' stage -FROM python:3.8-slim-buster +FROM python:3.8-slim-buster as python-run-stage ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 diff --git a/{{cookiecutter.project_slug}}/compose/production/traefik/Dockerfile b/{{cookiecutter.project_slug}}/compose/production/traefik/Dockerfile index 26a653d50..aa879052b 100644 --- a/{{cookiecutter.project_slug}}/compose/production/traefik/Dockerfile +++ b/{{cookiecutter.project_slug}}/compose/production/traefik/Dockerfile @@ -1,4 +1,4 @@ -FROM traefik:v2.0 +FROM traefik:v2.2.11 RUN mkdir -p /etc/traefik/acme \ && touch /etc/traefik/acme/acme.json \ && chmod 600 /etc/traefik/acme/acme.json