aki-008 commited on
Commit
3e0360c
·
1 Parent(s): 1ade6ae

fix: cleanup large files and update deployment scripts

Browse files
Files changed (4) hide show
  1. .gitignore +20 -0
  2. Backend/app/config.py +0 -8
  3. Dockerfile +14 -6
  4. start.sh +17 -9
.gitignore CHANGED
@@ -243,3 +243,23 @@ __pycache__/
243
  /node_modules
244
  /Frontend/node_modules
245
  /Frontend/dist
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
243
  /node_modules
244
  /Frontend/node_modules
245
  /Frontend/dist
246
+
247
+ # Ignore Database & Vector Stores
248
+ chroma_store/
249
+ Backend/chroma_store/
250
+ *.sqlite3
251
+ *.bin
252
+ *.db
253
+
254
+ # Ignore Large Files/Documents
255
+ vector_db/
256
+ *.pdf
257
+ img/
258
+ *.png
259
+
260
+ # Ignore Python Cache & Envs
261
+ __pycache__/
262
+ *.pyc
263
+ .env
264
+ venv/
265
+ .venv/
Backend/app/config.py CHANGED
@@ -18,14 +18,6 @@ class Settings(BaseSettings):
18
 
19
  GROQ_API_KEY: str
20
 
21
- # Add Vapi Settings
22
- VAPI_PRIVATE_KEY: str
23
- VAPI_PUBLIC_KEY: str
24
- VAPI_ASSISTANT_ID: str
25
-
26
- VAPI_ASSISTANT_ID: str = "your-vapi-assistant-id"
27
- VAPI_PRIVATE_KEY: str
28
- VAPI_PUBLIC_KEY: str
29
 
30
  VAPI_ASSISTANT_ID: str = "your-vapi-assistant-id"
31
  VAPI_PRIVATE_KEY: str
 
18
 
19
  GROQ_API_KEY: str
20
 
 
 
 
 
 
 
 
 
21
 
22
  VAPI_ASSISTANT_ID: str = "your-vapi-assistant-id"
23
  VAPI_PRIVATE_KEY: str
Dockerfile CHANGED
@@ -4,19 +4,24 @@ 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
@@ -29,13 +34,16 @@ 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"]
 
4
  COPY Frontend/package*.json ./
5
  RUN npm install
6
  COPY Frontend/ .
7
+ RUN npm run build [cite: 19]
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 postgresql-client \
15
  build-essential portaudio19-dev libpq-dev git \
16
+ && rm -rf /var/lib/apt/lists/*
17
+
18
+ # Add PostgreSQL bin directory to PATH for non-root user (adjust version if necessary)
19
+ ENV PATH="/usr/lib/postgresql/15/bin:$PATH"
20
 
21
  # Setup non-root user for HF Spaces (UID 1000)
22
  RUN useradd -m -u 1000 user
23
+ # Create a data directory for PostgreSQL owned by the non-root user
24
+ RUN mkdir -p /home/user/postgres_data && chown -R user:user /home/user/postgres_data
25
  WORKDIR /home/user/app
26
 
27
  # Copy Backend and install requirements
 
34
  COPY --chown=user --from=build-stage /app/frontend/dist /usr/share/nginx/html
35
 
36
  # Copy Configs
37
+ COPY --chown=user nginx.conf /etc/nginx/sites-available/default [cite: 20] /
38
+ COPY --chown=user start.sh ./start.sh [cite: 20] /
39
+ RUN chmod +x ./start.sh [cite: 20]
40
 
41
  # Environment variables
42
  ENV PORT=7860
43
  EXPOSE 7860
44
 
45
+ # Set the non-root user as the default user for the container
46
+ USER user
47
+
48
  # Run the startup script
49
  CMD ["./start.sh"]
start.sh CHANGED
@@ -1,18 +1,26 @@
1
  #!/bin/bash
2
- # 1. Start PostgreSQL
3
- service postgresql start
 
 
 
 
 
 
 
 
 
4
 
5
  # Wait for service to initialize
6
  sleep 5
7
 
8
- # Execute database setup commands
9
- sudo -u postgres psql -c "CREATE USER prepuser WITH PASSWORD 'password';"
10
- sudo -u postgres psql -c "CREATE DATABASE studentdb OWNER prepuser;"
11
 
12
- export DATABASE_URL="postgresql+psycopg2://prepuser:password@127.0.0.1:5432/studentdb"
13
- export chroma_host="127.0.0.1"
14
- export chroma_port="8001" # Assuming you run ChromaDB on this port in start.sh
15
- export chroma_collection="prepai_collection"
16
 
17
  # 2. Start ChromaDB (in-process or separate port)
18
  chroma run --host 0.0.0.0 --port 8080 --path ./chroma_store &
 
1
  #!/bin/bash
2
+ # 1. Initialize & Start Local PostgreSQL (as non-root user)
3
+ export PGDATA=/home/user/postgres_data
4
+
5
+ if [ ! -d "$PGDATA/base" ]; then
6
+ echo "Initializing database..."
7
+ initdb -D "$PGDATA"
8
+ fi
9
+
10
+ echo "Starting PostgreSQL..."
11
+ # Start server in the background
12
+ pg_ctl -D "$PGDATA" -l /home/user/app/postgres.log start
13
 
14
  # Wait for service to initialize
15
  sleep 5
16
 
17
+ # Set environment variable for psql to use correct auth (needed for local startup)
18
+ export PGPASSWORD=password
 
19
 
20
+ # Execute database setup commands (no sudo needed, run as current user)
21
+ # Attempt to create the user and database if they don't exist
22
+ psql -h 127.0.0.1 -p 5432 -U postgres -d postgres -c "CREATE USER prepuser WITH PASSWORD 'password';" || true
23
+ createdb studentdb -h 127.0.0.1 -p 5432 -U postgres || true
24
 
25
  # 2. Start ChromaDB (in-process or separate port)
26
  chroma run --host 0.0.0.0 --port 8080 --path ./chroma_store &