Spaces:
Sleeping
Sleeping
| # Use Node.js 18 for better compatibility | |
| FROM node:18 | |
| # Set working directory | |
| WORKDIR /app | |
| # Install system dependencies | |
| RUN apt-get update && apt-get install -y \ | |
| python3 \ | |
| python3-pip \ | |
| python3-venv \ | |
| curl \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Create and activate virtual environment for Python packages | |
| RUN python3 -m venv /opt/venv | |
| ENV PATH="/opt/venv/bin:$PATH" | |
| # Install Python dependencies for document processing | |
| RUN pip install pypdf python-docx requests | |
| # Copy all source code first | |
| COPY . . | |
| # Install frontend dependencies | |
| RUN npm install | |
| # Install backend dependencies if backend exists | |
| RUN if [ -d "./backend" ] && [ -f "./backend/package.json" ]; then cd backend && npm install; fi | |
| # Build the Svelte application | |
| RUN npm run build | |
| # Make /app directory writable for Vite timestamp files | |
| RUN chmod -R 777 /app | |
| # Expose ports | |
| EXPOSE 7860 | |
| EXPOSE 3000 | |
| EXPOSE 5001 | |
| # Health check | |
| HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ | |
| CMD curl -f http://localhost:7860/ || exit 1 | |
| # Create a simple startup script | |
| RUN echo '#!/bin/bash\n\ | |
| set -e\n\ | |
| export PATH="/opt/venv/bin:$PATH"\n\ | |
| export VITE_CJS_TRACE=false\n\ | |
| export VITE_CJS_IGNORE_WARNING=true\n\ | |
| \n\ | |
| # Create tmp directory for Vite cache with proper permissions\n\ | |
| mkdir -p /tmp/.vite\n\ | |
| chmod 777 /tmp/.vite\n\ | |
| \n\ | |
| echo "===== Application Startup at $(date +"%Y-%m-%d %H:%M:%S") ====="\n\ | |
| echo ""\n\ | |
| echo "Starting SEDNA RFP System..."\n\ | |
| \n\ | |
| # Start backend if it exists\n\ | |
| if [ -d "./backend" ] && [ -f "./backend/server.js" ]; then\n\ | |
| echo "Starting backend server on port 5001..."\n\ | |
| cd /app/backend && node server.js &\n\ | |
| BACKEND_PID=$!\n\ | |
| echo "Backend PID: $BACKEND_PID"\n\ | |
| \n\ | |
| # Wait for backend to be ready\n\ | |
| echo "Waiting for backend to be ready..."\n\ | |
| for i in {1..30}; do\n\ | |
| if curl -f http://localhost:5001/api/health > /dev/null 2>&1; then\n\ | |
| echo "β Backend is ready!"\n\ | |
| break\n\ | |
| fi\n\ | |
| echo "Waiting for backend... ($i/30)"\n\ | |
| sleep 2\n\ | |
| done\n\ | |
| cd /app\n\ | |
| fi\n\ | |
| \n\ | |
| # Start frontend on port 7860 (HF Spaces default)\n\ | |
| echo "Starting frontend server on port 7860..."\n\ | |
| npx vite preview --host 0.0.0.0 --port 7860 --strictPort false &\n\ | |
| FRONTEND_PID=$!\n\ | |
| echo "Frontend PID: $FRONTEND_PID"\n\ | |
| \n\ | |
| # Wait a bit for frontend to start\n\ | |
| sleep 5\n\ | |
| \n\ | |
| echo ""\n\ | |
| echo "β Application started successfully!"\n\ | |
| echo "π‘ Frontend: http://0.0.0.0:7860"\n\ | |
| echo "π§ Backend: http://0.0.0.0:5001"\n\ | |
| echo "π€ AI Model: meta-llama/Llama-2-13b-chat-hf"\n\ | |
| echo ""\n\ | |
| \n\ | |
| # Keep container running and forward signals\n\ | |
| wait $FRONTEND_PID\n\ | |
| ' > /app/start.sh && chmod +x /app/start.sh | |
| # Start the application | |
| CMD ["/app/start.sh"] |