Skip to content

Commit

Permalink
Use pip, alpine image and multistage build
Browse files Browse the repository at this point in the history
  • Loading branch information
raidensakura committed Dec 23, 2023
1 parent 63bc146 commit 51d90fe
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
FROM python:3.10
FROM python:3.11-alpine as base

RUN apt update && apt install -y g++ git && pip install --upgrade pip
RUN apk add --no-cache \
# cairosvg dependencies
cairo-dev cairo cairo-tools \
# pillow dependencies
jpeg-dev zlib-dev freetype-dev lcms2-dev \
&& adduser -D -h /home/modmail -g 'Modmail' modmail

ENV VIRTUAL_ENV=/home/modmail/.venv
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

RUN useradd modmail
USER modmail
WORKDIR /home/modmail

RUN pip install --user pipenv
FROM base as builder

RUN apk add build-base libffi-dev

USER modmail

RUN python -m venv $VIRTUAL_ENV

COPY --chown=modmail:modmail requirements.txt .
RUN pip install --upgrade pip setuptools && \
pip install -r requirements.txt

ENV PATH="/home/modmail/.local/bin:${PATH}"
FROM base as runtime

COPY --chown=modmail:modmail Pipfile Pipfile.lock ./
RUN pipenv install
# copy the entire venv
COPY --from=builder --chown=modmail:modmail $VIRTUAL_ENV $VIRTUAL_ENV

# copy repository files
COPY --chown=modmail:modmail . .

# this disables the internal auto-update
ENV USING_DOCKER yes

CMD ["pipenv", "run", "bot"]
CMD ["python", "bot.py"]

0 comments on commit 51d90fe

Please sign in to comment.