|
1 |
| -### websockets-notifications demo |
| 1 | +### websockets-notifications Demo |
2 | 2 |
|
3 |
| -#### How to set JWK public key to validate jwt tokens |
4 |
| -One of the options: |
5 |
| -1. By setting the key as an environment variable named `JWT_PUBLIC_KEY`. |
6 |
| -2. By placing the key in a file named `jwt_public_key.pem` inside the `secrets` folder in repo root. |
| 3 | +This project requires Python 3.12+. |
| 4 | +Dependencies are managed by [uv](https://github.com/astral-sh/uv) and should be installed. |
| 5 | +The list of requirements is stored in `pyproject.toml`. |
7 | 6 |
|
8 |
| -If both options are set, the application will not start. |
| 7 | +### Some Facts About Environment Variables: |
| 8 | +1. When running in a container, do not forget to set `WEBSOCKETS_HOST` in the environment variables. In most cases, it should be `0.0.0.0`. |
| 9 | +2. The app requires a JWT public key for authentication. It can be set using one of two options (if both are set, the app will not start): |
| 10 | + 1. Environment variable `JWT_PUBLIC_KEY`. Ensure it has no newlines. Check `env.example` for the correct format. |
| 11 | + 2. A file named `jwt_public_key.pem` inside the `src` directory. |
| 12 | + |
| 13 | +### Develop on a Local Machine |
| 14 | +Install and activate a virtual environment: |
| 15 | +```bash |
| 16 | +uv venv |
| 17 | +source venv/bin/activate |
| 18 | +``` |
| 19 | + |
| 20 | +Set environment variables |
| 21 | +```bash |
| 22 | +cp env.example ./src/.env # default environment variables |
| 23 | +``` |
| 24 | + |
| 25 | +Install requirements: |
| 26 | +```bash |
| 27 | +make # compile and install deps |
| 28 | +``` |
| 29 | + |
| 30 | +Run message broker: |
| 31 | +```bash |
| 32 | +docker compose up -d |
| 33 | +``` |
| 34 | + |
| 35 | +Run server: |
| 36 | +```bash |
| 37 | +cd python src/entrypoint.py |
| 38 | +``` |
| 39 | + |
| 40 | +Connect to the server in cli: |
| 41 | +```bash |
| 42 | +python -m websockets ws://localhost:{% port %}/{% websockets_path % } |
| 43 | +``` |
| 44 | + |
| 45 | +Format code with ruff |
| 46 | +```bash |
| 47 | +make fmt |
| 48 | +``` |
| 49 | + |
| 50 | +Run linters |
| 51 | +```bash |
| 52 | +make lint |
| 53 | +``` |
| 54 | + |
| 55 | +Run tests |
| 56 | +```bash |
| 57 | +make test |
| 58 | +``` |
| 59 | + |
| 60 | +## Build docker image |
| 61 | +If you need to set python version manually |
| 62 | +```bash |
| 63 | +docker build --build-arg "PYTHON_VERSION=3.11.6" --tag websocket-notifications . |
| 64 | +``` |
| 65 | + |
| 66 | +Preferred way is to use `.python-version` file |
| 67 | +```bash |
| 68 | +docker build --build-arg "PYTHON_VERSION=$(cat .python-version)" --tag websocket-notifications . |
| 69 | +``` |
0 commit comments