Ashutosh1975270 commited on
Commit
430b5be
·
1 Parent(s): 9c023b6

Configure Neo4j single container deployment

Browse files
Files changed (2) hide show
  1. backend/Dockerfile +24 -3
  2. backend/start.sh +32 -0
backend/Dockerfile CHANGED
@@ -11,6 +11,9 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
11
  build-essential \
12
  libpq-dev \
13
  curl \
 
 
 
14
  && rm -rf /var/lib/apt/lists/*
15
 
16
  # Install python dependencies
@@ -22,7 +25,25 @@ RUN pip install --no-cache-dir --upgrade pip && \
22
  COPY . /app/
23
 
24
  # Create volume directories so they exist with the correct permissions in the image
25
- RUN mkdir -p /app/chroma_db /app/uploaded_documents /app/logs /app/db
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
  # Collect static files (no-op if no static files, but ready for future)
28
  RUN python manage.py collectstatic --noinput 2>/dev/null || true
@@ -40,5 +61,5 @@ EXPOSE 8000
40
  HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \
41
  CMD curl -f http://localhost:8000/api/health/ || exit 1
42
 
43
- # Production command using gunicorn with auto-migrations
44
- CMD ["sh", "-c", "python manage.py migrate && gunicorn config.wsgi:application --bind 0.0.0.0:8000 --workers 4 --threads 2 --timeout 300 --access-logfile - --error-logfile -"]
 
11
  build-essential \
12
  libpq-dev \
13
  curl \
14
+ wget \
15
+ procps \
16
+ default-jre \
17
  && rm -rf /var/lib/apt/lists/*
18
 
19
  # Install python dependencies
 
25
  COPY . /app/
26
 
27
  # Create volume directories so they exist with the correct permissions in the image
28
+ RUN mkdir -p /app/chroma_db /app/uploaded_documents /app/logs /app/db /app/db/neo4j_data
29
+
30
+ # Download and setup Neo4j Community Edition
31
+ RUN wget -q -O neo4j.tar.gz "https://neo4j.com/artifact.php?name=neo4j-community-5.23.0-unix.tar.gz" \
32
+ && tar -xf neo4j.tar.gz \
33
+ && mv neo4j-community-5.23.0 /app/neo4j \
34
+ && rm neo4j.tar.gz
35
+
36
+ # Configure Neo4j to run within resource limits and set directories
37
+ RUN echo "server.directories.data=/app/db/neo4j_data" >> /app/neo4j/conf/neo4j.conf \
38
+ && echo "server.memory.heap.initial_size=512m" >> /app/neo4j/conf/neo4j.conf \
39
+ && echo "server.memory.heap.max_size=1G" >> /app/neo4j/conf/neo4j.conf \
40
+ && echo "server.memory.pagecache.size=1G" >> /app/neo4j/conf/neo4j.conf
41
+
42
+ # Set default password (matches backend settings)
43
+ RUN /app/neo4j/bin/neo4j-admin dbms set-initial-password "password"
44
+
45
+ # Ensure start script is executable
46
+ RUN chmod +x /app/start.sh
47
 
48
  # Collect static files (no-op if no static files, but ready for future)
49
  RUN python manage.py collectstatic --noinput 2>/dev/null || true
 
61
  HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \
62
  CMD curl -f http://localhost:8000/api/health/ || exit 1
63
 
64
+ # Production command using custom startup script to run both Neo4j and Gunicorn
65
+ CMD ["/app/start.sh"]
backend/start.sh ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -e
3
+
4
+ # Set Neo4j environment variables
5
+ export NEO4J_HOME="/app/neo4j"
6
+ export PATH="$NEO4J_HOME/bin:$PATH"
7
+
8
+ echo "Starting Neo4j database in the background..."
9
+ neo4j start
10
+
11
+ echo "Waiting for Neo4j to be ready on port 7474..."
12
+ max_retries=60
13
+ count=0
14
+ # Loop until Neo4j HTTP API responds (it will respond to a basic curl even if unauthenticated)
15
+ while ! curl -s http://localhost:7474 > /dev/null; do
16
+ count=$((count+1))
17
+ if [ $count -ge $max_retries ]; then
18
+ echo "Error: Neo4j failed to start within 60 seconds."
19
+ exit 1
20
+ fi
21
+ echo "Waiting for Neo4j... ($count/$max_retries)"
22
+ sleep 2
23
+ done
24
+
25
+ echo "Neo4j is up and running!"
26
+
27
+ echo "Running Django database migrations..."
28
+ python manage.py migrate --noinput
29
+
30
+ echo "Starting Gunicorn web server..."
31
+ # Use exec to replace the shell with gunicorn so it receives OS signals properly
32
+ exec gunicorn config.wsgi:application --bind 0.0.0.0:8000 --workers 4 --threads 2 --timeout 300 --access-logfile - --error-logfile -