Skip to content

feat: add docker compose for pg db, pgadmin and ngrok #7

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ MISTRAL_API_KEY=your_mistral_api_key_here
GROQ_API_KEY=your_groq_api_key_here

DATABASE_URL=

NGROK_AUTHTOKEN=your_ngrok_authtoken_here
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"makefile.configureOnOpen": false
}
66 changes: 66 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Makefile for PostgreSQL, pgAdmin

# Set your Docker Compose file name
COMPOSE_FILE := docker-compose.yml

# Default target (runs in detached mode)
up:
docker-compose -f $(COMPOSE_FILE) up -d

# Run in foreground (for logs)
up-foreground:
docker-compose -f $(COMPOSE_FILE) up

# Stop containers
down:
docker-compose -f $(COMPOSE_FILE) down

# Stop and remove containers, networks, images, and volumes (use with caution!)
down-all:
docker-compose -f $(COMPOSE_FILE) down --rmi all --volumes

# Rebuild containers (useful after code changes in your project)
rebuild:
docker-compose -f $(COMPOSE_FILE) up -d --build

# Execute a command inside the 'db' container
postgres-exec:
docker-compose -f $(COMPOSE_FILE) exec db bash

# Execute a command inside the 'pgadmin' container
pgadmin-exec:
docker-compose -f $(COMPOSE_FILE) exec pgadmin /bin/sh

# Connect to the PostgreSQL database using psql
psql:
docker-compose -f $(COMPOSE_FILE) exec db psql -U postgres -d cursorlens

# Backup the database
backup:
docker-compose -f $(COMPOSE_FILE) exec -T db pg_dump -U postgres postgres > backup.sql

# Restore the database
restore:
cat backup.sql | docker-compose -f $(COMPOSE_FILE) exec -T db psql -U postgres -d cursorlens

# Get ngrok URL
ngrok-url:
@echo "Fetching ngrok URL..."
@curl -s http://localhost:4040/api/tunnels | jq -r '.tunnels[0].public_url'


# List available targets
help:
@echo "Available targets:"
@echo " up - Start services in detached mode"
@echo " up-foreground - Start services in the foreground (for logs)"
@echo " down - Stop services"
@echo " down-all - Stop and remove everything (use with caution!)"
@echo " rebuild - Rebuild and restart containers"
@echo " postgres-exec - Execute a command inside the 'db' container"
@echo " pgadmin-exec - Execute a command inside the 'pgadmin' container"
@echo " psql - Connect to the PostgreSQL database using psql"
@echo " backup - Backup the PostgreSQL database"
@echo " restore - Restore the PostgreSQL database from backup"
@echo " ngrok-url - Get the ngrok URL"
@echo " help - Show this help message"
38 changes: 27 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,48 @@ We are live on ProductHunt today, please upvote us if you find this useful! 🙏

## Getting Started

