Amal Nimmy Lal commited on
Commit
d3acb8a
·
1 Parent(s): 35765b5

feat : Added deployable files

Browse files
.dockerignore CHANGED
@@ -17,8 +17,11 @@ env/
17
  *.egg-info/
18
  .pytest_cache/
19
 
 
20
  # Node
21
  node_modules/
 
 
22
  npm-debug.log
23
  yarn-error.log
24
 
 
17
  *.egg-info/
18
  .pytest_cache/
19
 
20
+
21
  # Node
22
  node_modules/
23
+ frontend/node_modules/
24
+ frontend/dist/
25
  npm-debug.log
26
  yarn-error.log
27
 
Dockerfile ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Stage 1: Build frontend
2
+ FROM node:18-alpine AS frontend-build
3
+ WORKDIR /build
4
+ COPY frontend/package*.json ./frontend/
5
+ COPY frontend/ ./
6
+ RUN npm ci
7
+ RUN npm run build
8
+
9
+ # Stage 2: Build backend
10
+ FROM python:3.11-slim AS backend-build
11
+ RUN useradd -m -u 1000 user
12
+ ENV HOME=/home/user \
13
+ PATH=/home/user/.local/bin:$PATH
14
+ WORKDIR /home/user/app
15
+ RUN apt-get update && apt-get install -y gcc && rm -rf /var/lib/apt/lists/*
16
+ COPY backend/requirements.txt /tmp/requirements.txt
17
+ RUN pip install --no-cache-dir -r /tmp/requirements.txt
18
+ COPY backend/ /home/user/app
19
+ COPY --from=frontend-build /build/dist /home/user/app/frontend_dist
20
+ COPY backend/entrypoint.sh /home/user/app/entrypoint.sh
21
+ RUN chmod +x /home/user/app/entrypoint.sh || true
22
+ RUN mkdir -p /data && chmod 700 /data
23
+ USER user
24
+ RUN pip install --no-cache-dir --upgrade pip
25
+
26
+ # Stage 3: Final image with nginx and supervisord
27
+ FROM python:3.11-slim
28
+ RUN apt-get update && apt-get install -y nginx supervisor gcc && rm -rf /var/lib/apt/lists/*
29
+ RUN useradd -m -u 1000 user
30
+ ENV HOME=/home/user \
31
+ PATH=/home/user/.local/bin:$PATH
32
+ WORKDIR /home/user/app
33
+ COPY --from=backend-build /home/user/app /home/user/app
34
+ COPY --from=backend-build /data /data
35
+ COPY nginx.conf /etc/nginx/nginx.conf
36
+ COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
37
+ RUN chmod +x /home/user/app/entrypoint.sh || true
38
+ RUN mkdir -p /data && chmod 700 /data
39
+ USER user
40
+ EXPOSE 8000 80
41
+ ENTRYPOINT ["/home/user/app/entrypoint.sh"]
42
+ CMD ["supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
README.md CHANGED
@@ -4,6 +4,7 @@ emoji: ⚡
4
  colorFrom: red
5
  colorTo: indigo
6
  sdk: docker
 
7
  pinned: false
8
  license: mit
9
  short_description: Semantic, shared AI project memory.
 
4
  colorFrom: red
5
  colorTo: indigo
6
  sdk: docker
7
+ app_port: 80
8
  pinned: false
9
  license: mit
10
  short_description: Semantic, shared AI project memory.
backend/.env.example ADDED
File without changes
backend/Dockerfile CHANGED
@@ -1,28 +1,43 @@
1
- # Backend Dockerfile
2
  FROM python:3.11-slim
3
 
4
- # Set working directory
5
- WORKDIR /app
6
 
7
- # Install system dependencies
 
 
 
 
 
 
 
8
  RUN apt-get update && apt-get install -y \
9
  gcc \
10
  && rm -rf /var/lib/apt/lists/*
11
 
12
  # Copy requirements first for better caching
13
- COPY requirements.txt .
 
 
 
 
 
 
 
 
 
14
 
15
- # Install Python dependencies
16
- RUN pip install --no-cache-dir -r requirements.txt
17
 
18
- # Copy application code
19
- COPY . .
20
 
21
- # Create directory for database
22
- RUN mkdir -p /app/data
23
 
24
- # Expose port
25
  EXPOSE 8000
26
 
27
- # Run the application
28
  CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
 
 
1
  FROM python:3.11-slim
2
 
3
+ # Create a non-root user with UID 1000 (matches HF Spaces runtime)
4
+ RUN useradd -m -u 1000 user
5
 
6
+ # Set HOME and include user's local bin in PATH
7
+ ENV HOME=/home/user \
8
+ PATH=/home/user/.local/bin:$PATH
9
+
10
+ # Set working directory early to avoid permission issues
11
+ WORKDIR $HOME/app
12
+
13
+ # Install system dependencies as root
14
  RUN apt-get update && apt-get install -y \
15
  gcc \
16
  && rm -rf /var/lib/apt/lists/*
17
 
18
  # Copy requirements first for better caching
19
+ COPY requirements.txt /tmp/requirements.txt
20
+
21
+ # Install Python dependencies (system-wide)
22
+ RUN pip install --no-cache-dir -r /tmp/requirements.txt
23
+
24
+ # Copy the application and set ownership to 'user' at copy time to avoid expensive chowns
25
+ COPY --chown=user:user . $HOME/app
26
+
27
+ # Ensure entrypoint is executable (no-op if missing)
28
+ RUN chmod +x $HOME/app/entrypoint.sh || true
29
 
30
+ # Create /data directory (runtime-mounted on HF Spaces) with safe permissions
31
+ RUN mkdir -p /data && chmod 700 /data
32
 
33
+ # Switch to non-root user for subsequent steps and runtime
34
+ USER user
35
 
36
+ # Upgrade pip in user's environment
37
+ RUN pip install --no-cache-dir --upgrade pip
38
 
39
+ # Expose the port and set entrypoint to prepare /data at runtime
40
  EXPOSE 8000
41
 
42
+ ENTRYPOINT ["/home/user/app/entrypoint.sh"]
43
  CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
backend/entrypoint.sh ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/sh
2
+ set -e
3
+
4
+ # Ensure /data exists and has safe permissions. On HF Spaces /data is mounted at runtime when
5
+ # persistent storage is enabled. Creating it here is harmless for local runs.
6
+ mkdir -p /data
7
+ chmod 700 /data || true
8
+
9
+ # Execute the command (or CMD) passed to the container
10
+ exec "$@"
nginx.conf ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ user nginx;
2
+ worker_processes auto;
3
+ error_log /var/log/nginx/error.log warn;
4
+ pid /var/run/nginx.pid;
5
+
6
+ # events block
7
+ events {
8
+ worker_connections 1024;
9
+ }
10
+
11
+ http {
12
+ include /etc/nginx/mime.types;
13
+ default_type application/octet-stream;
14
+ sendfile on;
15
+ keepalive_timeout 65;
16
+
17
+ server {
18
+ listen 80;
19
+ server_name localhost;
20
+
21
+ # Serve frontend static files
22
+ location / {
23
+ root /home/user/app/frontend_dist;
24
+ try_files $uri $uri/ /index.html;
25
+ }
26
+
27
+ # Proxy API requests to backend
28
+ location /api/ {
29
+ proxy_pass http://127.0.0.1:8000/api/;
30
+ proxy_set_header Host $host;
31
+ proxy_set_header X-Real-IP $remote_addr;
32
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
33
+ proxy_set_header X-Forwarded-Proto $scheme;
34
+ }
35
+ }
36
+ }
supervisord.conf ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [supervisord]
2
+ nodaemon=true
3
+
4
+ [program:nginx]
5
+ command=/usr/sbin/nginx -g 'daemon off;'
6
+ autostart=true
7
+ autorestart=true
8
+
9
+ [program:uvicorn]
10
+ command=uvicorn app.main:app --host 0.0.0.0 --port 8000
11
+ directory=/home/user/app
12
+ autostart=true
13
+ autorestart=true
14
+ user=user