From b6aa68e419f7f020a010dc9b0b0c54615e043f89 Mon Sep 17 00:00:00 2001 From: mike wakerly Date: Tue, 19 Jul 2022 18:58:10 +0100 Subject: [PATCH] docker: switch back to debian base image Alpine builds are taking a very long time, possibly due to python dependencies lacking pre-built musl wheels [1]. Moreover resulting image sizes are comparable so benefit of alpine here is ambiguous at best. [1] https://megamorf.gitlab.io/2020/05/06/why-it-s-better-not-to-use-alpine-linux-for-python-projects/ --- Dockerfile | 59 +++++++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9f70caa2..a5da774c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3-alpine +FROM python:3.10.5-bullseye RUN mkdir /app WORKDIR /app @@ -9,44 +9,49 @@ ENV SHELL=/bin/sh \ KEGBOT_IN_DOCKER=True \ KEGBOT_ENV=debug -RUN apk update && \ - apk add --no-cache \ - bash \ +# Install toolchains. Mostly, image libraries that Python PIL/Pillow will require. +RUN apt-get -qq update \ + && DEBIAN_FRONTEND=noninteractive apt-get -y install \ curl \ - libjpeg \ - libjpeg-turbo \ - openjpeg \ - mariadb-connector-c-dev \ - libpq && \ - apk add --no-cache --virtual _build-deps \ - build-base \ - mariadb-dev \ - postgresql-dev \ - libjpeg-turbo-dev \ - zlib-dev \ - py-gevent \ - libffi-dev \ - musl-dev \ - python3-dev \ - openssl-dev \ - cargo - -RUN pip install poetry - + libffi-dev \ + libfreetype6-dev \ + libfribidi-dev \ + libharfbuzz-dev \ + libjpeg-turbo-progs \ + libjpeg62-turbo-dev \ + liblcms2-dev \ + libopenjp2-7-dev \ + libtiff5-dev \ + libwebp-dev \ + libssl-dev \ + zlib1g-dev \ + && rm -rf /var/lib/apt/lists/* \ + && python -m pip install -U pip \ + # The cryptography build requires rust, which adds >1GB to the image. \ + # Install it only to install cryptography, then remove it. \ + && curl https://sh.rustup.rs -sSf | sh -s -- -y \ + && pip install cryptography \ + && rm -rf /root/.rustup /root/.cargo \ + && pip install poetry \ + && rm -rf /root/.cache + +# Install python dependencies. COPY pyproject.toml poetry.lock ./ ADD pykeg/__init__.py ./pykeg/ RUN poetry config virtualenvs.create false && poetry install -n +# Install the app itself. ADD bin ./bin ADD pykeg ./pykeg RUN poetry run python bin/kegbot collectstatic --noinput -v 0 +# Tag the build with build information. ARG GIT_SHORT_SHA="unknown" ARG VERSION="unknown" ARG BUILD_DATE="unknown" -RUN echo "GIT_SHORT_SHA=${GIT_SHORT_SHA}" > /etc/kegbot-version -RUN echo "VERSION=${VERSION}" >> /etc/kegbot-version -RUN echo "BUILD_DATE=${BUILD_DATE}" >> /etc/kegbot-version +RUN echo "GIT_SHORT_SHA=${GIT_SHORT_SHA}" \ + && echo "VERSION=${VERSION}" \ + && echo "BUILD_DATE=${BUILD_DATE}" /etc/kegbot-version VOLUME ["/kegbot-data"]