Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docker-compose FalkorDB, Backend, Frontend #367

Merged
merged 29 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
63ba49e
Merge pull request #315 from FalkorDB/staging
AviAvni Dec 31, 2024
58eb3b5
updated readme with setup instructions
swilly22 Jan 8, 2025
1912e2e
address PR comments
swilly22 Jan 9, 2025
f419fe6
Merge pull request #348 from FalkorDB/setup-instructions
swilly22 Jan 9, 2025
8d2e6ec
add publish docker publish frontend
gkorland Jan 24, 2025
c4eb6b8
Update .github/workflows/release-image.yml
gkorland Jan 24, 2025
d639e7c
Update Trivy action to version 0.29.0
gkorland Jan 24, 2025
ec73ee4
add docker-compose
gkorland Jan 24, 2025
12d3466
Remove vulnerability scan step from workflow
gkorland Jan 24, 2025
cebdd83
Merge pull request #365 from FalkorDB/docker
gkorland Jan 24, 2025
fb783b1
udpate version 0.2
gkorland Jan 24, 2025
a4b6e33
Merge pull request #368 from FalkorDB/0.2
gkorland Jan 24, 2025
b542f2d
Merge branch 'main' into compose
gkorland Jan 29, 2025
46bd62b
Merge branch 'staging' into compose
gkorland Jan 29, 2025
8f05cf8
fix tests
Naseem77 Jan 29, 2025
a7c282d
fix chat error & increase timing
Naseem77 Jan 29, 2025
7b9acf6
improve tests timing and locators
Naseem77 Jan 29, 2025
e6972d4
update locators
Naseem77 Jan 29, 2025
e2f506e
add logging
Naseem77 Jan 30, 2025
aaedf00
tests improvements
Naseem77 Jan 31, 2025
451b02d
fix failing tests
Naseem77 Jan 31, 2025
8f4343c
Add CI screenshots on test failure
Naseem77 Feb 2, 2025
bbe2070
Update playwright.yml
Naseem77 Feb 2, 2025
6a37813
add logging
Naseem77 Feb 2, 2025
44282ad
add polling with retries
Naseem77 Feb 2, 2025
364ace5
add logging and timing
Naseem77 Feb 2, 2025
0fefd04
add more logging improve transformnNode
Naseem77 Feb 2, 2025
c214063
Update testData.ts
Naseem77 Feb 3, 2025
681e655
remove logging, increase workers
Naseem77 Feb 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/release-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Release image to DockerHub

on:
workflow_dispatch:
push:
tags: ["v*.*.*"]
branches:
- main

jobs:
build-and-release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set tags
run: |
if ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags') }}; then
echo "TAGS=falkordb/code-graph-frontend:latest,falkordb/code-graph-frontend:${{ github.ref_name }}" >> $GITHUB_ENV
else
echo "TAGS=falkordb/code-graph-frontend:edge" >> $GITHUB_ENV
fi

- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ env.TAGS }}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Use a Node.js base image
FROM node:20
FROM node:22

