Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +68 -46
Dockerfile
CHANGED
|
@@ -1,68 +1,90 @@
|
|
|
|
|
| 1 |
FROM python:3.13-bookworm
|
| 2 |
|
| 3 |
-
#
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
# Download and install Neo4j Community Edition
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
mv neo4j-community-5.15.0 /neo4j && \
|
| 17 |
rm neo4j.tar.gz
|
| 18 |
|
| 19 |
-
#
|
| 20 |
-
RUN
|
|
|
|
| 21 |
|
| 22 |
-
# Set
|
| 23 |
WORKDIR /app
|
| 24 |
|
| 25 |
-
|
| 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 |
-
#
|
| 31 |
-
RUN
|
|
|
|
| 32 |
|
| 33 |
# === Correct Neo4j Configuration ===
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 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 |
-
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
RUN mv /app/nginx.conf /etc/nginx/nginx.conf
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
RUN chmod +x /app/scripts/run.sh
|
| 60 |
|
| 61 |
-
#
|
| 62 |
-
|
| 63 |
|
| 64 |
-
#
|
| 65 |
-
|
| 66 |
|
| 67 |
-
# Entrypoint
|
| 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"]
|