Enhance Telegram bot with database integration and API features
- Added SQLite database support with Alembic for migrations. - Implemented FastAPI for HTTP API to manage duties. - Updated configuration to include database URL and HTTP port. - Created entrypoint script for Docker to handle migrations and permissions. - Expanded command handlers to register users and display duties. - Developed a web application for calendar display of duties. - Included necessary Pydantic schemas and SQLAlchemy models for data handling. - Updated requirements.txt to include new dependencies for FastAPI and SQLAlchemy.
This commit is contained in:
33
Dockerfile
33
Dockerfile
@@ -1,18 +1,37 @@
|
||||
# Multi-stage: builder installs deps; runtime copies only site-packages and app code.
|
||||
# Single image for both dev and prod; Compose files differentiate behavior.
|
||||
|
||||
# --- Stage 1: builder (dependencies only) ---
|
||||
FROM python:3.12-slim AS builder
|
||||
WORKDIR /app
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# --- Stage 2: runtime (minimal final image) ---
|
||||
FROM python:3.12-slim
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Install dependencies
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
# Install gosu (drop privileges in entrypoint)
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends gosu \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Copy installed packages and console scripts from builder (no requirements.txt, no pip layer)
|
||||
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
|
||||
COPY --from=builder /usr/local/bin /usr/local/bin
|
||||
|
||||
# Application code
|
||||
COPY config.py main.py ./
|
||||
COPY config.py main.py alembic.ini entrypoint.sh ./
|
||||
COPY db/ ./db/
|
||||
COPY api/ ./api/
|
||||
COPY handlers/ ./handlers/
|
||||
COPY alembic/ ./alembic/
|
||||
COPY webapp/ ./webapp/
|
||||
|
||||
# Run as non-root
|
||||
RUN adduser --disabled-password --gecos "" botuser && chown -R botuser:botuser /app
|
||||
USER botuser
|
||||
# Create data dir; entrypoint runs as root, fixes perms for volume, then runs app as botuser
|
||||
RUN adduser --disabled-password --gecos "" botuser \
|
||||
&& mkdir -p /app/data && chown -R botuser:botuser /app
|
||||
|
||||
# Entrypoint runs as root: fix /app/data ownership (for volume mount), run migrations, then exec as botuser
|
||||
ENTRYPOINT ["/bin/sh", "./entrypoint.sh"]
|
||||
CMD ["python", "main.py"]
|
||||
|
||||
Reference in New Issue
Block a user