Skip to content

Commit

Permalink
How to run inside docker and how to start
Browse files Browse the repository at this point in the history
  • Loading branch information
nkiryanov committed Jun 14, 2024
1 parent a14278e commit eaaf049
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 7 deletions.
14 changes: 14 additions & 0 deletions Dockerfile
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"]
73 changes: 67 additions & 6 deletions README.md
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 .
```
2 changes: 1 addition & 1 deletion src/app/conf/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Settings(BaseSettings):
env_file=".env",
env_file_encoding="utf-8",
case_sensitive=True,
secrets_dir="../secrets",
secrets_dir=".",
)


Expand Down

0 comments on commit eaaf049

Please sign in to comment.