Dmitry Beresnev commited on
Commit ·
718b531
1
Parent(s): e890083
fix dockerfile and UI
Browse files- Dockerfile +1 -1
- app.py +29 -15
Dockerfile
CHANGED
|
@@ -25,7 +25,7 @@ RUN uv sync --no-dev
|
|
| 25 |
COPY . /app
|
| 26 |
|
| 27 |
ENV PORT=7860
|
| 28 |
-
ENV OPENCLAW_PORT=
|
| 29 |
ENV OPENCLAW_BIN=openclaw
|
| 30 |
ENV VAULT_PATH=/app/vault
|
| 31 |
ENV OPENCLAW_HOME=/app/.openclaw
|
|
|
|
| 25 |
COPY . /app
|
| 26 |
|
| 27 |
ENV PORT=7860
|
| 28 |
+
ENV OPENCLAW_PORT=18789
|
| 29 |
ENV OPENCLAW_BIN=openclaw
|
| 30 |
ENV VAULT_PATH=/app/vault
|
| 31 |
ENV OPENCLAW_HOME=/app/.openclaw
|
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import shutil
|
|
| 4 |
import subprocess
|
| 5 |
from datetime import date
|
| 6 |
from pathlib import Path
|
|
|
|
| 7 |
|
| 8 |
import pandas as pd
|
| 9 |
import requests
|
|
@@ -16,13 +17,16 @@ from tools.backtesting_runner import (
|
|
| 16 |
)
|
| 17 |
|
| 18 |
HF_PORT = int(os.getenv("PORT", "7860"))
|
| 19 |
-
OPENCLAW_PORT = int(os.getenv("OPENCLAW_PORT", "
|
| 20 |
VAULT_PATH = os.getenv("VAULT_PATH", "/app/vault")
|
| 21 |
OPENCLAW_BIN_ENV = os.getenv("OPENCLAW_BIN", "openclaw")
|
| 22 |
CONFIG_PATH = Path(os.getenv("OPENCLAW_CONFIG_PATH", "openclaw.json"))
|
| 23 |
ENV_EXAMPLE_PATH = Path("config/openclaw.env.example")
|
| 24 |
LOG_MAX_LINES = 300
|
| 25 |
-
OPENCLAW_STANDARD_UI_URL = os.getenv(
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
|
| 28 |
def resolve_openclaw_bin() -> str | None:
|
|
@@ -100,14 +104,10 @@ def start_gateway() -> tuple[bool, str]:
|
|
| 100 |
if binary is None:
|
| 101 |
return False, "OpenClaw binary not found (expected `openclaw` or `clawdbot`)."
|
| 102 |
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
"--
|
| 107 |
-
str(OPENCLAW_PORT),
|
| 108 |
-
"--vault-path",
|
| 109 |
-
VAULT_PATH,
|
| 110 |
-
]
|
| 111 |
proc = subprocess.Popen(
|
| 112 |
cmd,
|
| 113 |
stdout=subprocess.PIPE,
|
|
@@ -170,6 +170,15 @@ def test_gateway(query: str) -> str:
|
|
| 170 |
return f"Gateway request failed: {exc}"
|
| 171 |
|
| 172 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
def build_strategy_frame(data: pd.DataFrame, fast_period: int, slow_period: int) -> pd.DataFrame:
|
| 174 |
frame = pd.DataFrame(index=data.index)
|
| 175 |
frame["Close"] = data["Close"]
|
|
@@ -274,20 +283,25 @@ std_ui_status_col, std_ui_embed_col = st.columns([1, 3])
|
|
| 274 |
with std_ui_status_col:
|
| 275 |
ui_ok = False
|
| 276 |
ui_status_text = "Unavailable"
|
|
|
|
| 277 |
try:
|
| 278 |
-
ui_resp = requests.get(
|
| 279 |
-
|
| 280 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 281 |
except Exception:
|
| 282 |
ui_ok = False
|
| 283 |
st.markdown(
|
| 284 |
f"Status: {':green_circle:' if ui_ok else ':red_circle:'} {ui_status_text}"
|
| 285 |
)
|
| 286 |
-
st.caption(f"URL: {
|
| 287 |
|
| 288 |
with std_ui_embed_col:
|
| 289 |
if ui_ok:
|
| 290 |
-
components.iframe(
|
| 291 |
else:
|
| 292 |
st.info("Standard UI is not reachable yet. Start gateway and refresh.")
|
| 293 |
|
|
|
|
| 4 |
import subprocess
|
| 5 |
from datetime import date
|
| 6 |
from pathlib import Path
|
| 7 |
+
from urllib.parse import urlencode, urlsplit, urlunsplit, parse_qsl
|
| 8 |
|
| 9 |
import pandas as pd
|
| 10 |
import requests
|
|
|
|
| 17 |
)
|
| 18 |
|
| 19 |
HF_PORT = int(os.getenv("PORT", "7860"))
|
| 20 |
+
OPENCLAW_PORT = int(os.getenv("OPENCLAW_PORT", "18789"))
|
| 21 |
VAULT_PATH = os.getenv("VAULT_PATH", "/app/vault")
|
| 22 |
OPENCLAW_BIN_ENV = os.getenv("OPENCLAW_BIN", "openclaw")
|
| 23 |
CONFIG_PATH = Path(os.getenv("OPENCLAW_CONFIG_PATH", "openclaw.json"))
|
| 24 |
ENV_EXAMPLE_PATH = Path("config/openclaw.env.example")
|
| 25 |
LOG_MAX_LINES = 300
|
| 26 |
+
OPENCLAW_STANDARD_UI_URL = os.getenv(
|
| 27 |
+
"OPENCLAW_STANDARD_UI_URL", f"http://127.0.0.1:{OPENCLAW_PORT}/"
|
| 28 |
+
)
|
| 29 |
+
OPENCLAW_GATEWAY_TOKEN = os.getenv("OPENCLAW_GATEWAY_TOKEN", "")
|
| 30 |
|
| 31 |
|
| 32 |
def resolve_openclaw_bin() -> str | None:
|
|
|
|
| 104 |
if binary is None:
|
| 105 |
return False, "OpenClaw binary not found (expected `openclaw` or `clawdbot`)."
|
| 106 |
|
| 107 |
+
# `openclaw` and legacy `clawdbot` use different gateway flags.
|
| 108 |
+
cmd = [binary, "gateway", "--port", str(OPENCLAW_PORT)]
|
| 109 |
+
if binary == "clawdbot":
|
| 110 |
+
cmd.extend(["--vault-path", VAULT_PATH])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
proc = subprocess.Popen(
|
| 112 |
cmd,
|
| 113 |
stdout=subprocess.PIPE,
|
|
|
|
| 170 |
return f"Gateway request failed: {exc}"
|
| 171 |
|
| 172 |
|
| 173 |
+
def with_token(url: str, token: str) -> str:
|
| 174 |
+
if not token:
|
| 175 |
+
return url
|
| 176 |
+
parts = urlsplit(url)
|
| 177 |
+
query = dict(parse_qsl(parts.query, keep_blank_values=True))
|
| 178 |
+
query.setdefault("token", token)
|
| 179 |
+
return urlunsplit((parts.scheme, parts.netloc, parts.path, urlencode(query), parts.fragment))
|
| 180 |
+
|
| 181 |
+
|
| 182 |
def build_strategy_frame(data: pd.DataFrame, fast_period: int, slow_period: int) -> pd.DataFrame:
|
| 183 |
frame = pd.DataFrame(index=data.index)
|
| 184 |
frame["Close"] = data["Close"]
|
|
|
|
| 283 |
with std_ui_status_col:
|
| 284 |
ui_ok = False
|
| 285 |
ui_status_text = "Unavailable"
|
| 286 |
+
std_ui_url = with_token(OPENCLAW_STANDARD_UI_URL, OPENCLAW_GATEWAY_TOKEN)
|
| 287 |
try:
|
| 288 |
+
ui_resp = requests.get(std_ui_url, timeout=2, allow_redirects=True)
|
| 289 |
+
# 401/403 means gateway is up but auth is required.
|
| 290 |
+
ui_ok = ui_resp.status_code < 500
|
| 291 |
+
if ui_resp.status_code in (401, 403):
|
| 292 |
+
ui_status_text = f"Available (auth required, HTTP {ui_resp.status_code})"
|
| 293 |
+
else:
|
| 294 |
+
ui_status_text = "Available" if ui_ok else f"HTTP {ui_resp.status_code}"
|
| 295 |
except Exception:
|
| 296 |
ui_ok = False
|
| 297 |
st.markdown(
|
| 298 |
f"Status: {':green_circle:' if ui_ok else ':red_circle:'} {ui_status_text}"
|
| 299 |
)
|
| 300 |
+
st.caption(f"URL: {std_ui_url}")
|
| 301 |
|
| 302 |
with std_ui_embed_col:
|
| 303 |
if ui_ok:
|
| 304 |
+
components.iframe(std_ui_url, height=560, scrolling=True)
|
| 305 |
else:
|
| 306 |
st.info("Standard UI is not reachable yet. Start gateway and refresh.")
|
| 307 |
|