feat: Add Dockerfile and .dockerignore for improved containerization
This commit is contained in:
23
.dockerignore
Normal file
23
.dockerignore
Normal 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/
|
||||
34
Dockerfile
34
Dockerfile
@@ -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"]
|
||||
|
||||
Reference in New Issue
Block a user