MongoDB / Dockerfile
Zok213
Add build version label to Dockerfile to enforce rebuilds when necessary
9c1cc8f
FROM python:3.10-slim
# Set working directory
WORKDIR /app
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PORT=7860
# Add build version to force rebuild when needed
LABEL build_version="1.0.1"
# Install only the required system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
curl \
&& rm -rf /var/lib/apt/lists/*
# Copy requirements first to leverage Docker caching
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy mandatory application files
COPY app.py db_connector.py ./
# Create placeholder files for optional files
RUN touch .env.example
RUN touch .dockerignore
RUN touch .gitignore
RUN echo "# MongoDB Telegram Bot API" > README.md
# Create logs directory with proper permissions
RUN mkdir -p /app/logs && \
touch /app/app.log && \
chmod 666 /app/app.log
# Health check
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
CMD curl -f http://localhost:7860/health || exit 1
# Start the application with uvicorn
CMD uvicorn app:app --host 0.0.0.0 --port ${PORT}