fix: run frontend in a container

This commit is contained in:
Boris Arzentar 2024-06-23 13:24:58 +02:00
parent cb64ab14fa
commit e23faccb6a
10 changed files with 151 additions and 165 deletions

View file

@ -1,50 +1,29 @@
FROM python:3.11
FROM python:3.11-slim
# Set build argument
ARG DEBUG
ARG API_ENABLED
# Set environment variable based on the build argument
ENV DEBUG=${DEBUG}
ENV API_ENABLED=${API_ENABLED}
ENV PIP_NO_CACHE_DIR=true
ENV PATH="${PATH}:/root/.poetry/bin"
RUN pip install poetry
WORKDIR /app
COPY pyproject.toml poetry.lock /app/
RUN pip install poetry
# Create virtualenv
RUN poetry config virtualenvs.create false
# Install the dependencies
RUN poetry config virtualenvs.create false && \
poetry install --no-root --no-dev
RUN apt-get update -q && \
apt-get install -y -q \
gcc \
python3-dev \
curl \
zip \
jq \
netcat-traditional && \
pip install poetry && \
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && \
unzip -qq awscliv2.zip && \
./aws/install && \
apt-get clean && \
rm -rf \
awscliv2.zip \
/var/lib/apt/lists/* \
/tmp/* \
/var/tmp/*
WORKDIR /app
RUN poetry install --no-root --no-dev
# Set the PYTHONPATH environment variable to include the /app directory
ENV PYTHONPATH=/app
COPY cognee/ /app/cognee
COPY entrypoint.sh /app/entrypoint.sh
RUN chmod +x /app/entrypoint.sh

49
Dockerfile-old Normal file
View file

@ -0,0 +1,49 @@
FROM python:3.11
# Set build argument
ARG DEBUG
# Set environment variable based on the build argument
ENV DEBUG=${DEBUG}
ENV PIP_NO_CACHE_DIR=true
ENV PATH="${PATH}:/root/.poetry/bin"
RUN pip install poetry
WORKDIR /app
COPY pyproject.toml poetry.lock /app/
# Install the dependencies
RUN poetry config virtualenvs.create false && \
poetry install --no-root --no-dev
RUN apt-get update -q && \
apt-get install -y -q \
gcc \
python3-dev \
curl \
zip \
jq \
netcat-traditional && \
pip install poetry && \
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && \
unzip -qq awscliv2.zip && \
./aws/install && \
apt-get clean && \
rm -rf \
awscliv2.zip \
/var/lib/apt/lists/* \
/tmp/* \
/var/tmp/*
WORKDIR /app
# Set the PYTHONPATH environment variable to include the /app directory
ENV PYTHONPATH=/app
COPY cognee/ /app/cognee
COPY entrypoint.sh /app/entrypoint.sh
RUN chmod +x /app/entrypoint.sh
ENTRYPOINT ["/app/entrypoint.sh"]

View file

@ -1,30 +0,0 @@
FROM python:3.11-slim
# Set build argument
ARG DEBUG
# Set environment variable based on the build argument
ENV DEBUG=${DEBUG}
ENV PIP_NO_CACHE_DIR=true
ENV PATH="${PATH}:/root/.poetry/bin"
WORKDIR /app
COPY pyproject.toml poetry.lock /app/
RUN pip install poetry
# Create virtualenv
RUN poetry config virtualenvs.create false
# Install the dependencies
RUN poetry install --no-root --no-dev
# Set the PYTHONPATH environment variable to include the /app directory
ENV PYTHONPATH=/app
COPY cognee/ /app/cognee
COPY entrypoint-vanilla.sh /app/entrypoint-vanilla.sh
RUN chmod +x /app/entrypoint-vanilla.sh
ENTRYPOINT ["/app/entrypoint-vanilla.sh"]

View file

@ -0,0 +1,2 @@
.next
node_modules

View file

@ -1,20 +1,20 @@
# Use an official Node.js runtime as a parent image
FROM node:18.17.0
FROM node:18-alpine
# Set the working directory to /app
WORKDIR /app
# Copy package.json and package-lock.json to the working directory
COPY package*.json ./
COPY package.json package-lock.json ./
# Install any needed packages specified in package.json
RUN npm install
RUN npm ci
# Copy the rest of the application code to the working directory
COPY . .
# Make port 3000 available to the world outside this container
EXPOSE 3000
COPY src ./src
COPY public ./public
COPY next.config.mjs .
COPY tsconfig.json .
# Build the app and run it
CMD ["sh", "-c", "npm run dev"]
CMD npm run dev

View file

@ -5,21 +5,21 @@ services:
- cognee-network
build:
context: .
dockerfile: Dockerfile-vanilla
dockerfile: Dockerfile
volumes:
- .:/app
- /app/cognee-frontend/
- /app/cognee-frontend/ # Ignore frontend code
environment:
- HOST=0.0.0.0
- ENVIRONMENT=local
- PYTHONPATH=.
ports:
- 8000:8000
- 5678:5678 # Debugging
# - 5678:5678 # Debugging
deploy:
resources:
limits:
cpus: "4.0"
cpus: 4.0
memory: 8GB
frontend:
@ -28,9 +28,11 @@ services:
context: ./cognee-frontend
dockerfile: Dockerfile
volumes:
- "./cognee-frontend:/app"
- ./cognee-frontend/src:/app/src
- ./cognee-frontend/public:/app/public
ports:
- "3000:3000"
- 3000:3000
# - 9229:9229 # Debugging
networks:
- cognee-network

View file

@ -1,45 +1,25 @@
version: "3.9"
services:
neo4j:
image: neo4j:latest
container_name: neo4j
ports:
- "7474:7474"
- "7687:7687"
environment:
- NEO4J_AUTH=neo4j/pleaseletmein
- NEO4J_PLUGINS=["apoc"]
networks:
- cognee_backend
cognee:
container_name: cognee
networks:
- cognee_backend
- cognee-network
build:
context: ./
context: .
dockerfile: Dockerfile
volumes:
- "./:/app"
- ./.data:/app/.data
- .:/app
- /app/cognee-frontend/ # Ignore frontend code
environment:
- HOST=0.0.0.0
- ENVIRONMENT=local
- PYTHONPATH=.
ports:
- 8000:8000
- 443:443
- 80:80
- 50051:50051
- 5678:5678 # Debugging
depends_on:
- postgres
- neo4j
- frontend
# - 5678:5678 # Debugging
deploy:
resources:
limits:
cpus: "4.0"
cpus: 4.0
memory: 8GB
frontend:
@ -48,36 +28,40 @@ services:
context: ./cognee-frontend
dockerfile: Dockerfile
volumes:
- "./cognee-frontend:/app"
- ./cognee-frontend/src:/app/src
- ./cognee-frontend/public:/app/public
ports:
- "3000:3000"
- 3000:3000
# - 9229:9229 # Debugging
networks:
- cognee_backend
- cognee-network
postgres:
image: postgres
container_name: postgres
environment:
- POSTGRES_HOST_AUTH_METHOD=trust
- POSTGRES_USER=bla
- POSTGRES_PASSWORD=bla
- POSTGRES_DB=bubu
networks:
- cognee_backend
ports:
- "5432:5432"
neo4j:
image: neo4j:latest
container_name: neo4j
profiles:
- neo4j
ports:
- 7474:7474
- 7687:7687
environment:
- NEO4J_AUTH=neo4j/pleaseletmein
- NEO4J_PLUGINS=["apoc"]
networks:
- cognee-network
falkordb:
image: falkordb/falkordb:edge
container_name: falkordb
profiles:
- falkordb
ports:
- "6379:6379"
- "3001:3000"
- 6379:6379
- 3001:3000
networks:
- cognee_backend
- cognee-network
networks:
cognee_backend:
name: cognee_backend
cognee-network:
name: cognee-network

35
entrypoint-old.sh Executable file
View file

@ -0,0 +1,35 @@
#!/bin/bash
# export ENVIRONMENT
echo "Debug mode: $DEBUG"
echo "Environment: $ENVIRONMENT"
if [ "$ENVIRONMENT" != "local" ]; then
echo "Running fetch_secret.py"
PYTHONPATH=. python cognee/fetch_secret.py
if [ $? -ne 0 ]; then
echo "Error: fetch_secret.py failed"
exit 1
fi
else
echo '"local" environment is active, skipping fetch_secret.py'
fi
echo "Creating database..."
#
#PYTHONPATH=. python cognee/setup_database.py
#if [ $? -ne 0 ]; then
# echo "Error: setup_database.py failed"
# exit 1
#fi
echo "Starting Gunicorn"
if [ "$DEBUG" = true ]; then
echo "Waiting for the debugger to attach..."
python -m debugpy --wait-for-client --listen 0.0.0.0:5678 -m gunicorn -w 3 -k uvicorn.workers.UvicornWorker -t 30000 --bind=0.0.0.0:8000 --bind=0.0.0.0:443 --log-level debug cognee.api.client:app
else
gunicorn -w 3 -k uvicorn.workers.UvicornWorker -t 30000 --bind=0.0.0.0:8000 --bind=0.0.0.0:443 --log-level debug cognee.api.client:app
fi

View file

@ -1,18 +0,0 @@
#!/bin/bash
echo "Debug mode: $DEBUG"
echo "Environment: $ENVIRONMENT"
echo "Starting Gunicorn"
if [ "$ENVIRONMENT" = "local" ]; then
if [ "$DEBUG" = true ]; then
echo "Waiting for the debugger to attach..."
python -m debugpy --wait-for-client --listen 0.0.0.0:5678 -m gunicorn -w 3 -k uvicorn.workers.UvicornWorker -t 30000 --bind=0.0.0.0:8000 --log-level debug --reload cognee.api.client:app
else
gunicorn -w 3 -k uvicorn.workers.UvicornWorker -t 30000 --bind=0.0.0.0:8000 --log-level debug --reload cognee.api.client:app
fi
else
gunicorn -w 3 -k uvicorn.workers.UvicornWorker -t 30000 --bind=0.0.0.0:8000 --log-level error cognee.api.client:app
fi

View file

@ -1,35 +1,18 @@
#!/bin/bash
# export ENVIRONMENT
echo "Debug mode: $DEBUG"
echo "Environment: $ENVIRONMENT"
if [ "$ENVIRONMENT" != "local" ]; then
echo "Running fetch_secret.py"
PYTHONPATH=. python cognee/fetch_secret.py
if [ $? -ne 0 ]; then
echo "Error: fetch_secret.py failed"
exit 1
fi
else
echo '"local" environment is active, skipping fetch_secret.py'
fi
echo "Creating database..."
#
#PYTHONPATH=. python cognee/setup_database.py
#if [ $? -ne 0 ]; then
# echo "Error: setup_database.py failed"
# exit 1
#fi
echo "Starting Gunicorn"
if [ "$DEBUG" = true ]; then
echo "Waiting for the debugger to attach..."
python -m debugpy --wait-for-client --listen 0.0.0.0:5678 -m gunicorn -w 3 -k uvicorn.workers.UvicornWorker -t 30000 --bind=0.0.0.0:8000 --bind=0.0.0.0:443 --log-level debug cognee.api.client:app
if [ "$ENVIRONMENT" = "local" ]; then
if [ "$DEBUG" = true ]; then
echo "Waiting for the debugger to attach..."
python -m debugpy --wait-for-client --listen 0.0.0.0:5678 -m gunicorn -w 3 -k uvicorn.workers.UvicornWorker -t 30000 --bind=0.0.0.0:8000 --log-level debug --reload cognee.api.client:app
else
gunicorn -w 3 -k uvicorn.workers.UvicornWorker -t 30000 --bind=0.0.0.0:8000 --log-level debug --reload cognee.api.client:app
fi
else
gunicorn -w 3 -k uvicorn.workers.UvicornWorker -t 30000 --bind=0.0.0.0:8000 --bind=0.0.0.0:443 --log-level debug cognee.api.client:app
gunicorn -w 3 -k uvicorn.workers.UvicornWorker -t 30000 --bind=0.0.0.0:8000 --log-level error cognee.api.client:app
fi