For detailed installation instructions, please refer to our [Installation Guide](https://www.cursorlens.com/docs/getting-started/installation).

### Prerequisites

- Node.js (v14 or later)
- pnpm
- PostgreSQL
- ngrok
- Docker and Docker Compose
- ngrok account and authtoken (sign up for free at ngrok.com)

### Quick Installation Steps

1. Clone the repository
2. Install dependencies with `pnpm install`
3. Set up environment variables
3. Set up environment variables:
- Create a `.env` file in the root directory of the project
- Sign up for a free account at <https://ngrok.com> if you haven't already
- Obtain your ngrok authtoken from <https://dashboard.ngrok.com/get-started/your-authtoken>
- Add your ngrok authtoken to the `.env` file: `NGROK_AUTHTOKEN=your_token_here`
4. Set up the database with `pnpm prisma migrate dev`
5. Build the project with `pnpm build`
6. Set up ngrok
7. Configure Cursor to use your ngrok URL as the API endpoint
5. Build and start the project with `pnpm build` and `pnpm start`
6. In a separate terminal, start the Docker services:

```
make up
```

7. Get your ngrok URL from `http://localhost:4040`, by running the following if you have `curl` and `jq` installed:

```
make ngrok-url
```

or from the ngrok dashboard at <https://dashboard.ngrok.com/cloud-edge/endpoints>.

8. Configure Cursor to use your ngrok URL as the API endpoint

For full details on each step, please see the [Installation Guide](https://www.cursorlens.com/docs/getting-started/installation).

## Usage

1. Configure Cursor to use Cursor Lens as its API endpoint by overriding `OpenAI Base URL`.
2. Choose a `gpt-` model. Use Cursor as normal for AI-assisted coding.
3. Visit the Cursor Lens dashboard to view logs, statistics, and insights.
1. Settings > Cursor Settings > Models > OpenAI API Key
2. Configure Cursor to use Cursor Lens as its API endpoint by overriding `OpenAI Base URL`.
3. Choose a `gpt-` model. Use Cursor as normal for AI-assisted coding.
4. Visit the Cursor Lens dashboard to view logs, statistics, and insights.

![Cursor settings](public/cl-settings.png)

Expand Down
55 changes: 55 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
version: "3.8"

services:
db:
image: postgres:15
platform: linux/arm64/v8
container_name: cursorlens_postgres
restart: always
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: cursorlens
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data

pgadmin:
image: dpage/pgadmin4:8.9
container_name: cursorlens_pgadmin4
restart: always
environment:
PGADMIN_DEFAULT_EMAIL: [email protected]
PGADMIN_DEFAULT_PASSWORD: root
PGADMIN_SERVER_JSON_FILE: /pgadmin4/servers.json
ports:
- "5050:80"
volumes:
- ./servers.json:/pgadmin4/servers.json
depends_on:
- db

ngrok:
image: ngrok/ngrok:latest
container_name: cursorlens_ngrok
restart: unless-stopped
command:
- "start"
- "--all"
- "--config"
- "/etc/ngrok.yml"
volumes:
- ./ngrok.yml:/etc/ngrok.yml
ports:
- 4040:4040
environment:
- NGROK_AUTHTOKEN=${NGROK_AUTHTOKEN}

volumes:
postgres_data:

networks:
default:
name: postgres_network
external: true
5 changes: 5 additions & 0 deletions ngrok.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: "2"
tunnels:
web:
proto: http
addr: host.docker.internal:3000
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
"dev": "next dev",
"build": "next build",
"start": "next start",
"db:generate": "prisma migrate dev",
"db:migrate": "prisma migrate deploy",
"db:push": "prisma db push",
"db:studio": "prisma studio",
"postinstall": "prisma generate",
"lint": "next lint",
"seed": "tsx prisma/seed.ts"
},
Expand Down
13 changes: 13 additions & 0 deletions servers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"Servers": {
"1": {
"Name": "Local Postgres",
"Group": "Servers",
"Host": "db",
"Port": 5432,
"MaintenanceDB": "postgres",
"Username": "postgres",
"Password": "postgres"
}
}
}
2 changes: 2 additions & 0 deletions src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const env = createEnv({
COHERE_API_KEY: z.string().optional(),
MISTRAL_API_KEY: z.string().optional(),
GROQ_API_KEY: z.string().optional(),
NGROK_AUTHTOKEN: z.string(),
},

/**
Expand All @@ -39,6 +40,7 @@ export const env = createEnv({
COHERE_API_KEY: process.env.COHERE_API_KEY,
MISTRAL_API_KEY: process.env.MISTRAL_API_KEY,
GROQ_API_KEY: process.env.GROQ_API_KEY,
NGROK_AUTHTOKEN: process.env.NGROK_AUTHTOKEN,
// NEXT_PUBLIC_CLIENTVAR: process.env.NEXT_PUBLIC_CLIENTVAR,
},
/**
Expand Down