bhuvanmdev commited on
Commit
77e57ab
·
verified ·
1 Parent(s): 1528d4d

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +68 -46
Dockerfile CHANGED
@@ -1,68 +1,90 @@
 
1
  FROM python:3.13-bookworm
2
 
3
- # Install system dependencies
4
- # Use the headless version of openjdk-17, which is standard for server environments
5
- RUN apt-get update && \
6
- apt-get install -y git curl openjdk-17-jre-headless nginx netcat-traditional unzip && \
7
- rm -rf /var/lib/apt/lists/*
 
 
8
 
9
- # Set JAVA_HOME (Good practice, though often not strictly necessary if Java is in the PATH)
10
- ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
 
 
 
 
 
 
 
 
 
11
 
12
- # Download and install Neo4j Community Edition
13
- ENV NEO4J_VERSION=5.15.0
14
- RUN curl -fsSL https://dist.neo4j.org/neo4j-community-5.15.0-unix.tar.gz -o neo4j.tar.gz && \
15
- tar -xzf neo4j.tar.gz && \
16
- mv neo4j-community-5.15.0 /neo4j && \
17
  rm neo4j.tar.gz
18
 
19
- # Download and install the APOC plugin for Neo4j
20
- RUN curl -fsSL https://github.com/neo4j/apoc/releases/download/5.15.0/apoc-5.15.0-core.jar -o /neo4j/plugins/apoc.jar
 
21
 
22
- # Set workdir
23
  WORKDIR /app
24
 
25
- RUN pwd
26
- # === Step 2.2: USE THE BUILD ARGUMENT IN YOUR CLONE COMMAND ===
27
- # Clone the project using the token for authentication
28
  RUN git clone https://github.com/bhuvanmdev/graph-rag-agent.git /app
29
 
30
- # Create directories for Neo4j data and logs
31
- RUN mkdir -p /app/neo4j_data /app/neo4j_logs
 
32
 
33
  # === Correct Neo4j Configuration ===
34
- RUN sed -i 's/#server.default_listen_address=127.0.0.1/server.default_listen_address=0.0.0.0/' /neo4j/conf/neo4j.conf && \
35
- sed -i 's|#dbms.directories.data=data|dbms.directories.data=/app/neo4j_data|' /neo4j/conf/neo4j.conf && \
36
- sed -i 's|#dbms.directories.logs=logs|dbms.directories.logs=/app/neo4j_logs|' /neo4j/conf/neo4j.conf && \
37
- echo 'dbms.security.auth_enabled=false' >> /neo4j/conf/neo4j.conf
38
-
39
- # Install Python dependencies
40
- RUN pip install --upgrade pip && \
41
- pip install -r requirements.txt
42
-
43
- # Install git-lfs, pull LFS files, and unzip. This will now work because the repo
44
- # was cloned with credentials.
45
- # RUN apt-get update && \
46
- # apt-get install -y --no-install-recommends git-lfs unzip && \
47
- # git lfs install && \
48
- # git lfs pull && \
49
- # unzip neo4j_data.zip && \
50
- # rm -rf /var/lib/apt/lists/*
51
 
 
 
52
  COPY neo4j_data.zip /app/neo4j_data.zip
53
- RUN unzip neo4j_data.zip
54
- # Move the unzipped data
55
- RUN mv /app/neo4j_data/* /neo4j/data/ && mv /app/neo4j_logs/* /neo4j/logs/
 
 
 
 
 
 
56
 
57
- # Copy Nginx config and run script
 
 
 
 
 
 
58
  RUN mv /app/nginx.conf /etc/nginx/nginx.conf
 
 
 
 
 
 
 
59
  RUN chmod +x /app/scripts/run.sh
60
 
61
- # Expose HTTP (Nginx), Neo4j, and Gradio ports
62
- EXPOSE 8080
63
 
64
- # Set Neo4j Home
65
- ENV NEO4J_HOME=/neo4j
66
 
67
- # Entrypoint: Start all services
68
  ENTRYPOINT ["/app/scripts/run.sh"]
 
1
+ # Start from a stable Python base image
2
  FROM python:3.13-bookworm
3
 
4
+ # Use ARG for versions to easily update them
5
+ ARG NEO4J_VERSION=5.15.0
6
+
7
+ # Set Environment Variables
8
+ ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64 \
9
+ NEO4J_HOME=/neo4j \
10
+ PATH="$PATH:/neo4j/bin"
11
 
12
+ # Install system dependencies as root
13
+ # Using --no-install-recommends to keep the image smaller
14
+ RUN apt-get update && \
15
+ apt-get install -y --no-install-recommends \
16
+ git \
17
+ curl \
18
+ openjdk-17-jre-headless \
19
+ nginx \
20
+ netcat-traditional \
21
+ unzip \
22
+ && rm -rf /var/lib/apt/lists/*
23
 
24
+ # Download and install Neo4j Community Edition as root
25
+ RUN curl -fsSL "https://dist.neo4j.org/neo4j-community-${NEO4J_VERSION}-unix.tar.gz" -o neo4j.tar.gz && \
26
+ tar -xzf neo4j.tar.gz -C / && \
27
+ mv "/neo4j-community-${NEO4J_VERSION}" "${NEO4J_HOME}" && \
 
28
  rm neo4j.tar.gz
29
 
30
+ # Create plugins directory and download the APOC plugin
31
+ RUN mkdir -p ${NEO4J_HOME}/plugins
32
+ RUN curl -fsSL "https://github.com/neo4j/apoc/releases/download/${NEO4J_VERSION}/apoc-${NEO4J_VERSION}-core.jar" -o "${NEO4J_HOME}/plugins/apoc.jar"
33
 
34
+ # Set the working directory
35
  WORKDIR /app
36
 
37
+ # Clone the project repository.
 
 
38
  RUN git clone https://github.com/bhuvanmdev/graph-rag-agent.git /app
39
 
40
+ # Install Python dependencies before creating the non-root user
41
+ RUN pip install --no-cache-dir --upgrade pip && \
42
+ pip install --no-cache-dir -r requirements.txt
43
 
44
  # === Correct Neo4j Configuration ===
45
+ # Create directories first, then configure Neo4j to use them.
46
+ RUN mkdir -p /app/neo4j_data /app/neo4j_logs
47
+ RUN sed -i 's/#server.default_listen_address=127.0.0.1/server.default_listen_address=0.0.0.0/' ${NEO4J_HOME}/conf/neo4j.conf && \
48
+ sed -i 's|#dbms.directories.data=data|dbms.directories.data=/app/neo4j_data|' ${NEO4J_HOME}/conf/neo4j.conf && \
49
+ sed -i 's|#dbms.directories.logs=logs|dbms.directories.logs=/app/neo4j_logs|' ${NEO4J_HOME}/conf/neo4j.conf && \
50
+ echo 'dbms.security.auth_enabled=false' >> ${NEO4J_HOME}/conf/neo4j.conf && \
51
+ echo 'dbms.security.procedures.unrestricted=apoc.*' >> ${NEO4J_HOME}/conf/neo4j.conf
 
 
 
 
 
 
 
 
 
 
52
 
53
+ # === Correctly Prepare and Place Data ===
54
+ # The neo4j_data.zip file should be in the same directory as your Dockerfile
55
  COPY neo4j_data.zip /app/neo4j_data.zip
56
+ # Unzip the data into a temporary directory first to inspect its structure
57
+ RUN unzip /app/neo4j_data.zip -d /app && \
58
+ rm -rf /app/neo4j_data.zip
59
+ # RUN mkdir -p /app/temp_unzip && unzip /app/neo4j_data.zip -d /app/temp_unzip
60
+ # Assuming the zip file contains 'neo4j_data' and 'neo4j_logs' folders,
61
+ # move their *contents* to the correct final destination.
62
+ # RUN mv /app/temp_unzip/neo4j_data/* /app/neo4j_data/ && \
63
+ # mv /app/temp_unzip/neo4j_logs/* /app/neo4j_logs/ && \
64
+ # rm -rf /app/temp_unzip /app/neo4j_data.zip
65
 
66
+ # Create a non-root user 'user' with UID 1000 as required by Hugging Face Spaces
67
+ RUN useradd -m -u 1000 user
68
+ ENV HOME=/home/user
69
+
70
+ # === Configure Nginx ===
71
+ RUN mkdir -p /var/lib/nginx/body /var/log/nginx
72
+ # Move the nginx.conf from the cloned repo to its destination
73
  RUN mv /app/nginx.conf /etc/nginx/nginx.conf
74
+
75
+ # === Set Final Permissions ===
76
+ # This is the most critical step to prevent runtime errors.
77
+ # Change ownership of all application, database, and Nginx directories to the non-root user.
78
+ RUN chown -R user:user /app ${NEO4J_HOME} /var/lib/nginx /var/log/nginx /etc/nginx/nginx.conf
79
+
80
+ # Make the startup script executable
81
  RUN chmod +x /app/scripts/run.sh
82
 
83
+ # Switch to the non-root user for runtime
84
+ USER user
85
 
86
+ # Expose the port Nginx will listen on
87
+ EXPOSE 8080
88
 
89
+ # Entrypoint to start all services
90
  ENTRYPOINT ["/app/scripts/run.sh"]