Skip to content
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

Fetching initial peers from env variables #12

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,16 @@ To monitor your private swarm instead of the public one, please replace `PUBLIC_
```python
INITIAL_PEERS = ['/ip4/10.1.2.3/tcp/31234/p2p/QmcXhze98AcgGQDDYna23s4Jho96n8wkwLJv78vxtFNq44']
```

Or you can set the `INITIAL_PEERS` environment variable in the `docker-compose` as a comma separated list instead of editing the config file directly:

```yaml
version: '3.7'
services:
app:
image: petals/health-monitor
ports:
- 5000:5000
environment:
- INITIAL_PEERS=/ip4/209.38.217.30/tcp/31337/p2p/QmecL18cmRaDdAcRmA7Ctj1gyAeUYG433WppA1UWTHTew6,/ip4/127.0.0.1/tcp/31337/p2p/QmecL18cmRaDdAcRmA7Ctj1gyAeUYG433WppA1UWTHTew6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- INITIAL_PEERS=/ip4/209.38.217.30/tcp/31337/p2p/QmecL18cmRaDdAcRmA7Ctj1gyAeUYG433WppA1UWTHTew6,/ip4/127.0.0.1/tcp/31337/p2p/QmecL18cmRaDdAcRmA7Ctj1gyAeUYG433WppA1UWTHTew6
- INITIAL_PEERS=/ip4/209.38.217.30/tcp/31337/p2p/QmecL18cmRaDdAcRmA7Ctj1gyAeUYG433WppA1UWTHTew6 /ip4/127.0.0.1/tcp/31337/p2p/QmecL18cmRaDdAcRmA7Ctj1gyAeUYG433WppA1UWTHTew6

```
9 changes: 7 additions & 2 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import os
from petals.constants import PUBLIC_INITIAL_PEERS

from data_structures import ModelInfo


INITIAL_PEERS = PUBLIC_INITIAL_PEERS
initial_peers_str = os.getenv("INITIAL_PEERS")
initial_peers_list = initial_peers_str.split(",") if initial_peers_str else []
if len(initial_peers_list) > 0:
INITIAL_PEERS = initial_peers_list
else:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggest moving from petals.constants import PUBLIC_INITIAL_PEERS into the else branch

INITIAL_PEERS = PUBLIC_INITIAL_PEERS
Comment on lines +6 to +11
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
initial_peers_str = os.getenv("INITIAL_PEERS")
initial_peers_list = initial_peers_str.split(",") if initial_peers_str else []
if len(initial_peers_list) > 0:
INITIAL_PEERS = initial_peers_list
else:
INITIAL_PEERS = PUBLIC_INITIAL_PEERS
INITIAL_PEERS = PUBLIC_INITIAL_PEERS
if value := os.getenv("INITIAL_PEERS"): # Override with the env variable if defined
INITIAL_PEERS = value.split()

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not super familiar with python, but redefining a constant like that seems unexpected


MODELS = [
ModelInfo(
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ services:
volumes:
- .:/usr/src/app
ports:
- "5000:5000"
- "5000:5000"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep the diff minimal and revert this change :)