# Use official Python slim image FROM python:3.9-slim # Install Java Runtime Environment and build essentials RUN apt-get update && \ apt-get install -y --no-install-recommends \ default-jre \ gcc \ python3-dev \ && 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 # Set environment variables ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH \ PYTHONPATH=/home/user/app \ JAVA_HOME=/usr/lib/jvm/default-java \ _JAVA_OPTIONS="-Xmx4g" # Create the application directory and set permissions BEFORE switching users # This ensures the 'user' has full write access to their own app folder RUN mkdir -p /home/user/app && chown user:user /home/user/app WORKDIR /home/user/app # Switch to the "user" USER user # Copy the requirements file and install dependencies as the "user" COPY --chown=user requirements.txt . RUN pip install --no-cache-dir --user -r requirements.txt # Copy the rest of the application and set ownership COPY --chown=user . . # Create necessary data directories as the user RUN mkdir -p data/input data/output data/save_pdf data/raw_csv_temp data/output_process_data data/strictly_cleaned_data logs # Expose port 7860 EXPOSE 7860 # Use 'python -m uvicorn' to ensure the user-installed package is found and executable CMD ["python", "-m", "uvicorn", "telecom_anomaly.api:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1", "--timeout-keep-alive", "60"]