From ea825c43210b204777a22aa5031446b9b36c7686 Mon Sep 17 00:00:00 2001 From: Taku <45324516+Taaku18@users.noreply.github.com> Date: Tue, 14 May 2024 03:50:22 -0700 Subject: [PATCH] Use the slim-bookworm image, refactored some steps --- Dockerfile | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8316d6139b..18584c342e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,38 +1,38 @@ -FROM python:3.11-alpine as base - -RUN apk add --no-cache \ - # cairosvg dependencies - cairo-dev cairo cairo-tools \ - # pillow dependencies - jpeg-dev zlib-dev \ - && adduser -D -h /home/modmail -g 'Modmail' modmail - -ENV VIRTUAL_ENV=/home/modmail/.venv -ENV PATH="$VIRTUAL_ENV/bin:$PATH" - -WORKDIR /home/modmail +FROM python:3.11-slim-bookworm as base + +RUN apt-get update && \ + apt-get install --no-install-recommends -y \ + # Install CairoSVG dependencies. + libcairo2 && \ + # Cleanup APT. + apt-get clean && \ + rm -rf /var/lib/apt/lists/* && \ + # Create a non-root user. + useradd --create-home -d /opt/modmail modmail FROM base as builder -RUN apk add build-base libffi-dev +COPY requirements.txt . -RUN python -m venv $VIRTUAL_ENV +RUN pip install --root-user-action=ignore --no-cache-dir --upgrade pip wheel && \ + python -m venv /opt/modmail/.venv && \ + . /opt/modmail/.venv/bin/activate && \ + pip install --no-cache-dir --upgrade -r requirements.txt -COPY --chown=modmail:modmail requirements.txt . -RUN pip install --upgrade pip setuptools && \ - pip install -r requirements.txt +FROM base -FROM base as runtime - -# copy the entire venv -COPY --from=builder --chown=modmail:modmail $VIRTUAL_ENV $VIRTUAL_ENV +# Copy the entire venv. +COPY --from=builder --chown=modmail:modmail /opt/modmail/.venv /opt/modmail/.venv # copy repository files +WORKDIR /opt/modmail +USER modmail:modmail COPY --chown=modmail:modmail . . -# this disables the internal auto-update -ENV USING_DOCKER yes - -USER modmail +# This sets some Python runtime variables and disables the internal auto-update. +ENV PYTHONUNBUFFERED=1 \ + PYTHONDONTWRITEBYTECODE=1 \ + PATH=/opt/modmail/.venv/bin:$PATH \ + USING_DOCKER=yes CMD ["python", "bot.py"]