-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
How to run inside docker and how to start
- Loading branch information
Showing
3 changed files
with
82 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
ARG PYTHON_VERSION | ||
FROM python:${PYTHON_VERSION}-slim-bookworm | ||
|
||
ADD requirements.txt / | ||
|
||
RUN pip install --no-cache-dir -r /requirements.txt | ||
|
||
WORKDIR /src | ||
|
||
ADD src/ . | ||
|
||
USER nobody | ||
|
||
ENTRYPOINT ["python", "entrypoint.py"] |
This file contains 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,8 +1,69 @@ | ||
### websockets-notifications demo | ||
### websockets-notifications Demo | ||
|
||
#### How to set JWK public key to validate jwt tokens | ||
One of the options: | ||
1. By setting the key as an environment variable named `JWT_PUBLIC_KEY`. | ||
2. By placing the key in a file named `jwt_public_key.pem` inside the `secrets` folder in repo root. | ||
This project requires Python 3.12+. | ||
Dependencies are managed by [uv](https://github.com/astral-sh/uv) and should be installed. | ||
The list of requirements is stored in `pyproject.toml`. | ||
|
||
If both options are set, the application will not start. | ||
### Some Facts About Environment Variables: | ||
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`. | ||
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): | ||
1. Environment variable `JWT_PUBLIC_KEY`. Ensure it has no newlines. Check `env.example` for the correct format. | ||
2. A file named `jwt_public_key.pem` inside the `src` directory. | ||
|
||
### Develop on a Local Machine | ||
Install and activate a virtual environment: | ||
```bash | ||
uv venv | ||
source venv/bin/activate | ||
``` | ||
|
||
Set environment variables | ||
```bash | ||
cp env.example ./src/.env # default environment variables | ||
``` | ||
|
||
Install requirements: | ||
```bash | ||
make # compile and install deps | ||
``` | ||
|
||
Run message broker: | ||
```bash | ||
docker compose up -d | ||
``` | ||
|
||
Run server: | ||
```bash | ||
cd python src/entrypoint.py | ||
``` | ||
|
||
Connect to the server in cli: | ||
```bash | ||
python -m websockets ws://localhost:{% port %}/{% websockets_path % } | ||
``` | ||
|
||
Format code with ruff | ||
```bash | ||
make fmt | ||
``` | ||
|
||
Run linters | ||
```bash | ||
make lint | ||
``` | ||
|
||
Run tests | ||
```bash | ||
make test | ||
``` | ||
|
||
## Build docker image | ||
If you need to set python version manually | ||
```bash | ||
docker build --build-arg "PYTHON_VERSION=3.11.6" --tag websocket-notifications . | ||
``` | ||
|
||
Preferred way is to use `.python-version` file | ||
```bash | ||
docker build --build-arg "PYTHON_VERSION=$(cat .python-version)" --tag websocket-notifications . | ||
``` |
This file contains 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