From 23c4c51f0041318d4de64b9debcc10cccca110ae Mon Sep 17 00:00:00 2001 From: Matthew Cengia Date: Thu, 22 Jun 2023 10:34:06 -0700 Subject: [PATCH] Configure multi-stage container build incl template --- django/Dockerfile | 30 ++++++++++++++++++++++++------ django/Dockerfile.dev | 40 ---------------------------------------- 2 files changed, 24 insertions(+), 46 deletions(-) delete mode 100644 django/Dockerfile.dev diff --git a/django/Dockerfile b/django/Dockerfile index bdf617f..03edfaf 100644 --- a/django/Dockerfile +++ b/django/Dockerfile @@ -5,7 +5,7 @@ COPY docs src RUN mdbook build -FROM python:3.11.3-bullseye +FROM python:3.11.3-bullseye AS template ENV PYTHONUNBUFFERED=1 ENV PYTHONDONTWRITEBYTECODE=1 WORKDIR /code @@ -16,10 +16,6 @@ RUN apt-get update && \ libproj-dev \ gdal-bin \ libsqlite3-mod-spatialite \ - # Database client for using './manage.py dbshell' etc - #sqlite3 \ - #spatialite-bin \ - #postgresql-client \ && \ apt-get -y autoremove && \ apt-get -y clean && \ @@ -31,10 +27,32 @@ VOLUME /static VOLUME /media VOLUME /docs COPY . . -COPY --from=docs /book/book /built_docs EXPOSE 8000 HEALTHCHECK --interval=10s --timeout=5s --retries=5 CMD bash -c '[[ "$(curl -L -o /dev/null -s -w "%{http_code}\n" http://localhost:8000/)" == "200" ]]' ENTRYPOINT ["/code/docker-entrypoint.sh"] + + +FROM template AS dev_template +RUN apt-get update && \ + apt-get install -y \ + # Database client for using './manage.py dbshell' etc + sqlite3 \ + spatialite-bin \ + postgresql-client \ + && \ + apt-get -y autoremove && \ + apt-get -y clean && \ + rm -rf /var/lib/apt/lists/* + + +FROM dev_template AS dev +COPY . . +COPY --from=docs /book/book /built_docs + + +FROM template AS prod +COPY . . +COPY --from=docs /book/book /built_docs diff --git a/django/Dockerfile.dev b/django/Dockerfile.dev deleted file mode 100644 index 2f6dce9..0000000 --- a/django/Dockerfile.dev +++ /dev/null @@ -1,40 +0,0 @@ -FROM --platform=$BUILDPLATFORM peaceiris/mdbook:v0.4.30 AS docs - -WORKDIR /book -COPY docs src -RUN mdbook build - - -FROM python:3.11.3-bullseye -ENV PYTHONUNBUFFERED=1 -ENV PYTHONDONTWRITEBYTECODE=1 -WORKDIR /code - -RUN apt-get update && \ - apt-get install -y \ - binutils \ - libproj-dev \ - gdal-bin \ - libsqlite3-mod-spatialite \ - # Database client for using './manage.py dbshell' etc - sqlite3 \ - spatialite-bin \ - postgresql-client \ - && \ - apt-get -y autoremove && \ - apt-get -y clean && \ - rm -rf /var/lib/apt/lists/* - -COPY requirements.txt . -RUN pip install -r requirements.txt -VOLUME /static -VOLUME /media -VOLUME /docs -COPY . . -COPY --from=docs /book/book /built_docs - -EXPOSE 8000 - -HEALTHCHECK --interval=10s --timeout=5s --retries=5 CMD bash -c '[[ "$(curl -L -o /dev/null -s -w "%{http_code}\n" http://localhost:8000/)" == "200" ]]' - -ENTRYPOINT ["/code/docker-entrypoint.sh"]