Dmitry Beresnev commited on
Commit ·
2020c3f
1
Parent(s): a7746cb
fix dockerfile and app
Browse filesFiles changed (2)
- Dockerfile+1-2
- app.py+81-15
29 unmodified lines303132333435363738394029 unmodified linesENV VAULT_PATH=/app/vaultENV OPENCLAW_HOME=/app/.openclawENV OPENCLAW_STATE_DIR=/app/.openclaw/stateENV OPENCLAW_CONFIG_PATH=/app/openclaw.jsonENV AUTO_START_GATEWAY=0RUN mkdir -p /app/vault /app/.openclaw/stateEXPOSE 7860CMD ["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"]29 unmodified lines3031323334353637383929 unmodified linesENV VAULT_PATH=/app/vaultENV OPENCLAW_HOME=/app/.openclawENV OPENCLAW_STATE_DIR=/app/.openclaw/stateENV AUTO_START_GATEWAY=0RUN mkdir -p /app/vault /app/.openclaw/stateEXPOSE 7860CMD ["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"]
123456719 unmodified lines27282930313216 unmodified lines49505152535440 unmodified lines95969798991004 unmodified lines105106107108109110111112113114115116117118119120121122123124125126import jsonimport osimport shutilimport subprocessfrom datetime import datefrom pathlib import Pathfrom urllib.parse import urlencode, urlsplit, urlunsplit, parse_qsl19 unmodified lines"OPENCLAW_STANDARD_UI_URL", f"http://127.0.0.1:{OPENCLAW_PORT}/")OPENCLAW_GATEWAY_TOKEN = os.getenv("OPENCLAW_GATEWAY_TOKEN", "")def resolve_openclaw_bin() -> str | None:16 unmodified linesst.session_state.setdefault("backtest_data", None)st.session_state.setdefault("backtest_params", None)st.session_state.setdefault("backtest_error", "")def load_config_text() -> str:40 unmodified linesbreaklines.append(line.rstrip())append_logs(lines)def start_gateway() -> tuple[bool, str]:4 unmodified linesif binary is None:return False, "OpenClaw binary not found (expected `openclaw` or `clawdbot`)."# `openclaw` and legacy `clawdbot` use different gateway flags.cmd = [binary, "gateway", "--port", str(OPENCLAW_PORT)]if binary == "clawdbot":cmd.extend(["--vault-path", VAULT_PATH])proc = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.STDOUT,text=True,bufsize=1,)if proc.stdout is not None:os.set_blocking(proc.stdout.fileno(), False)st.session_state["gateway_process"] = procappend_logs([f"$ {' '.join(cmd)}", "Gateway process started."])return True, "Gateway started."def stop_gateway() -> tuple[bool, str]:12345678919 unmodified lines2930313233343516 unmodified lines5253545556575840 unmodified lines991001011021031041051061071081091101111121131141151161171181194 unmodified lines124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192import jsonimport osimport shutilimport socketimport subprocessimport timefrom datetime import datefrom pathlib import Pathfrom urllib.parse import urlencode, urlsplit, urlunsplit, parse_qsl19 unmodified lines"OPENCLAW_STANDARD_UI_URL", f"http://127.0.0.1:{OPENCLAW_PORT}/")OPENCLAW_GATEWAY_TOKEN = os.getenv("OPENCLAW_GATEWAY_TOKEN", "")GATEWAY_BOOT_LOG_PATH = Path(os.getenv("OPENCLAW_GATEWAY_LOG_PATH", "/tmp/openclaw-gateway.log"))def resolve_openclaw_bin() -> str | None:16 unmodified linesst.session_state.setdefault("backtest_data", None)st.session_state.setdefault("backtest_params", None)st.session_state.setdefault("backtest_error", "")st.session_state.setdefault("gateway_boot_log_offset", 0)def load_config_text() -> str:40 unmodified linesbreaklines.append(line.rstrip())append_logs(lines)pull_boot_logs()def pull_boot_logs() -> None:if not GATEWAY_BOOT_LOG_PATH.exists():returntry:with GATEWAY_BOOT_LOG_PATH.open("r", encoding="utf-8", errors="ignore") as fh:fh.seek(st.session_state["gateway_boot_log_offset"])new_content = fh.read()st.session_state["gateway_boot_log_offset"] = fh.tell()except Exception:returnif new_content:append_logs([ln for ln in new_content.splitlines() if ln.strip()])def start_gateway() -> tuple[bool, str]:4 unmodified linesif binary is None:return False, "OpenClaw binary not found (expected `openclaw` or `clawdbot`)."candidate_cmds = [[binary, "gateway", "run", "--port", str(OPENCLAW_PORT), "--allow-unconfigured"],[binary, "gateway", "--port", str(OPENCLAW_PORT), "--allow-unconfigured"],]if binary == "clawdbot":candidate_cmds = [[binary, "gateway", "--port", str(OPENCLAW_PORT), "--vault-path", VAULT_PATH],[binary, "gateway", "run", "--port", str(OPENCLAW_PORT), "--vault-path", VAULT_PATH],]last_error = "unknown startup failure"for cmd in candidate_cmds:proc = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.STDOUT,text=True,bufsize=1,)if proc.stdout is not None:os.set_blocking(proc.stdout.fileno(), False)append_logs([f"$ {' '.join(cmd)}"])# Verify the process stays alive and opens the gateway port.deadline = time.time() + 6opened = Falsewhile time.time() < deadline:if proc.poll() is not None:breakwith socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:sock.settimeout(0.3)if sock.connect_ex(("127.0.0.1", OPENCLAW_PORT)) == 0:opened = Truebreaktime.sleep(0.2)if opened:st.session_state["gateway_process"] = procappend_logs(["Gateway process started."])return True, "Gateway started."# Collect some logs for diagnosis before trying next command.fail_lines = []if proc.stdout is not None:try:while True:line = proc.stdout.readline()if not line:breakfail_lines.append(line.rstrip())except BlockingIOError:passif fail_lines:append_logs(fail_lines[-10:])last_error = fail_lines[-1]else:last_error = f"command exited with code {proc.poll()}"try:proc.terminate()except Exception:passreturn False, f"Failed to start gateway ({last_error})."def stop_gateway() -> tuple[bool, str]:
Dockerfile+1-2
app.py+81-15