|
| 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