Skip to content

Commit

Permalink
Refactor Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
raidensakura committed Dec 22, 2023
1 parent d20c2fa commit 357d5cc
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,34 @@ RUN apk update && apk add git \
jpeg-dev zlib-dev && \
adduser -D -h /home/modmail -g 'Modmail' modmail

ENV PIP_DISABLE_PIP_VERSION_CHECK=1
ENV PIP_DISABLE_PIP_VERSION_CHECK=1 \
USING_DOCKER=1

WORKDIR /home/modmail

FROM base as poetry
FROM base as builder

ENV POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_IN_PROJECT=1 \
POETRY_VIRTUALENVS_CREATE=1 \
POETRY_CACHE_DIR=/tmp/poetry_cache

RUN apk add build-base libffi-dev && \
pip install -U poetry

COPY --chown=modmail:modmail poetry.lock pyproject.toml /home/modmail/
RUN python -m poetry export -o requirements.txt

FROM base as deps
RUN --mount=type=cache,target=$POETRY_CACHE_DIR poetry install --without dev --no-root

USER modmail
RUN poetry install --without dev --no-root

COPY --from=poetry /home/modmail/requirements.txt /home/modmail/
FROM base as runtime

RUN pip install -r requirements.txt --user
ENV VIRTUAL_ENV=/home/modmail/.venv \
PATH="/home/modmail/.venv/bin:$PATH"

FROM deps as runtime
COPY --from=builder --chown=modmail:modmail ${VIRTUAL_ENV} ${VIRTUAL_ENV}

ENV PATH=/home/modmail/.local/bin:$PATH
COPY --chown=modmail:modmail . .

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

0 comments on commit 357d5cc

Please sign in to comment.