Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Docker file permission issue #3323

Merged
merged 4 commits into from
May 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 30 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
FROM python:3.10 as py
FROM python:3.11-slim-bookworm as base

FROM py as build
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 --shell /usr/sbin/nologin --create-home -d /opt/modmail modmail

RUN apt update && apt install -y g++ git
FROM base as builder

COPY requirements.txt /
RUN pip install --prefix=/inst -U -r /requirements.txt
COPY requirements.txt .

FROM py
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 --from=build /inst /usr/local
FROM base

ENV USING_DOCKER yes
RUN useradd --system --no-create-home modmail
USER modmail
# 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 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

WORKDIR /modmailbot
CMD ["python", "bot.py"]
COPY --chown=modmail:modmail . /modmailbot
Loading