# Set working directory
WORKDIR /app
Expand Down
64 changes: 58 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,80 @@
## Getting Started
[Live Demo](https://code-graph.falkordb.com/)

## Run locally
This project is composed of three pieces:

1. FalkorDB Graph DB - this is where your graphs are stored and queried
2. Code-Graph-Backend - backend logic
3. Code-Graph-Frontend - website

You'll need to start all three components:

### Run FalkorDB

```bash
docker run -p 6379:6379 -it --rm falkordb/falkordb
```

### Install node packages
### Run Code-Graph-Backend

#### Clone the Backend

```bash
npm install
git clone https://github.com/FalkorDB/code-graph-backend.git
```

### Set your OpenAI key
#### Setup environment variables

`SECRET_TOKEN` - user defined token used to authorize the request

```bash
export FALKORDB_HOST=localhost FALKORDB_PORT=6379 \
OPENAI_API_KEY=<YOUR OPENAI_API_KEY> SECRET_TOKEN=<YOUR_SECRECT_TOKEN> \
FLASK_RUN_HOST=0.0.0.0 FLASK_RUN_PORT=5000
```
export OPENAI_API_KEY=YOUR_OPENAI_API_KEY

#### Install dependencies & run

```bash
cd code-graph-backend

pip install --no-cache-dir -r requirements.txt

flask --app api/index.py run --debug > flask.log 2>&1 &

```

### Run the development server
### Run Code-Graph-Frontend

#### Clone the Frontend

```bash
git clone https://github.com/FalkorDB/code-graph.git
```

#### Setup environment variables

```bash
export BACKEND_URL=http://${FLASK_RUN_HOST}:${FLASK_RUN_PORT} \
SECRET_TOKEN=<YOUR_SECRECT_TOKEN> OPENAI_API_KEY=<YOUR_OPENAI_API_KEY>
```

#### Install dependencies & run

```bash
cd code-graph
npm install
npm run dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
### Process a local repository
```bash
curl -X POST http://127.0.0.1:5000/analyze_folder -H "Content-Type: application/json" -d '{"path": "<PATH_TO_LOCAL_REPO>", "ignore": ["./.github", "./sbin", "./.git","./deps", "./bin", "./build"]}' -H "Authorization: <YOUR_SECRECT_TOKEN>"
```

Note: At the moment code-graph can analyze both the C & Python source files.
Support for additional languages e.g. JavaScript, Go, Java is planned to be added
in the future.

Browse to [http://localhost:3000](http://localhost:3000)
36 changes: 36 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: "3.9"

services:
falkordb:
image: falkordb/falkordb:latest
ports:
- "6379:6379"
- "3001:3000"
volumes:
- ./:/data/
stdin_open: true # Keep the container's STDIN open
tty: true # Allocate a pseudo-TTY
Comment on lines +4 to +12
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Several critical issues in the FalkorDB service configuration need attention.

  1. Using the latest tag is not recommended for production as it can lead to unexpected changes during deployments.
  2. The volume mount ./:/data/ exposes the entire current directory, which could include sensitive files.
  3. Port mapping 3001:3000 might conflict with the frontend's port 3000.

Consider applying these changes:

  falkordb:
-    image: falkordb/falkordb:latest
+    image: falkordb/falkordb:1.0.0  # Replace with specific version
    ports:
      - "6379:6379"
-      - "3001:3000"
+      - "3001:3001"  # Use consistent port numbers
    volumes:
-      - ./:/data/
+      - falkordb_data:/data  # Use named volume
    stdin_open: true
    tty: true

volumes:
  falkordb_data:  # Define named volume

Committable suggestion skipped: line range outside the PR's diff.


code-graph-frontend:
image: falkordb/code-graph-frontend:latest
ports:
- "3000:3000"
depends_on:
- code-graph-backend
environment:
- BACKEND_URL=http://code-graph-backend:5000 # Backend service URL
- SECRET_TOKEN=Vespa

Comment on lines +14 to +23
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Security concerns in the Frontend service configuration.

  1. Using latest tag is not recommended for production.
  2. The SECRET_TOKEN should not be hardcoded in the compose file.
  3. The backend communication should use HTTPS in production.

Consider applying these changes:

  code-graph-frontend:
-    image: falkordb/code-graph-frontend:latest
+    image: falkordb/code-graph-frontend:1.0.0  # Replace with specific version
    ports:
      - "3000:3000"
    depends_on:
      - code-graph-backend
    environment:
-      - BACKEND_URL=http://code-graph-backend:5000
+      - BACKEND_URL=${BACKEND_URL:-https://code-graph-backend:5000}
-      - SECRET_TOKEN=Vespa
+      - SECRET_TOKEN=${SECRET_TOKEN}  # Set via .env file or environment

Create a .env.example file to document required environment variables:

BACKEND_URL=https://code-graph-backend:5000
SECRET_TOKEN=your-secure-token-here

code-graph-backend:
image: falkordb/code-graph-backend:latest
ports:
- "4000:5000"
depends_on:
- falkordb
environment:
- FALKORDB_HOST=falkordb
- FALKORDB_PORT=6379
- OPENAI_API_KEY=YOUR_OPENAI_API_KEY
- SECRET_TOKEN=Vespa
- FLASK_RUN_HOST=0.0.0.0
- FLASK_RUN_PORT=5000
Comment on lines +24 to +36
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Critical security and reliability concerns in the Backend service configuration.

  1. Using latest tag is not recommended for production.
  2. Sensitive credentials (OpenAI API key, SECRET_TOKEN) should not be in the compose file.
  3. No health check is defined for the service.

Consider applying these changes:

  code-graph-backend:
-    image: falkordb/code-graph-backend:latest
+    image: falkordb/code-graph-backend:1.0.0  # Replace with specific version
    ports:
      - "4000:5000"
    depends_on:
      - falkordb
+    healthcheck:
+      test: ["CMD", "curl", "-f", "http://localhost:5000/health"]
+      interval: 30s
+      timeout: 10s
+      retries: 3
    environment:
      - FALKORDB_HOST=falkordb
      - FALKORDB_PORT=6379
-      - OPENAI_API_KEY=YOUR_OPENAI_API_KEY
+      - OPENAI_API_KEY=${OPENAI_API_KEY}
-      - SECRET_TOKEN=Vespa
+      - SECRET_TOKEN=${SECRET_TOKEN}
      - FLASK_RUN_HOST=0.0.0.0
      - FLASK_RUN_PORT=5000

Add these variables to your .env.example file:

OPENAI_API_KEY=your-openai-api-key

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "code-graph",
"version": "0.1.0",
"version": "0.2.0",
"private": true,
"scripts": {
"dev": "HOST=0.0.0.0 PORT=3000 next dev",
Expand Down
Loading