File size: 3,517 Bytes
33f7667 04b5ef9 33f7667 ccf3c35 e2d418f ea717de 33f7667 a12e15f ccf3c35 e2d418f ccf3c35 33f7667 ccf3c35 a12e15f 33f7667 04b5ef9 74f5beb 33f7667 ccf3c35 988c14d 04b5ef9 e2d418f 3c172b1 33f7667 ce1ad77 e2d418f ce1ad77 33f7667 0f239db d205cc8 0f239db d205cc8 0eac201 d205cc8 0eac201 d205cc8 0eac201 0f239db 5166602 0f239db |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
FROM python:3.11.6-slim
# Set environment variables
ENV PYTHONUNBUFFERED=1 \
PYTHONPATH="/app" \
DEBIAN_FRONTEND=noninteractive \
STREAMLIT_SERVER_ADDRESS=0.0.0.0 \
STREAMLIT_SERVER_PORT=7860
ENV PYTHONIOENCODING=utf-8
ENV LANG=C.UTF-8
ENV LC_ALL=C.UTF-8
ENV PYTHONPATH="/app"
ENV STREAMLIT_BROWSER_GATHER_USAGE_STATS=false
ENV STREAMLIT_SERVER_HEADLESS=true
# Install system dependencies
RUN apt-get update && apt-get install -y \
build-essential \
libglib2.0-0 \
libsm6 \
libxrender1 \
libxext6 \
git \
curl \
wget \
procps \
net-tools \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Create non-root user for security
RUN groupadd -r appuser && useradd -r -g appuser appuser
# Set working directory
WORKDIR /app
# Copy requirements first for better caching
COPY requirements.txt /app/
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir -r requirements.txt
# Copy path configuration first
COPY path_config.py /app/
# Copy validation script
COPY docker_validation.py /app/
# Copy project files
COPY . /app
# Create necessary directories with proper permissions for uploads
RUN mkdir -p /app/data /app/model /app/logs /app/cache /app/temp && \
mkdir -p /app/data/kaggle && \
mkdir -p /tmp/app_data /tmp/app_logs /tmp/app_cache
# Copy health check script and make it executable
COPY health_check.sh /app/
RUN chmod +x /app/health_check.sh
# Make scripts executable
RUN chmod +x /app/start.sh
# Copy initial datasets if they exist to the correct app structure
RUN if [ -d /app/data/kaggle ]; then \
echo "Kaggle datasets found in app structure"; \
chmod -R 775 /app/data/kaggle; \
fi && \
if [ -f /app/data/combined_dataset.csv ]; then \
echo "Combined dataset found in app structure"; \
chmod 664 /app/data/combined_dataset.csv; \
fi
# Set comprehensive permissions BEFORE switching users
RUN chown -R appuser:appuser /app && \
chown -R appuser:appuser /tmp/app_data /tmp/app_logs /tmp/app_cache && \
chmod -R 755 /app && \
chmod -R 777 /app/data /app/logs /app/cache /app/temp /app/model && \
chmod -R 775 /tmp/app_data /tmp/app_logs /tmp/app_cache
# Switch to non-root user AFTER setting permissions
USER appuser
# Create user-writable directories in case the above fails
RUN mkdir -p /tmp/fallback_data /tmp/fallback_logs && \
chmod 777 /tmp/fallback_data /tmp/fallback_logs
# Initialize system with the new path structure
RUN python /app/initialize_system.py
# Simple permission test using basic commands
RUN python3 -c "import sys; sys.path.append('/app'); from path_config import path_manager; print('Environment:', path_manager.environment); print('Data dir:', str(path_manager.base_paths['data'])); print('Model dir:', str(path_manager.base_paths['model']))"
# Test write permissions with a simple approach
RUN python3 -c "import sys; sys.path.append('/app'); from path_config import path_manager; from pathlib import Path; test_file = path_manager.get_data_path('test.txt'); test_file.write_text('test'); test_file.unlink(); print('Write permissions verified')" || echo "Using fallback permissions"
# Health check using the proper paths
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD /app/health_check.sh
# Expose ports
EXPOSE 7860 8000
# Set environment variable to help the app detect container environment
ENV DOCKER_CONTAINER=1
# Run the startup script
CMD ["./start.sh"] |