File size: 2,224 Bytes
3786a3f
db4d559
 
3786a3f
 
db4d559
 
 
 
 
 
 
 
430b5be
 
 
db4d559
 
 
 
 
 
 
 
 
 
feca495
430b5be
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
feca495
3786a3f
 
 
 
 
 
 
 
 
 
db4d559
 
3786a3f
 
 
 
430b5be
 
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
FROM python:3.11-slim AS base

# Prevent Python from writing .pyc files and enable unbuffered logging
ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1

WORKDIR /app

# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    libpq-dev \
    curl \
    wget \
    procps \
    default-jre \
    && rm -rf /var/lib/apt/lists/*

# Install python dependencies
COPY requirements.txt /app/
RUN pip install --no-cache-dir --upgrade pip && \
    pip install --no-cache-dir -r requirements.txt

# Copy backend codebase
COPY . /app/

# Create volume directories so they exist with the correct permissions in the image
RUN mkdir -p /app/chroma_db /app/uploaded_documents /app/logs /app/db /app/db/neo4j_data

# Download and setup Neo4j Community Edition
RUN wget -q -O neo4j.tar.gz "https://neo4j.com/artifact.php?name=neo4j-community-5.23.0-unix.tar.gz" \
    && tar -xf neo4j.tar.gz \
    && mv neo4j-community-5.23.0 /app/neo4j \
    && rm neo4j.tar.gz

# Configure Neo4j to run within resource limits and set directories
RUN echo "server.directories.data=/app/db/neo4j_data" >> /app/neo4j/conf/neo4j.conf \
    && echo "server.memory.heap.initial_size=512m" >> /app/neo4j/conf/neo4j.conf \
    && echo "server.memory.heap.max_size=1G" >> /app/neo4j/conf/neo4j.conf \
    && echo "server.memory.pagecache.size=1G" >> /app/neo4j/conf/neo4j.conf

# Set default password (matches backend settings)
RUN /app/neo4j/bin/neo4j-admin dbms set-initial-password "password"

# Ensure start script is executable
RUN chmod +x /app/start.sh

# Collect static files (no-op if no static files, but ready for future)
RUN python manage.py collectstatic --noinput 2>/dev/null || true

# Create non-root user for security
RUN groupadd -r appuser && useradd -r -g appuser -d /app -s /sbin/nologin appuser \
    && chown -R appuser:appuser /app

# Switch to non-root user
USER appuser

EXPOSE 8000

# Health check against the /api/health/ endpoint
HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \
    CMD curl -f http://localhost:8000/api/health/ || exit 1

# Production command using custom startup script to run both Neo4j and Gunicorn
CMD ["/app/start.sh"]