From 9b72d224a6a7800743e1956b3b98e9c45e1a7fca Mon Sep 17 00:00:00 2001 From: Stephen Rayner Date: Sun, 18 Aug 2024 18:15:27 +0100 Subject: [PATCH 1/2] feat: add docker compose for pg db and pgadmin setup and prisma alias scripts --- cursorlens-db/Makefile | 59 ++++++++++++++++++++++++++++++++ cursorlens-db/docker-compose.yml | 38 ++++++++++++++++++++ cursorlens-db/servers.json | 13 +++++++ package.json | 5 +++ 4 files changed, 115 insertions(+) create mode 100644 cursorlens-db/Makefile create mode 100644 cursorlens-db/docker-compose.yml create mode 100644 cursorlens-db/servers.json diff --git a/cursorlens-db/Makefile b/cursorlens-db/Makefile new file mode 100644 index 0000000..2c3cae6 --- /dev/null +++ b/cursorlens-db/Makefile @@ -0,0 +1,59 @@ +# 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 + +# 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 " help - Show this help message" diff --git a/cursorlens-db/docker-compose.yml b/cursorlens-db/docker-compose.yml new file mode 100644 index 0000000..e8171f8 --- /dev/null +++ b/cursorlens-db/docker-compose.yml @@ -0,0 +1,38 @@ +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: admin@admin.com + PGADMIN_DEFAULT_PASSWORD: root + PGADMIN_SERVER_JSON_FILE: /pgadmin4/servers.json + ports: + - "5050:80" + volumes: + - ./servers.json:/pgadmin4/servers.json + depends_on: + - db + +volumes: + postgres_data: + +networks: + default: + name: postgres_network diff --git a/cursorlens-db/servers.json b/cursorlens-db/servers.json new file mode 100644 index 0000000..845fa7a --- /dev/null +++ b/cursorlens-db/servers.json @@ -0,0 +1,13 @@ +{ + "Servers": { + "1": { + "Name": "Local Postgres", + "Group": "Servers", + "Host": "db", + "Port": 5432, + "MaintenanceDB": "postgres", + "Username": "postgres", + "Password": "postgres" + } + } +} diff --git a/package.json b/package.json index 1952f1d..36d577d 100644 --- a/package.json +++ b/package.json @@ -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" }, From 125c38dd1b863903b93b2377e3d476e351911bb2 Mon Sep 17 00:00:00 2001 From: Stephen Rayner Date: Tue, 20 Aug 2024 10:09:17 +0100 Subject: [PATCH 2/2] chore: add ngrok via docker-compose --- .env.example | 2 + .vscode/settings.json | 3 ++ cursorlens-db/Makefile => Makefile | 7 ++++ README.md | 38 +++++++++++++------ .../docker-compose.yml => docker-compose.yml | 17 +++++++++ ngrok.yml | 5 +++ cursorlens-db/servers.json => servers.json | 0 src/env.ts | 2 + 8 files changed, 63 insertions(+), 11 deletions(-) create mode 100644 .vscode/settings.json rename cursorlens-db/Makefile => Makefile (91%) rename cursorlens-db/docker-compose.yml => docker-compose.yml (69%) create mode 100644 ngrok.yml rename cursorlens-db/servers.json => servers.json (100%) diff --git a/.env.example b/.env.example index 85c59e3..11eb633 100644 --- a/.env.example +++ b/.env.example @@ -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 diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..c98f086 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "makefile.configureOnOpen": false +} diff --git a/cursorlens-db/Makefile b/Makefile similarity index 91% rename from cursorlens-db/Makefile rename to Makefile index 2c3cae6..806baf4 100644 --- a/cursorlens-db/Makefile +++ b/Makefile @@ -43,6 +43,12 @@ backup: 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:" @@ -56,4 +62,5 @@ help: @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" diff --git a/README.md b/README.md index e91785a..bf7fce4 100644 --- a/README.md +++ b/README.md @@ -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 if you haven't already + - Obtain your ngrok authtoken from + - 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 . + +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) diff --git a/cursorlens-db/docker-compose.yml b/docker-compose.yml similarity index 69% rename from cursorlens-db/docker-compose.yml rename to docker-compose.yml index e8171f8..980ff0c 100644 --- a/cursorlens-db/docker-compose.yml +++ b/docker-compose.yml @@ -30,9 +30,26 @@ services: 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 diff --git a/ngrok.yml b/ngrok.yml new file mode 100644 index 0000000..cc6f357 --- /dev/null +++ b/ngrok.yml @@ -0,0 +1,5 @@ +version: "2" +tunnels: + web: + proto: http + addr: host.docker.internal:3000 diff --git a/cursorlens-db/servers.json b/servers.json similarity index 100% rename from cursorlens-db/servers.json rename to servers.json diff --git a/src/env.ts b/src/env.ts index aea06e3..abae538 100644 --- a/src/env.ts +++ b/src/env.ts @@ -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(), }, /** @@ -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, }, /**