feat: Add Dockerfile and .dockerignore for improved containerization

This commit is contained in:
Andre Beging
2025-10-08 15:54:28 +02:00
parent f3b30d46c9
commit 8bb8cbfde7
2 changed files with 48 additions and 9 deletions

23
.dockerignore Normal file
View File

@@ -0,0 +1,23 @@
.git
.gitignore
**/__pycache__/
*.py[cod]
*.pyo
*.pyd
*.swp
*.swo
*.log
.env
venv/
.venv/
env/
ENV/
.build/
build/
dist/
node_modules/
__pycache__/
.testresults/
.pytest_cache/
.coverage
.mypy_cache/

View File

@@ -1,4 +1,19 @@
FROM python:3.11-slim
FROM python:3.11-alpine AS builder
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1
WORKDIR /app
RUN apk add --no-cache \
build-base \
libffi-dev \
openssl-dev
COPY requirements.txt ./
RUN pip install --no-cache-dir --prefix=/install -r requirements.txt
FROM python:3.11-alpine AS runner
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
@@ -6,18 +21,19 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
WORKDIR /app
# Install system dependencies required by Telethon and FastAPI
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
libffi-dev \
&& rm -rf /var/lib/apt/lists/*
RUN apk add --no-cache \
libffi \
libstdc++ \
openssl \
&& adduser -D appuser
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY --from=builder /install /usr/local
COPY app ./app
RUN mkdir -p data
RUN mkdir -p data && chown -R appuser:appuser /app
USER appuser
EXPOSE 8000
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]