Skip to content

Commit f84b31e

Browse files
Adding local dev script for running backend & frontend locally alongside with docker containers for local development
1 parent a6fbf7e commit f84b31e

File tree

8 files changed

+707
-0
lines changed

8 files changed

+707
-0
lines changed

apps/opik-backend/entrypoint.sh

100644100755
File mode changed.

apps/opik-backend/install_rds_cert.sh

100644100755
File mode changed.

apps/opik-backend/run_db_migrations.sh

100644100755
File mode changed.

apps/opik-guardrails-backend/entrypoint.sh

100644100755
File mode changed.

apps/opik-python-backend/demo_data_entrypoint.sh

100644100755
File mode changed.

scripts/QUICKSTART.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Quick Start Guide
2+
3+
## Getting Started with OPIK Local Development
4+
5+
This guide will help you get the OPIK development environment running locally in minutes.
6+
7+
### Prerequisites
8+
9+
Make sure you have the following installed:
10+
- Docker
11+
- Maven
12+
- Node.js (v18+)
13+
- npm
14+
15+
### Step 1: Start Everything
16+
17+
Run the development script:
18+
19+
```bash
20+
./scripts/dev-local.sh
21+
```
22+
23+
This will:
24+
- ✅ Start all required containers (MySQL, Redis, ClickHouse, etc.)
25+
- ✅ Configure nginx and frontend environment for local development
26+
- ✅ Build the backend with Maven (skipping tests)
27+
- ✅ Start the backend on http://localhost:8080
28+
- ✅ Start the frontend on http://localhost:5173
29+
30+
### Step 2: Access the Application
31+
32+
Once everything is running, you can access:
33+
- **Frontend**: http://localhost:5173
34+
- **Backend API**: http://localhost:8080
35+
- **Backend Health Check**: http://localhost:8080/health-check
36+
37+
### Step 3: Stop Everything
38+
39+
Press `Ctrl+C` to stop the backend and frontend processes.
40+
41+
To stop the containers:
42+
```bash
43+
./opik.sh --stop
44+
```
45+
46+
### Alternative Workflows
47+
48+
#### Start Only Containers
49+
If you want to run backend/frontend from your IDE:
50+
```bash
51+
./scripts/dev-local.sh --containers-only
52+
```
53+
54+
#### Start Only Backend
55+
```bash
56+
./scripts/dev-local.sh --backend-only
57+
```
58+
59+
#### Start Only Frontend
60+
```bash
61+
./scripts/dev-local.sh --frontend-only
62+
```
63+
64+
### Troubleshooting
65+
66+
If you encounter issues:
67+
68+
1. **Check if Docker is running**
69+
2. **Check if ports are available** (8080, 5173, 3306, 6379, 8123)
70+
3. **Check container logs**: `docker logs opik-mysql-1`
71+
4. **Restart containers**: `./opik.sh --stop && ./scripts/dev-local.sh --containers-only`
72+
73+
### Next Steps
74+
75+
- Read the full documentation in `scripts/README-dev-local.md`
76+
- Check the main project README for development guidelines
77+
- Join the community for support

