Use layers to build Docker image

Better cache and lighter image, yay.
This commit is contained in:
Yohan Boniface 2023-06-05 15:44:32 +02:00
parent faebeebbdf
commit 3856cd447b
3 changed files with 46 additions and 39 deletions

View file

@ -8,56 +8,60 @@ RUN npm install
RUN npm run vendors RUN npm run vendors
FROM python:3.11-slim FROM python:3.11-slim as common
ENV PYTHONUNBUFFERED=1 \
PORT=8000
RUN mkdir -p /srv/umap/uploads
COPY . /srv/umap
COPY --from=vendors /srv/umap/umap/static/umap/vendors /srv/umap/umap/static/umap/vendors
WORKDIR /srv/umap
RUN apt-get update && \ RUN apt-get update && \
apt-get install -y --no-install-recommends \ apt-get install -y --no-install-recommends \
tini \ tini \
uwsgi \ uwsgi \
libpq-dev \
build-essential \
binutils \
gdal-bin \
libproj-dev \
curl \
git \
gettext \
sqlite3 \ sqlite3 \
libffi-dev \ libpq-dev \
libtiff5-dev \ gdal-bin \
libjpeg62-turbo-dev \
zlib1g-dev \
libfreetype6-dev \
liblcms2-dev \
libwebp-dev \
&& \
pip install .[docker] && \
apt-get remove -y \
binutils \
libproj-dev \
libffi-dev \
libtiff5-dev \
libjpeg62-turbo-dev \
zlib1g-dev \
libfreetype6-dev \
liblcms2-dev \
libwebp-dev \
&& \ && \
apt-get autoremove -y && \ apt-get autoremove -y && \
apt-get clean && \ apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
FROM common as build
RUN apt-get update && \
apt-get install -y --no-install-recommends \
build-essential \
binutils \
libproj-dev \
curl \
git \
gettext \
python3-venv \
libffi-dev \
libtiff5-dev \
libjpeg62-turbo-dev \
zlib1g-dev \
libfreetype6-dev \
liblcms2-dev \
libwebp-dev
RUN python -m venv /venv
WORKDIR /srv/umap
COPY . /srv/umap
RUN /venv/bin/pip install .[docker]
FROM common
COPY --from=build /srv/umap/docker/ /srv/umap/docker/
COPY --from=build /venv/ /venv/
COPY --from=vendors /srv/umap/umap/static/umap/vendors /srv/umap/umap/static/umap/vendors
WORKDIR /srv/umap
RUN mkdir -p /srv/umap/uploads
ENV PYTHONUNBUFFERED=1 \
PORT=8000
EXPOSE 8000 EXPOSE 8000
ENTRYPOINT ["/usr/bin/tini", "--"] ENTRYPOINT ["/usr/bin/tini", "--"]

View file

@ -1,6 +1,8 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -eo pipefail set -eo pipefail
source /venv/bin/activate
# default variables # default variables
: "${SLEEP:=1}" : "${SLEEP:=1}"
: "${TRIES:=60}" : "${TRIES:=60}"

View file

@ -1,5 +1,6 @@
[uwsgi] [uwsgi]
http = :$(PORT) http = :$(PORT)
home = /venv
module = umap.wsgi:application module = umap.wsgi:application
master = True master = True
vacuum = True vacuum = True