Ahmedik95316's picture
Update Dockerfile
3c172b1
raw
history blame
3.04 kB
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
# 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
# The path_config.py will handle environment-specific paths
RUN mkdir -p /app/data /app/model /app/logs /app/cache /app/temp && \
chmod -R 755 /app/data /app/model /app/logs /app/cache /app/temp
# Ensure logs directory is writable
RUN chmod 777 /app/logs || echo "Could not set logs permissions, will use fallback logging"
# Make scripts executable
RUN chmod +x /app/start.sh
# Copy health check script and make it executable
COPY health_check.sh /app/
RUN chmod +x /app/health_check.sh
# Copy initial datasets if they exist to the correct app structure
# The system will use /app/data/* directly instead of copying to /tmp
RUN if [ -d /app/data/kaggle ]; then \
echo "Kaggle datasets found in app structure"; \
fi && \
if [ -f /app/data/combined_dataset.csv ]; then \
echo "Combined dataset found in app structure"; \
fi
# Initialize system with the new path structure
RUN python /app/initialize_system.py
# Test the system initialization
RUN python3 -c "\
import sys; \
sys.path.append('/app'); \
from path_config import path_manager; \
print(f'Container environment: {path_manager.environment}'); \
print(f'Base directory: {path_manager.base_paths[\"base\"]}'); \
print(f'Data directory: {path_manager.base_paths[\"data\"]}'); \
print(f'Model directory: {path_manager.base_paths[\"model\"]}'); \
critical_files = [path_manager.get_combined_dataset_path(), path_manager.get_model_file_path(), path_manager.get_vectorizer_path()]; \
[print(f'βœ… {file_path}' if file_path.exists() else f'❌ {file_path}') for file_path in critical_files]; \
print('System check completed')"
# Health check using the proper paths
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD /app/health_check.sh
# Change ownership to appuser
RUN chown -R appuser:appuser /app
# Switch to non-root user
USER appuser
# 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"]