Skip to content

Commit eaaf049

Browse files
committed
How to run inside docker and how to start
1 parent a14278e commit eaaf049

File tree

3 files changed

+82
-7
lines changed

3 files changed

+82
-7
lines changed

Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
ARG PYTHON_VERSION
2+
FROM python:${PYTHON_VERSION}-slim-bookworm
3+
4+
ADD requirements.txt /
5+
6+
RUN pip install --no-cache-dir -r /requirements.txt
7+
8+
WORKDIR /src
9+
10+
ADD src/ .
11+
12+
USER nobody
13+
14+
ENTRYPOINT ["python", "entrypoint.py"]

README.md

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,69 @@
1-
### websockets-notifications demo
1+
### websockets-notifications Demo
22

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`.
76

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+
```

src/app/conf/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Settings(BaseSettings):
2626
env_file=".env",
2727
env_file_encoding="utf-8",
2828
case_sensitive=True,
29-
secrets_dir="../secrets",
29+
secrets_dir=".",
3030
)
3131

3232

0 commit comments

Comments
 (0)