From 62c84dde5e18591c9a4623eaa0729dfc60a19615 Mon Sep 17 00:00:00 2001 From: Vasilije <8619304+Vasilije1990@users.noreply.github.com> Date: Sat, 8 Mar 2025 08:51:57 -0800 Subject: [PATCH] feat: added helm clean push (#606) ## Description ## DCO Affirmation I affirm that all code in every commit of this pull request conforms to the terms of the Topoteretes Developer Certificate of Origin ## Summary by CodeRabbit - **New Features** - Introduced a Helm-based deployment package that streamlines setup for the backend application and PostgreSQL database on Kubernetes. - Added orchestration support via Docker Compose for managing multi-container deployments. - Added new Kubernetes resources including Deployments, Services, and PersistentVolumeClaims for both the backend and PostgreSQL. - **Documentation** - Provided comprehensive infrastructure and deployment instructions for Kubernetes environments. - **Chores** - Established a standardized container build process for the Python application. - Introduced configuration settings for service ports, resource limits, and environment variables. --------- Co-authored-by: Daniel Molnar Co-authored-by: Boris --- helm/Chart.yaml | 24 ++++++++++ helm/Dockerfile | 59 +++++++++++++++++++++++++ helm/README.md | 25 +++++++++++ helm/docker-compose-helm.yml | 46 +++++++++++++++++++ helm/templates/cognee_deployment.yaml | 32 ++++++++++++++ helm/templates/cognee_service.yaml | 13 ++++++ helm/templates/postgres_deployment.yaml | 35 +++++++++++++++ helm/templates/postgres_pvc.yaml | 10 +++++ helm/templates/postgres_service.yaml | 14 ++++++ helm/values.yaml | 22 +++++++++ 10 files changed, 280 insertions(+) create mode 100644 helm/Chart.yaml create mode 100644 helm/Dockerfile create mode 100644 helm/README.md create mode 100644 helm/docker-compose-helm.yml create mode 100644 helm/templates/cognee_deployment.yaml create mode 100644 helm/templates/cognee_service.yaml create mode 100644 helm/templates/postgres_deployment.yaml create mode 100644 helm/templates/postgres_pvc.yaml create mode 100644 helm/templates/postgres_service.yaml create mode 100644 helm/values.yaml diff --git a/helm/Chart.yaml b/helm/Chart.yaml new file mode 100644 index 000000000..ab9e087df --- /dev/null +++ b/helm/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: cognee-chart +description: A helm chart of the cognee backend deployment on Kubernetes environment + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "1.16.0" diff --git a/helm/Dockerfile b/helm/Dockerfile new file mode 100644 index 000000000..153834cd6 --- /dev/null +++ b/helm/Dockerfile @@ -0,0 +1,59 @@ +FROM python:3.11-slim + +# Define Poetry extras to install +ARG POETRY_EXTRAS="\ +# Storage & Databases \ +filesystem postgres weaviate qdrant neo4j falkordb milvus \ +# Notebooks & Interactive Environments \ +notebook \ +# LLM & AI Frameworks \ +langchain llama-index gemini huggingface ollama mistral groq \ +# Evaluation & Monitoring \ +deepeval evals posthog \ +# Graph Processing & Code Analysis \ +codegraph graphiti \ +# Document Processing \ +docs" + +# 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 apt-get install -y \ + gcc \ + libpq-dev + + +WORKDIR /app +COPY pyproject.toml poetry.lock /app/ + + +RUN pip install poetry + +# Don't create virtualenv since docker is already isolated +RUN poetry config virtualenvs.create false + +# Install the dependencies +RUN poetry install --extras "${POETRY_EXTRAS}" --no-root --without dev + + +# Set the PYTHONPATH environment variable to include the /app directory +ENV PYTHONPATH=/app + +COPY cognee/ /app/cognee + +# Copy Alembic configuration +COPY alembic.ini /app/alembic.ini +COPY alembic/ /app/alembic + +COPY entrypoint.sh /app/entrypoint.sh +RUN chmod +x /app/entrypoint.sh + +RUN sed -i 's/\r$//' /app/entrypoint.sh + +ENTRYPOINT ["/app/entrypoint.sh"] diff --git a/helm/README.md b/helm/README.md new file mode 100644 index 000000000..b7aaa6325 --- /dev/null +++ b/helm/README.md @@ -0,0 +1,25 @@ + +# cognee-infra-helm +General infrastructure setup for Cognee on Kubernetes using a Helm chart. + +## Prerequisites +Before deploying the Helm chart, ensure the following prerequisites are met:  + +**Kubernetes Cluster**: A running Kubernetes cluster (e.g., Minikube, GKE, EKS). + +**Helm**: Installed and configured for your Kubernetes cluster. You can install Helm by following the [official guide](https://helm.sh/docs/intro/install/).  + +**kubectl**: Installed and configured to interact with your cluster. Follow the instructions [here](https://kubernetes.io/docs/tasks/tools/install-kubectl/). + +Clone the Repository Clone this repository to your local machine and navigate to the directory. + +## Deploy Helm Chart: + + ```bash + helm install cognee ./cognee-chart + ``` + +**Uninstall Helm Release**: + ```bash + helm uninstall cognee + ``` diff --git a/helm/docker-compose-helm.yml b/helm/docker-compose-helm.yml new file mode 100644 index 000000000..8aaa63816 --- /dev/null +++ b/helm/docker-compose-helm.yml @@ -0,0 +1,46 @@ +services: + cognee: + image : cognee-backend:latest + container_name: cognee-backend + networks: + - cognee-network + build: + context: . + dockerfile: Dockerfile + volumes: + - .:/app + - /app/cognee-frontend/ # Ignore frontend code + environment: + - HOST=0.0.0.0 + - ENVIRONMENT=local + - PYTHONPATH=. + ports: + - 8000:8000 + # - 5678:5678 # Debugging + deploy: + resources: + limits: + cpus: '4.0' + memory: 8GB + + postgres: + image: pgvector/pgvector:pg17 + container_name: postgres + environment: + POSTGRES_USER: cognee + POSTGRES_PASSWORD: cognee + POSTGRES_DB: cognee_db + volumes: + - postgres_data:/var/lib/postgresql/data + ports: + - 5432:5432 + networks: + - cognee-network + +networks: + cognee-network: + name: cognee-network + +volumes: + postgres_data: + diff --git a/helm/templates/cognee_deployment.yaml b/helm/templates/cognee_deployment.yaml new file mode 100644 index 000000000..f16a475ec --- /dev/null +++ b/helm/templates/cognee_deployment.yaml @@ -0,0 +1,32 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ .Release.Name }}-cognee + labels: + app: {{ .Release.Name }}-cognee +spec: + replicas: 1 + selector: + matchLabels: + app: {{ .Release.Name }}-cognee + template: + metadata: + labels: + app: {{ .Release.Name }}-cognee + spec: + containers: + - name: cognee + image: {{ .Values.cognee.image }} + ports: + - containerPort: {{ .Values.cognee.port }} + env: + - name: HOST + value: {{ .Values.cognee.env.HOST }} + - name: ENVIRONMENT + value: {{ .Values.cognee.env.ENVIRONMENT }} + - name: PYTHONPATH + value: {{ .Values.cognee.env.PYTHONPATH }} + resources: + limits: + cpu: {{ .Values.cognee.resources.cpu }} + memory: {{ .Values.cognee.resources.memory }} diff --git a/helm/templates/cognee_service.yaml b/helm/templates/cognee_service.yaml new file mode 100644 index 000000000..21e9e470e --- /dev/null +++ b/helm/templates/cognee_service.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ .Release.Name }}-cognee + labels: + app: {{ .Release.Name }}-cognee +spec: + type: NodePort + ports: + - port: {{ .Values.cognee.port }} + targetPort: {{ .Values.cognee.port }} + selector: + app: {{ .Release.Name }}-cognee diff --git a/helm/templates/postgres_deployment.yaml b/helm/templates/postgres_deployment.yaml new file mode 100644 index 000000000..fc47647a2 --- /dev/null +++ b/helm/templates/postgres_deployment.yaml @@ -0,0 +1,35 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ .Release.Name }}-postgres + labels: + app: {{ .Release.Name }}-postgres +spec: + replicas: 1 + selector: + matchLabels: + app: {{ .Release.Name }}-postgres + template: + metadata: + labels: + app: {{ .Release.Name }}-postgres + spec: + containers: + - name: postgres + image: {{ .Values.postgres.image }} + ports: + - containerPort: {{ .Values.postgres.port }} + env: + - name: POSTGRES_USER + value: {{ .Values.postgres.env.POSTGRES_USER }} + - name: POSTGRES_PASSWORD + value: {{ .Values.postgres.env.POSTGRES_PASSWORD }} + - name: POSTGRES_DB + value: {{ .Values.postgres.env.POSTGRES_DB }} + volumeMounts: + - name: postgres-storage + mountPath: /var/lib/postgresql/data + volumes: + - name: postgres-storage + persistentVolumeClaim: + claimName: {{ .Release.Name }}-postgres-pvc diff --git a/helm/templates/postgres_pvc.yaml b/helm/templates/postgres_pvc.yaml new file mode 100644 index 000000000..7d7661b16 --- /dev/null +++ b/helm/templates/postgres_pvc.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: {{ .Release.Name }}-postgres-pvc +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: {{ .Values.postgres.storage }} diff --git a/helm/templates/postgres_service.yaml b/helm/templates/postgres_service.yaml new file mode 100644 index 000000000..7a944a128 --- /dev/null +++ b/helm/templates/postgres_service.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ .Release.Name }}-postgres + labels: + app: {{ .Release.Name }}-postgres +spec: + type: ClusterIP + ports: + - port: {{ .Values.postgres.port }} + targetPort: {{ .Values.postgres.port }} + selector: + app: {{ .Release.Name }}-postgres + diff --git a/helm/values.yaml b/helm/values.yaml new file mode 100644 index 000000000..fb2d3f7e3 --- /dev/null +++ b/helm/values.yaml @@ -0,0 +1,22 @@ +# Configuration for the 'cognee' application service +cognee: + # Image name (using the local image we’ll build in Minikube) + image: "hajdul1988/cognee-backend:latest" + port: 8000 + env: + HOST: "0.0.0.0" + ENVIRONMENT: "local" + PYTHONPATH: "." + resources: + cpu: "4.0" + memory: "8Gi" + +# Configuration for the 'postgres' database service +postgres: + image: "pgvector/pgvector:pg17" + port: 5432 + env: + POSTGRES_USER: "cognee" + POSTGRES_PASSWORD: "cognee" + POSTGRES_DB: "cognee_db" + storage: "8Gi"