scripts/README-dev-local.md

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
# Local Development Script
2+
3+
This directory contains a script for running OPIK locally for development purposes.
4+
5+
## `dev-local.sh`
6+
7+
A comprehensive shell script that sets up the OPIK development environment by:
8+
1. Starting all required containers (excluding backend & frontend)
9+
2. Building the backend with Maven (skipping tests)
10+
3. Running the backend and frontend locally
11+
12+
### Prerequisites
13+
14+
Before running the script, ensure you have the following installed:
15+
16+
- **Docker** - For running containers
17+
- **Maven** - For building the Java backend
18+
- **Node.js** - For running the frontend
19+
- **npm** - For managing frontend dependencies
20+
21+
### Usage
22+
23+
#### Basic Usage (Full Setup)
24+
```bash
25+
./scripts/dev-local.sh
26+
```
27+
28+
This will:
29+
- Start all required containers (MySQL, Redis, ClickHouse, Zookeeper, MinIO, Python Backend)
30+
- Build the backend with Maven (skipping tests)
31+
- Run the backend locally on http://localhost:8080
32+
- Run the frontend locally on http://localhost:5173
33+
34+
#### Options
35+
36+
```bash
37+
# Only start containers (don't run backend/frontend locally)
38+
./scripts/dev-local.sh --containers-only
39+
40+
# Only build and run backend locally
41+
./scripts/dev-local.sh --backend-only
42+
43+
# Only run frontend locally
44+
./scripts/dev-local.sh --frontend-only
45+
46+
# Show help
47+
./scripts/dev-local.sh --help
48+
```
49+
50+
### What the Script Does
51+
52+
#### Container Management
53+
- Starts the following containers using Docker Compose:
54+
- `mysql` - Database for state management
55+
- `redis` - Caching and session storage
56+
- `clickhouse` - Analytics database
57+
- `zookeeper` - Distributed coordination
58+
- `minio` - Object storage (S3-compatible)
59+
- `python-backend` - Python evaluation service
60+
61+
- Configures nginx for local development (updates `nginx_default_local.conf`)
62+
- Waits for all containers to be healthy before proceeding
63+
- Uses the same container configuration as the main `opik.sh` script
64+
65+
#### Backend Setup
66+
- Changes to the `apps/opik-backend` directory
67+
- Runs `mvn clean install -DskipTests` to build the backend
68+
- Sets up all necessary environment variables for local development
69+
- Runs database migrations using `./run_db_migrations.sh`
70+
- Starts the backend server using the built JAR file
71+
- Waits for the backend to be accessible on http://localhost:8080
72+
73+
#### Frontend Setup
74+
- Changes to the `apps/opik-frontend` directory
75+
- Installs npm dependencies if `node_modules` doesn't exist
76+
- Configures `.env.development` with local development settings:
77+
- `VITE_BASE_URL=/`
78+
- `VITE_BASE_API_URL=http://localhost:8080`
79+
- Starts the Vite development server using `npm start`
80+
- Waits for the frontend to be accessible on http://localhost:5173
81+
82+
### Configuration Files
83+
84+
The script automatically configures the following files for local development:
85+
86+
#### Frontend Environment (`.env.development`)
87+
```bash
88+
VITE_BASE_URL=/
89+
VITE_BASE_API_URL=http://localhost:8080
90+
```
91+
92+
#### Nginx Configuration (`nginx_default_local.conf`)
93+
Updates the proxy_pass directive to use `host.docker.internal:8080` instead of `backend:8080` for local development.
94+
95+
### Environment Variables
96+
97+
The script sets up the following environment variables for the backend:
98+
99+
```bash
100+
STATE_DB_PROTOCOL=jdbc:mysql://
101+
STATE_DB_URL=localhost:3306/opik?createDatabaseIfNotExist=true&rewriteBatchedStatements=true
102+
STATE_DB_DATABASE_NAME=opik
103+
STATE_DB_USER=opik
104+
STATE_DB_PASS=opik
105+
ANALYTICS_DB_MIGRATIONS_URL=jdbc:clickhouse://localhost:8123
106+
ANALYTICS_DB_MIGRATIONS_USER=opik
107+
ANALYTICS_DB_MIGRATIONS_PASS=opik
108+
ANALYTICS_DB_PROTOCOL=HTTP
109+
ANALYTICS_DB_HOST=localhost
110+
ANALYTICS_DB_PORT=8123
111+
ANALYTICS_DB_DATABASE_NAME=opik
112+
ANALYTICS_DB_USERNAME=opik
113+
ANALYTICS_DB_PASS=opik
114+
JAVA_OPTS=-Dliquibase.propertySubstitutionEnabled=true -XX:+UseG1GC -XX:MaxRAMPercentage=80.0
115+
REDIS_URL=redis://:opik@localhost:6379/
116+
OPIK_OTEL_SDK_ENABLED=false
117+
OTEL_VERSION=2.16.0
118+
OTEL_PROPAGATORS=tracecontext,baggage,b3
119+
OTEL_EXPERIMENTAL_EXPORTER_OTLP_RETRY_ENABLED=true
120+
OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION=BASE2_EXPONENTIAL_BUCKET_HISTOGRAM
121+
OTEL_EXPERIMENTAL_RESOURCE_DISABLED_KEYS=process.command_args
122+
OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE=delta
123+
OPIK_USAGE_REPORT_ENABLED=true
124+
AWS_ACCESS_KEY_ID=THAAIOSFODNN7EXAMPLE
125+
AWS_SECRET_ACCESS_KEY=LESlrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
126+
PYTHON_EVALUATOR_URL=http://localhost:8000
127+
TOGGLE_GUARDRAILS_ENABLED=false
128+
```
129+
130+
### Stopping the Services
131+
132+
- Press `Ctrl+C` to stop all services gracefully
133+
- The script will automatically clean up background processes
134+
- Containers will continue running (use `./opik.sh --stop` to stop them)
135+
136+
### Troubleshooting
137+
138+
#### Common Issues
139+
140+
1. **Docker not running**
141+
```
142+
[ERROR] Docker is not running or not accessible. Please start Docker first.
143+
```
144+
- Start Docker Desktop or Docker daemon
145+
146+
2. **Maven not found**
147+
```
148+
[ERROR] Maven is not installed. Please install Maven first.
149+
```
150+
- Install Maven: `sudo apt install maven` (Ubuntu/Debian) or `brew install maven` (macOS)
151+
152+
3. **Node.js not found**
153+
```
154+
[ERROR] Node.js is not installed. Please install Node.js first.
155+
```
156+
- Install Node.js from https://nodejs.org/
157+
158+
4. **Backend build fails**
159+
- Check that you have Java 17+ installed
160+
- Ensure you have sufficient memory for Maven build
161+
- Check the Maven output for specific error messages
162+
163+
5. **Containers not starting**
164+
- Check Docker logs: `docker logs opik-mysql-1` (replace with container name)
165+
- Ensure ports are not already in use
166+
- Check available disk space
167+
168+
#### Debugging
169+
170+
- The script provides colored output to help identify issues
171+
- Check container health: `docker ps` to see running containers
172+
- Check container logs: `docker logs <container-name>`
173+
- Verify ports are accessible: `curl http://localhost:8080/health-check`
174+
175+
### Integration with IDE
176+
177+
You can use this script to start the infrastructure, then run the backend and frontend directly from your IDE:
178+
179+
1. Run `./scripts/dev-local.sh --containers-only` to start containers
180+
2. Run the backend from your IDE (e.g., IntelliJ IDEA, VS Code)
181+
3. Run the frontend from your IDE or terminal
182+
183+
This approach gives you better debugging capabilities and faster development cycles.

0 commit comments

Comments
 (0)