Repository navigation
refactor: Externalize secrets and bind ports to localhost in Docker setup #3081
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
programmiri
wants to merge
3
commits into
main
Choose a base branch
from
docker-secure-config-setup
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.