Skip to content
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,7 @@ coral/stats.html

# E2E tests playwright

e2e/playwright-report*
e2e/playwright-report*
# Local Docker setup: secrets must never be committed (truststores live outside the repo, in ~/.klaw/truststore)
docker-scripts/.env
docker-scripts/klaw-secrets.properties
13 changes: 8 additions & 5 deletions coral/docs/development-with-local-klaw.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,19 @@ Please check out the [proxy README](../proxy/README.md) for more detailed inform
6. Install and run Docker: [Get Docker](https://docs.docker.com/get-docker/)
7. Go to directory [`coral/proxy`](../../coral/proxy)
8. Run `pnpm install` if you haven't already
9. Run `pnpm run setup` to build and deploy your docker container for:
9. Run `pnpm dev:start:testEnv` to build and deploy your docker containers for:
- Klaw core: the main API Coral interacts with
- Klaw cluster api: the API interacting with the Kafka clusters managed by Klaw
- Kafka, zoo-keeper, schema-registry: a basic Kafka setup
Comment thread
programmiri marked this conversation as resolved.
Resolved
10. Run `pnmv dev:[start|restart]`
- check out the [documentation](../../coral/proxy/README.md) for more scripts and information when to use them.
- the proxy runs on [`http://localhost:1337`](http://localhost:1337)

This also starts the proxy and Coral. The first run takes several minutes. For later sessions, use
`pnpm dev:proxy` while Klaw is still running, or `pnpm dev:restart` to restart the containers.

10. Open the proxy at [`http://localhost:1337`](http://localhost:1337)
- check out the [documentation](../../coral/proxy/README.md) for all scripts and information when to use them.
- Login (❗️The correct redirect for login and authentication is **not** working in the proxy yet):
- Go to your [local Klaw](http://localhost:9097/login)
- Login as superadmin with: `superadmin`, password based on configuration (klaw.superadmin.default.password) (see [application.properties](../../core/src/main/resources/application.properties))
- Login as superadmin with: `superadmin` and the password in `docker-scripts/.env` (created on the first start, see the [Docker documentation](../../docker-scripts/README.md))
- Go back to the [proxy](http://localhost:1337)
11. As superadmin, create one or more users [proxy](http://localhost:1337/users)
"User" and "superadmin" are roles that have authorization to different views and functionality. We're migrating
Expand Down
149 changes: 43 additions & 106 deletions coral/proxy/README.md
Original file line number Diff line number Diff line change
@@ -1,125 +1,62 @@
# Development proxy server

We're running a proxy server to enable a convenient way of developing Coral locally without the need to connect a remote api.
The proxy lets you develop Coral locally without a remote API. It runs Klaw (core and cluster-api) in Docker, starts the
Coral dev server and puts both behind one address:

## Table of content
**Your local development is always available at <http://localhost:1337>.**

- [Installation](#installation)
- [Commands and flags](#commands-and-flags)
- [➡️ `pnpm dev:start`](#-pnpm-devstart)
- [➡️ `pnpm dev:restart`](#-pnpm-devrestart)
- [➡️ `pnpm:[start|restart]:testEnv`](#-pnpmstartrestarttestenv)
- [➡️ `pnpm dev:stop`](#-pnpm-devstop)
- [➡️ `pnpm dev:destroy`](#-pnpm-devdestroy)
- [➡️ `pnpm run setup`](#-pnpm-run-setup)
- [➡️ additional `--verbose` flag](#-additional---verbose-flag)
- [How it works](#how-it-works)
- [These scripts are used by other scripts](#these-scripts-are-used-by-other-scripts)
- [Files](#files)
How Klaw runs in Docker (configuration, passwords, connecting clusters, data) is described in
[`docker-scripts/README.md`](../../docker-scripts/README.md). This page only covers the proxy.

## Installation
## Requirements

** ℹRequirements**
- Coral is set up: [Installation Coral](../README.md)
- Docker is installed and running: [Get Docker](https://docs.docker.com/get-docker/)
- `pnpm install` has been run in this directory

- Coral is set up - [Installation coral](../README.md)
- Docker is installed - [Get Docker](https://docs.docker.com/get-docker/)
- in this directory, run `pnpm install`
All commands below are run in this directory.

All scripts need to be run in this directory!
## Commands

🙋‍♀️ **Your local development will always be available at [http://localhost:1337](http://localhost:1337)**
- `pnpm dev:start`: builds Klaw, starts it in Docker, then starts the proxy and Coral. **Fails if Klaw is already
running.** The first run takes several minutes (Maven build) and creates `docker-scripts/.env` with a random
password for the `superadmin` user.
- `pnpm dev:start:testEnv`: like `dev:start`, and also starts Kafka, ZooKeeper and a schema registry, so you can go
through whole workflows like requesting and approving a topic.
- `pnpm dev:proxy`: starts only the proxy and Coral, for a Klaw that is already running. This is the command for
everyday work on Coral. **Fails if Klaw is not running.**
- `pnpm dev:restart`: restarts the existing Klaw containers without rebuilding them, then starts the proxy and Coral.
**Fails if the containers do not exist.**
- `pnpm dev:stop`: stops the Docker containers. Your data is kept.
- `pnpm dev:destroy`: stops and removes the Docker containers. The data stays in a Docker volume, see
[Starting from scratch](../../docker-scripts/README.md#starting-from-scratch) to delete it too.

**⚠️ AUTHENTICATION AND LOGIN REDIRECT NOT WORKING**
Add `--verbose` to print every request the proxy handles (very noisy, useful for debugging), for example
`pnpm dev --mode=proxy --verbose`.

At the moment, our proxy does **not** handle the redirect from backend for authenticating the user.
The proxy and Coral stop with `Ctrl+C`. The Klaw containers keep running until you stop or destroy them.

- If you access `https:localhost:1337` without being currently authorized, you will be redirected to the login page on port `:9097`. After a successful login, please go back to `https:localhost:1337`.
**Changes in `/core` or `/cluster-api`:** to run them against a new build, run `pnpm dev:destroy` and then
`pnpm dev:start`.

- If you experience trouble with api calls while using `https:localhost:1337`(\*), your authorization may have expired. Please go to `http://localhost:9097/login` to log in again. After a successful login, please go back to `https:localhost:1337`.
## Login

(\*) You'll see requests to `http://localhost:1337/api/getAuth` returning `302`, followed right after with calls to `http://localhost:9097/login` causing an error: "Access to fetch at 'http://localhost:9097/login' (redirected from 'http://localhost:1337/api/getAuth') from origin 'http://localhost:1337' has been blocked by CORS policy"
The proxy does **not** handle the redirect from the backend for authenticating the user.

## Commands and flags
- Log in at <http://localhost:9097/login> as `superadmin`. The password is in `docker-scripts/.env`. Then go to
<http://localhost:1337>.
- If API calls fail while you use <http://localhost:1337>, your session may have expired. Log in again at
<http://localhost:9097/login>.

`pnpm dev` is our base command. It can be run with different flags. We provided alias commands for each flag, too, to make them more convenient to use.

### ➡️ `pnpm dev:start`

This is the alias for `pnpm dev --mode=start`.

Checks if Klaw core and Klaw cluster-api are running in the right ports in your docker container. If they are not, it will run a build and deploy job.

**Use `pnpm dev:start` when:**

- you run the docker containers for the first time
- there are changes in `/core` or `/cluster-api`, where you want a new build to run against the most current version

### ➡️ `pnpm dev:restart`

This is the alias for `pnpm dev --mode=restart`.

Checks if Klaw core and Klaw cluster-api are running in the right ports in your docker container. If they are not, it will trigger a new deployment, which will restart your container.

**Use `pnpm dev:restart` when:**

- you have a current version Klaw already in your container that you only want to restart

### ➡️ `pnpm:[start|restart]:testEnv`

This is the alias for `pnpm dev --mode=[start|restart] --testEnv=true`.

Runs the `pnpm dev` command with the mode flag start or restart and an additional flag "testEnv". When
`--testEnv=true` is set, we additionally check and, if necessary, set up a sandbox environment for Klaw.

**Use `pnpm:[start|restart]:testEnv` when:**

- you want to go through whole workflows, like for example requesting and approving a topic

### ➡️ `pnpm dev:stop`

This is the alias for `pnpm dev --mode=stop`.

This will stop all our docker containers. You can also do that in the Docker Dashboard if you're using a desktop app.

Note: You don't need to stop containers before you run `pnpm dev:start` for a new build.

**Use `pnpm dev:stop` when:**

You don't need the api anymore and want to stop the containers, and you probably don't need a new state next time you want to work with them again. You can start them up again next time with `pnpm dev:restart`.

### ➡️ `pnpm dev:destroy`

This is the alias for `pnpm dev --mode=destroy`.

This will stop and teardown all our docker containers. You can also do that in the Docker Dashboard if you're using a desktop app.

Note: You don't need to destroy containers before you run `pnpm dev:start` for a new build.

**Use `pnpm dev:destroy` when:**

- You don't need the api anymore and want to stop the containers, and you probably will need to use a new build next time anyway.

### ➡️ `pnpm run setup`

This is the alias for `pnpm dev --mode=all --testEnv=true`.

This will build Klaw, the cluster-api and a sandbox environment for klaw (container for zookeeper, kafka, schema-registry). You usually won't need that script, it is a convenient shortcut for the first setup.

### ➡️ additional `--verbose` flag

Adding this flag to any of the mentioned commands will run the proxy in "verbose" mode. We will print **all** requests that are handled in the terminal. This is very noisy, so not enabled by default. It can be a great way to debug in case something is not working like expecting.
Symptom: requests to `http://localhost:1337/api/getAuth` return `302`, followed by a call to
`http://localhost:9097/login` that fails with a CORS error.

## How it works

### These scripts are used by other scripts

- `_internal_use_proxy` starts the proxy.
- `_internal_use_start-coral` starts a vite local development server for Coral.
- `pnpm dev` runs the script `start-proxy-environment.sh` and is the base for all our `dev:` scripts. You _can_ use it with additional flags, but there is no need to.

### Files

- [`config.js`](config.js) contains all configuration for routes and our local ports.
- [`rules.js`](rules.js) util functions for handling rules defined in config.
- [`server.js`](server.js) set up and start of server as well as printing jobs.
- [`start-proxy-environment.sh`](start-proxy-environment.sh) is responsible for parsing the flags, running the correct docker scripts dependent on flags and start the proxy (running `pnpm _internal_use_proxy`) as well as coral (running `pnpm _internal_use_start-coral`).
- `pnpm dev` runs [`start-proxy-environment.sh`](start-proxy-environment.sh). It checks the Docker containers,
calls [`docker-scripts/klaw-docker.sh`](../../docker-scripts/klaw-docker.sh) and starts the proxy and Coral. All
`dev:` scripts are shortcuts for `pnpm dev --mode=<mode>`.
- `_internal_use_proxy` starts the proxy, `_internal_use_start-coral` starts the Vite dev server for Coral. Both are
used by other scripts, you do not need to run them yourself.
- [`config.js`](config.js) contains the routes and local ports, [`rules.js`](rules.js) the helpers for the rules
defined there, and [`server.js`](server.js) starts the server and prints the routes.
5 changes: 2 additions & 3 deletions coral/proxy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
"scripts": {
"_internal_use_proxy": "pnpm exec nodemon server.js",
"_internal_use_start-coral": "cd .. && pnpm vite --mode=local-api",
"setup": "pnpm dev --mode=start --testEnv=true",
"dev": "./start-proxy-environment.sh",
"dev:start": "pnpm dev --mode=start",
"dev:restart": "pnpm dev --mode=restart",
"dev:start:testEnv": "pnpm dev --mode=start --testEnv=true",
"dev:restart:testEnv": "pnpm dev --mode=restart --testEnv=true",
"dev:proxy": "pnpm dev --mode=proxy",
"dev:restart": "pnpm dev --mode=restart",
"dev:stop": "pnpm dev --mode=stop",
"dev:destroy": "pnpm dev --mode=destroy"
},
Expand Down
Loading
Loading