FROM python:3.12-slim # Install curl for health check RUN apt-get update && apt-get install -y curl && \ apt-get clean && rm -rf /var/lib/apt/lists/* # Set up a new user named "user" with user ID 1000 RUN useradd -m -u 1000 user # Switch to the "user" user USER user # Set home to the user's home directory ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH \ PYTHONPATH=/home/user/app \ PYTHONUNBUFFERED=1 \ PYTHONDONTWRITEBYTECODE=1 ENV PYTHONPATH="$HOME/.local/lib/python3.12/site-packages:$PYTHONPATH" # Set Python path so `src.telegram_bot` is importable ENV PYTHONPATH=/home/user/app # Set the working directory to the user's home directory WORKDIR $HOME/app # Upgrade pip with user permissions RUN pip install --no-cache-dir --upgrade pip # Copy requirements first for better Docker layer caching COPY --chown=user requirements.txt $HOME/app/ # Install Python dependencies in user space RUN pip install --no-cache-dir --upgrade -r requirements.txt # Copy source code with proper ownership COPY --chown=user src/ $HOME/app/src/ # Copy the main application file COPY --chown=user main.py $HOME/app/ # Copy any additional files you need COPY --chown=user *.py $HOME/app/ COPY --chown=user .env* $HOME/app/ # Create any directories your app needs RUN mkdir -p $HOME/app/logs && \ mkdir -p $HOME/app/data # Expose port EXPOSE 7860 # Health check HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \ CMD curl --fail http://localhost:7860/health || exit 1 # Run the application when the container starts HF #CMD ["uvicorn", "src.telegram_bot:app", "--host", "0.0.0.0", "--port", "7860"] CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"] # Uncomment the line below to run the application locally #CMD ["python", "-m", "telegram_bot"]