docker: Choose GitHub commit

This commit is contained in:
Nick Ninov
2026-06-29 22:28:21 +03:00
parent be0650d94e
commit 4c6c4d7c8c
3 changed files with 21 additions and 5 deletions
+6 -2
View File
@@ -1,13 +1,15 @@
import shutil, os, subprocess, sys, time
from pathlib import Path
from typing import Optional
from .logger import Logger
from . import exceptions
def launch_docker_container(wait_seconds: int = 5):
def launch_docker_container(commit: Optional[str] = None, wait_seconds: int = 5):
"""
Launch the Status Backend Docker container using `docker-compose.yaml`
Parameters:
- `commit` - the commit SHA. If no commit is provided, the latest version is pulled
- `wait_seconds` - nunmber of seconds to wait before the code resumes. Sleep prevents calling `class Account` faster than launching the docker container. This only happens when the container already exists and it is must be turned on.
"""
logger = Logger()
@@ -17,6 +19,7 @@ def launch_docker_container(wait_seconds: int = 5):
raise exceptions.DockerError("Please install Docker.")
logger.info(f"Running Docker on {platform}")
ref = commit if commit else "develop"
DOCKER_COMPOSE_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)), "docker-compose.yaml")
docker_path = DOCKER_COMPOSE_PATH
if is_windows:
@@ -24,7 +27,8 @@ def launch_docker_container(wait_seconds: int = 5):
drive = p.drive.rstrip(":").lower()
docker_path = f"/mnt/{drive}/" + "/".join(p.parts[1:])
cmd = ["docker", "compose", "-f", docker_path, "up", "-d"]
cmd = ["env", f"STATUS_GO_REF={ref}", "docker", "compose", "-f", docker_path, "up", "-d", "--build"]
if is_windows:
if not shutil.which("wsl"):
raise exceptions.DockerError("Please install wsl - https://learn.microsoft.com/en-us/windows/wsl/install.")
+1 -1
View File
@@ -1,7 +1,7 @@
services:
backend:
build:
context: https://github.com/status-im/status-go.git#develop
context: https://github.com/status-im/status-go.git#${STATUS_GO_REF:-develop}
platform: linux/amd64
container_name: status-backend
ports:
+14 -2
View File
@@ -6,18 +6,30 @@ Helper functions for setting up the Status Backend environment.
## Methods
### `launch_docker_container(wait_seconds=5)`
### `launch_docker_container(commit=None, wait_seconds=5)`
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.
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. The container is built from [`status-im/status-go`](https://github.com/status-im/status-go) at the git ref you choose:
```yaml
context: https://github.com/status-im/status-go.git#${STATUS_GO_REF:-develop}
```
The image is always rebuilt (`docker compose up --build`) so a newly chosen `commit` is picked up instead of reusing a previously built image.
| Name | Type | Required | Description |
|-----|-----|-----|-------------|
| `commit` | `str` | No | The `status-im/status-go` git ref to build from - a commit SHA, branch, or tag. When omitted, the latest `develop` branch is built. |
| `wait_seconds` | `int` | No | Number of seconds to pause after the `docker compose up` command returns, giving Status Backend enough time to finish booting before subsequent code runs. Defaults to `5`. This matters mainly when the container already exists and is being restarted, because `docker compose up` returns immediately while the backend is still warming up - instantiating [`Account`](./account.md#accountdomainlocalhost-port8080-is_securefalse-backup_foldernone) too quickly will fail to connect. |
```python
from bot import launch_docker_container
# Build from the latest develop branch
launch_docker_container(wait_seconds=10)
# Pin a specific status-go commit
# https://github.com/status-im/status-go/commit/2bee8b6a38cdc8f92d74e2dbb8c4e77fbbeea149
launch_docker_container(commit="2bee8b6a38cdc8f92d74e2dbb8c4e77fbbeea149")
```
**Windows Note**: In Docker go to `Settings > Resources > WSL integration` and make sure `Enable integration with my default WSL distro` and `Ubuntu` are **turned on**.