File size: 2,819 Bytes
35c4df7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# 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"]