Skip to content

Commit

Permalink
Use the slim-bookworm image, refactored some steps
Browse files Browse the repository at this point in the history
  • Loading branch information
Taaku18 committed May 14, 2024
1 parent 65a6931 commit ea825c4
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit ea825c4

Please sign in to comment.