Dmitry Beresnev commited on
Commit ·
2020c3f
1
Parent(s): a7746cb
fix dockerfile and app
Browse files- Dockerfile +1 -2
- app.py +81 -15
Dockerfile
CHANGED
|
@@ -30,11 +30,10 @@ ENV OPENCLAW_BIN=openclaw
|
|
| 30 |
ENV VAULT_PATH=/app/vault
|
| 31 |
ENV OPENCLAW_HOME=/app/.openclaw
|
| 32 |
ENV OPENCLAW_STATE_DIR=/app/.openclaw/state
|
| 33 |
-
ENV OPENCLAW_CONFIG_PATH=/app/openclaw.json
|
| 34 |
ENV AUTO_START_GATEWAY=0
|
| 35 |
|
| 36 |
RUN mkdir -p /app/vault /app/.openclaw/state
|
| 37 |
|
| 38 |
EXPOSE 7860
|
| 39 |
|
| 40 |
-
CMD ["sh", "-c", "${OPENCLAW_BIN} gateway --port ${OPENCLAW_PORT} > /tmp/openclaw-gateway.log 2>&1 & exec uv run streamlit run app.py --server.address=0.0.0.0 --server.port=7860"]
|
|
|
|
| 30 |
ENV VAULT_PATH=/app/vault
|
| 31 |
ENV OPENCLAW_HOME=/app/.openclaw
|
| 32 |
ENV OPENCLAW_STATE_DIR=/app/.openclaw/state
|
|
|
|
| 33 |
ENV AUTO_START_GATEWAY=0
|
| 34 |
|
| 35 |
RUN mkdir -p /app/vault /app/.openclaw/state
|
| 36 |
|
| 37 |
EXPOSE 7860
|
| 38 |
|
| 39 |
+
CMD ["sh", "-c", "${OPENCLAW_BIN} gateway run --port ${OPENCLAW_PORT} --allow-unconfigured > /tmp/openclaw-gateway.log 2>&1 & exec uv run streamlit run app.py --server.address=0.0.0.0 --server.port=7860"]
|
app.py
CHANGED
|
@@ -1,7 +1,9 @@
|
|
| 1 |
import json
|
| 2 |
import os
|
| 3 |
import shutil
|
|
|
|
| 4 |
import subprocess
|
|
|
|
| 5 |
from datetime import date
|
| 6 |
from pathlib import Path
|
| 7 |
from urllib.parse import urlencode, urlsplit, urlunsplit, parse_qsl
|
|
@@ -27,6 +29,7 @@ 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:
|
|
@@ -49,6 +52,7 @@ def init_state() -> None:
|
|
| 49 |
st.session_state.setdefault("backtest_data", None)
|
| 50 |
st.session_state.setdefault("backtest_params", None)
|
| 51 |
st.session_state.setdefault("backtest_error", "")
|
|
|
|
| 52 |
|
| 53 |
|
| 54 |
def load_config_text() -> str:
|
|
@@ -95,6 +99,21 @@ def pull_logs() -> None:
|
|
| 95 |
break
|
| 96 |
lines.append(line.rstrip())
|
| 97 |
append_logs(lines)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
|
| 99 |
|
| 100 |
def start_gateway() -> tuple[bool, str]:
|
|
@@ -105,22 +124,69 @@ def start_gateway() -> tuple[bool, str]:
|
|
| 105 |
if binary is None:
|
| 106 |
return False, "OpenClaw binary not found (expected `openclaw` or `clawdbot`)."
|
| 107 |
|
| 108 |
-
|
| 109 |
-
|
|
|
|
|
|
|
| 110 |
if binary == "clawdbot":
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
|
| 126 |
def stop_gateway() -> tuple[bool, str]:
|
|
|
|
| 1 |
import json
|
| 2 |
import os
|
| 3 |
import shutil
|
| 4 |
+
import socket
|
| 5 |
import subprocess
|
| 6 |
+
import time
|
| 7 |
from datetime import date
|
| 8 |
from pathlib import Path
|
| 9 |
from urllib.parse import urlencode, urlsplit, urlunsplit, parse_qsl
|
|
|
|
| 29 |
"OPENCLAW_STANDARD_UI_URL", f"http://127.0.0.1:{OPENCLAW_PORT}/"
|
| 30 |
)
|
| 31 |
OPENCLAW_GATEWAY_TOKEN = os.getenv("OPENCLAW_GATEWAY_TOKEN", "")
|
| 32 |
+
GATEWAY_BOOT_LOG_PATH = Path(os.getenv("OPENCLAW_GATEWAY_LOG_PATH", "/tmp/openclaw-gateway.log"))
|
| 33 |
|
| 34 |
|
| 35 |
def resolve_openclaw_bin() -> str | None:
|
|
|
|
| 52 |
st.session_state.setdefault("backtest_data", None)
|
| 53 |
st.session_state.setdefault("backtest_params", None)
|
| 54 |
st.session_state.setdefault("backtest_error", "")
|
| 55 |
+
st.session_state.setdefault("gateway_boot_log_offset", 0)
|
| 56 |
|
| 57 |
|
| 58 |
def load_config_text() -> str:
|
|
|
|
| 99 |
break
|
| 100 |
lines.append(line.rstrip())
|
| 101 |
append_logs(lines)
|
| 102 |
+
pull_boot_logs()
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
def pull_boot_logs() -> None:
|
| 106 |
+
if not GATEWAY_BOOT_LOG_PATH.exists():
|
| 107 |
+
return
|
| 108 |
+
try:
|
| 109 |
+
with GATEWAY_BOOT_LOG_PATH.open("r", encoding="utf-8", errors="ignore") as fh:
|
| 110 |
+
fh.seek(st.session_state["gateway_boot_log_offset"])
|
| 111 |
+
new_content = fh.read()
|
| 112 |
+
st.session_state["gateway_boot_log_offset"] = fh.tell()
|
| 113 |
+
except Exception:
|
| 114 |
+
return
|
| 115 |
+
if new_content:
|
| 116 |
+
append_logs([ln for ln in new_content.splitlines() if ln.strip()])
|
| 117 |
|
| 118 |
|
| 119 |
def start_gateway() -> tuple[bool, str]:
|
|
|
|
| 124 |
if binary is None:
|
| 125 |
return False, "OpenClaw binary not found (expected `openclaw` or `clawdbot`)."
|
| 126 |
|
| 127 |
+
candidate_cmds = [
|
| 128 |
+
[binary, "gateway", "run", "--port", str(OPENCLAW_PORT), "--allow-unconfigured"],
|
| 129 |
+
[binary, "gateway", "--port", str(OPENCLAW_PORT), "--allow-unconfigured"],
|
| 130 |
+
]
|
| 131 |
if binary == "clawdbot":
|
| 132 |
+
candidate_cmds = [
|
| 133 |
+
[binary, "gateway", "--port", str(OPENCLAW_PORT), "--vault-path", VAULT_PATH],
|
| 134 |
+
[binary, "gateway", "run", "--port", str(OPENCLAW_PORT), "--vault-path", VAULT_PATH],
|
| 135 |
+
]
|
| 136 |
+
|
| 137 |
+
last_error = "unknown startup failure"
|
| 138 |
+
for cmd in candidate_cmds:
|
| 139 |
+
proc = subprocess.Popen(
|
| 140 |
+
cmd,
|
| 141 |
+
stdout=subprocess.PIPE,
|
| 142 |
+
stderr=subprocess.STDOUT,
|
| 143 |
+
text=True,
|
| 144 |
+
bufsize=1,
|
| 145 |
+
)
|
| 146 |
+
if proc.stdout is not None:
|
| 147 |
+
os.set_blocking(proc.stdout.fileno(), False)
|
| 148 |
+
append_logs([f"$ {' '.join(cmd)}"])
|
| 149 |
+
|
| 150 |
+
# Verify the process stays alive and opens the gateway port.
|
| 151 |
+
deadline = time.time() + 6
|
| 152 |
+
opened = False
|
| 153 |
+
while time.time() < deadline:
|
| 154 |
+
if proc.poll() is not None:
|
| 155 |
+
break
|
| 156 |
+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
| 157 |
+
sock.settimeout(0.3)
|
| 158 |
+
if sock.connect_ex(("127.0.0.1", OPENCLAW_PORT)) == 0:
|
| 159 |
+
opened = True
|
| 160 |
+
break
|
| 161 |
+
time.sleep(0.2)
|
| 162 |
+
|
| 163 |
+
if opened:
|
| 164 |
+
st.session_state["gateway_process"] = proc
|
| 165 |
+
append_logs(["Gateway process started."])
|
| 166 |
+
return True, "Gateway started."
|
| 167 |
+
|
| 168 |
+
# Collect some logs for diagnosis before trying next command.
|
| 169 |
+
fail_lines = []
|
| 170 |
+
if proc.stdout is not None:
|
| 171 |
+
try:
|
| 172 |
+
while True:
|
| 173 |
+
line = proc.stdout.readline()
|
| 174 |
+
if not line:
|
| 175 |
+
break
|
| 176 |
+
fail_lines.append(line.rstrip())
|
| 177 |
+
except BlockingIOError:
|
| 178 |
+
pass
|
| 179 |
+
if fail_lines:
|
| 180 |
+
append_logs(fail_lines[-10:])
|
| 181 |
+
last_error = fail_lines[-1]
|
| 182 |
+
else:
|
| 183 |
+
last_error = f"command exited with code {proc.poll()}"
|
| 184 |
+
try:
|
| 185 |
+
proc.terminate()
|
| 186 |
+
except Exception:
|
| 187 |
+
pass
|
| 188 |
+
|
| 189 |
+
return False, f"Failed to start gateway ({last_error})."
|
| 190 |
|
| 191 |
|
| 192 |
def stop_gateway() -> tuple[bool, str]:
|