aki-008
commited on
Commit
·
6f693aa
1
Parent(s):
b916395
feat: spaces deployement
Browse files- Dockerfile +41 -0
- nginx.conf +15 -0
- start.sh +15 -0
Dockerfile
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# --- Stage 1: Build Frontend ---
|
| 2 |
+
FROM node:20-alpine as build-stage
|
| 3 |
+
WORKDIR /app/frontend
|
| 4 |
+
COPY Frontend/package*.json ./
|
| 5 |
+
RUN npm install
|
| 6 |
+
COPY Frontend/ .
|
| 7 |
+
RUN npm run build
|
| 8 |
+
|
| 9 |
+
# --- Stage 2: Runtime ---
|
| 10 |
+
FROM python:3.12-slim
|
| 11 |
+
|
| 12 |
+
# Install system dependencies (Nginx, PostgreSQL, PortAudio)
|
| 13 |
+
RUN apt-get update && apt-get install -y \
|
| 14 |
+
nginx postgresql postgresql-contrib \
|
| 15 |
+
build-essential portaudio19-dev libpq-dev git \
|
| 16 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 17 |
+
|
| 18 |
+
# Setup non-root user for HF Spaces (UID 1000)
|
| 19 |
+
RUN useradd -m -u 1000 user
|
| 20 |
+
WORKDIR /home/user/app
|
| 21 |
+
|
| 22 |
+
# Copy Backend and install requirements
|
| 23 |
+
COPY --chown=user Backend/requirements.txt ./Backend/
|
| 24 |
+
RUN pip install --no-cache-dir --upgrade pip && \
|
| 25 |
+
pip install --no-cache-dir torch --index-url https://download.pytorch.org/whl/cpu && \
|
| 26 |
+
pip install --no-cache-dir -r Backend/requirements.txt
|
| 27 |
+
|
| 28 |
+
COPY --chown=user Backend/ ./Backend/
|
| 29 |
+
COPY --chown=user --from=build-stage /app/frontend/dist /usr/share/nginx/html
|
| 30 |
+
|
| 31 |
+
# Copy Configs
|
| 32 |
+
COPY --chown=user nginx.conf /etc/nginx/sites-available/default
|
| 33 |
+
COPY --chown=user start.sh ./start.sh
|
| 34 |
+
RUN chmod +x ./start.sh
|
| 35 |
+
|
| 36 |
+
# Environment variables
|
| 37 |
+
ENV PORT=7860
|
| 38 |
+
EXPOSE 7860
|
| 39 |
+
|
| 40 |
+
# Run the startup script
|
| 41 |
+
CMD ["./start.sh"]
|
nginx.conf
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
server {
|
| 2 |
+
listen 7860;
|
| 3 |
+
|
| 4 |
+
location / {
|
| 5 |
+
root /usr/share/nginx/html;
|
| 6 |
+
index index.html;
|
| 7 |
+
try_files $uri $uri/ /index.html;
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
location /api/v1/ {
|
| 11 |
+
proxy_pass http://localhost:8000/api/v1/;
|
| 12 |
+
proxy_set_header Host $host;
|
| 13 |
+
proxy_set_header X-Real-IP $remote_addr;
|
| 14 |
+
}
|
| 15 |
+
}
|
start.sh
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# 1. Start PostgreSQL
|
| 3 |
+
service postgresql start
|
| 4 |
+
su - postgres -c "psql -c \"CREATE USER user WITH PASSWORD 'password';\""
|
| 5 |
+
su - postgres -c "psql -c \"CREATE DATABASE studentdb OWNER user;\""
|
| 6 |
+
|
| 7 |
+
# 2. Start ChromaDB (in-process or separate port)
|
| 8 |
+
chroma run --host 0.0.0.0 --port 8080 --path ./chroma_store &
|
| 9 |
+
|
| 10 |
+
# 3. Start Nginx
|
| 11 |
+
service nginx start
|
| 12 |
+
|
| 13 |
+
# 4. Start Backend
|
| 14 |
+
cd Backend
|
| 15 |
+
python run.py
|