diff --git a/README.md b/README.md index 6254086..988f878 100644 --- a/README.md +++ b/README.md @@ -14,13 +14,14 @@ Currently this repository is not on [PyPi](https://pypi.org/) but will be added ```mermaid graph TB - subgraph backend[status-im/status-go] - subgraph Endpoints[Network: status-bridge] + subgraph backend[status-im/status-go] + subgraph Endpoints[Network: status-bridge] RPC[RPC] HTTP[REST] SOCKET[Web Socket] end - Vol[(Backup)] + Vol1[(Backup)] + Vol2[(Assets)] end @@ -35,13 +36,14 @@ graph TB EVM end - SDK --> SIGNAL - SDK --> |Port 8080| RPC - SDK --> |Port 8080| HTTP - SIGNAL --> |Port 8080| SOCKET - SDK --> Vol - RPC --> |coingecko_api_key| COINGECKO - RPC --> |infura_token| EVM + SDK --> SIGNAL + SDK --> |Port 8080| RPC + SDK --> |Port 8080| HTTP + SIGNAL --> |Port 8080| SOCKET + SDK --> Vol1 + SDK --> Vol2 + RPC --> |coingecko_api_key| COINGECKO + RPC --> |infura_token| EVM ``` ## Setup @@ -63,16 +65,6 @@ sequenceDiagram Note over User,Python: from bot import Account
account = Account() ``` -### Docker - -Setup [`status-im/status-go`](https://github.com/status-im/status-go/) with the provided `docker-compose.yaml` file. - -``` -docker compose up -d -``` - -**Note**: To run on Windows, please make sure you clone `status-im/status-go` and change the context to the folder. If you do not want to clone the repository, make sure you have set up [WSL](https://learn.microsoft.com/en-us/windows/wsl/install) and started it. - ### Python 1. Setup environment. [Conda](https://www.anaconda.com/) example: @@ -87,3 +79,20 @@ conda create -n status-sdk python=3.12 ```bash pip install -r ./requirements.txt ``` + +### Docker + +Setup [`status-im/status-go`](https://github.com/status-im/status-go/) with the provided `docker-compose.yaml` file. + +``` +docker compose up -d +``` + +If you would like to initialize and start the container with Python: + +```python +from bot import launch_docker_container +launch_docker_container() +``` + +**Note**: To run on Windows, please make sure you clone `status-im/status-go` and change the context to the folder. If you do not want to clone the repository, make sure you have set up [WSL](https://learn.microsoft.com/en-us/windows/wsl/install) and started it. diff --git a/bot/__init__.py b/bot/__init__.py index 301bf3a..7030b2c 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -1 +1,2 @@ from .account import Account +from .utils import launch_docker_container diff --git a/bot/utils.py b/bot/utils.py new file mode 100644 index 0000000..ebfb8db --- /dev/null +++ b/bot/utils.py @@ -0,0 +1,32 @@ +import shutil, os, subprocess, sys +from pathlib import Path + +def launch_docker_container(): + """ + Launch the Status Backend Docker container using `docker-compose.yaml` + """ + is_windows = sys.platform == "win32" + if not shutil.which("docker"): + raise Exception("Please install Docker.") + + DOCKER_COMPOSE_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)), "docker-compose.yaml") + docker_path = DOCKER_COMPOSE_PATH + if is_windows: + p = Path(DOCKER_COMPOSE_PATH) + drive = p.drive.rstrip(":").lower() + docker_path = f"/mnt/{drive}/" + "/".join(p.parts[1:]) + + cmd = ["docker", "compose", "-f", docker_path, "up", "-d"] + if is_windows: + if not shutil.which("wsl"): + raise Exception("Please install wsl - https://learn.microsoft.com/en-us/windows/wsl/install.") + cmd.insert(0, "wsl") + + result = subprocess.run( + cmd, + cwd=os.path.dirname(DOCKER_COMPOSE_PATH), + stderr=subprocess.PIPE, + text=True, + ) + if result.returncode != 0: + raise Exception(result.stderr.strip()) diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md deleted file mode 100644 index b2d1e9f..0000000 --- a/docs/SUMMARY.md +++ /dev/null @@ -1,3 +0,0 @@ -# Summary - -[Account](./account.md) diff --git a/docs/images/overview-utils.png b/docs/images/overview-utils.png new file mode 100644 index 0000000..5716076 Binary files /dev/null and b/docs/images/overview-utils.png differ diff --git a/docs/utils.md b/docs/utils.md new file mode 100644 index 0000000..9ee3210 --- /dev/null +++ b/docs/utils.md @@ -0,0 +1,17 @@ +# Utils + +![Utils header image](./images/overview-utils.png) + +Helper functions for setting up the Status Backend environment. + +## Methods + +### `launch_docker_container()` + +Launch Status Backend Docker container in the background using `docker-compose.yaml`. If `docker` is not installed, or if the container fails to start, an **exception will be raised** with the error message from Docker. + +```python +from bot import launch_docker_container + +launch_docker_container() +```