Spaces:
Running
Running
Final Submission: Added SOC Dashboard and fixed UI explorer
Browse files- Dockerfile +3 -2
- openenv.yaml +1 -2
- server/app.py +0 -73
- start.sh +10 -7
Dockerfile
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
FROM python:3.11-slim
|
| 2 |
|
| 3 |
-
# System dependencies (docker.io for Docker-in-Docker sandbox)
|
| 4 |
RUN apt-get update \
|
| 5 |
-
&& apt-get install -y --no-install-recommends curl docker.io \
|
| 6 |
&& rm -rf /var/lib/apt/lists/*
|
| 7 |
|
| 8 |
WORKDIR /app
|
|
@@ -18,6 +18,7 @@ COPY openenv.yaml .
|
|
| 18 |
COPY pyproject.toml .
|
| 19 |
COPY inference.py .
|
| 20 |
COPY config.yaml .
|
|
|
|
| 21 |
|
| 22 |
# Copy and configure the startup script
|
| 23 |
COPY start.sh .
|
|
|
|
| 1 |
FROM python:3.11-slim
|
| 2 |
|
| 3 |
+
# System dependencies (docker.io for Docker-in-Docker sandbox, nginx for proxying)
|
| 4 |
RUN apt-get update \
|
| 5 |
+
&& apt-get install -y --no-install-recommends curl docker.io nginx gettext-base \
|
| 6 |
&& rm -rf /var/lib/apt/lists/*
|
| 7 |
|
| 8 |
WORKDIR /app
|
|
|
|
| 18 |
COPY pyproject.toml .
|
| 19 |
COPY inference.py .
|
| 20 |
COPY config.yaml .
|
| 21 |
+
COPY nginx.conf /etc/nginx/nginx.conf
|
| 22 |
|
| 23 |
# Copy and configure the startup script
|
| 24 |
COPY start.sh .
|
openenv.yaml
CHANGED
|
@@ -2,8 +2,7 @@ name: PatchHawk
|
|
| 2 |
version: 1.0.0
|
| 3 |
spec_version: 1
|
| 4 |
type: space
|
| 5 |
-
runtime:
|
| 6 |
-
app: server.app:app
|
| 7 |
port: 7860
|
| 8 |
description: Detect and patch supply-chain vulnerabilities in Python code.
|
| 9 |
tags: [security, supply-chain, code-review, llm-agent]
|
|
|
|
| 2 |
version: 1.0.0
|
| 3 |
spec_version: 1
|
| 4 |
type: space
|
| 5 |
+
runtime: docker
|
|
|
|
| 6 |
port: 7860
|
| 7 |
description: Detect and patch supply-chain vulnerabilities in Python code.
|
| 8 |
tags: [security, supply-chain, code-review, llm-agent]
|
server/app.py
CHANGED
|
@@ -1,18 +1,5 @@
|
|
| 1 |
"""
|
| 2 |
PatchHawk OpenEnv server entry point.
|
| 3 |
-
|
| 4 |
-
This file satisfies the ``openenv validate`` requirement for a
|
| 5 |
-
``server/app.py`` module that exposes a ``main()`` function.
|
| 6 |
-
|
| 7 |
-
Run directly:
|
| 8 |
-
python server/app.py
|
| 9 |
-
python server/app.py --port 7860
|
| 10 |
-
|
| 11 |
-
Or via the project script:
|
| 12 |
-
server (after pip install -e .)
|
| 13 |
-
|
| 14 |
-
Or via openenv serve (Docker / deployment):
|
| 15 |
-
openenv serve --env patchhawk.agent.environment:PatchHawkEnv --port 7860
|
| 16 |
"""
|
| 17 |
|
| 18 |
from __future__ import annotations
|
|
@@ -27,21 +14,14 @@ if _PROJECT_ROOT not in sys.path:
|
|
| 27 |
sys.path.insert(0, _PROJECT_ROOT)
|
| 28 |
|
| 29 |
from openenv.core import create_app
|
| 30 |
-
|
| 31 |
from patchhawk.agent.environment import PatchHawkEnv
|
| 32 |
from patchhawk.env_models import PatchHawkAction, PatchHawkObservation
|
| 33 |
-
from fastapi.responses import HTMLResponse, StreamingResponse
|
| 34 |
-
import httpx
|
| 35 |
-
from starlette.requests import Request
|
| 36 |
-
from starlette.background import BackgroundTask
|
| 37 |
-
|
| 38 |
|
| 39 |
def _env_factory() -> PatchHawkEnv:
|
| 40 |
"""Factory callable for create_app — returns a fresh PatchHawkEnv instance."""
|
| 41 |
scenarios_path = os.getenv("PATCHHAWK_SCENARIOS", "patchhawk/data/scenarios.json")
|
| 42 |
return PatchHawkEnv(scenarios_path=scenarios_path, use_docker=False)
|
| 43 |
|
| 44 |
-
|
| 45 |
def create_openenv_app():
|
| 46 |
"""Create the OpenEnv FastAPI application."""
|
| 47 |
return create_app(
|
|
@@ -51,65 +31,13 @@ def create_openenv_app():
|
|
| 51 |
env_name="PatchHawk",
|
| 52 |
)
|
| 53 |
|
| 54 |
-
|
| 55 |
app = create_openenv_app()
|
| 56 |
|
| 57 |
-
# ── Streamlit Proxy Configuration ─────────────────────────────────────
|
| 58 |
-
STREAMLIT_URL = "http://localhost:8501"
|
| 59 |
-
|
| 60 |
-
@app.api_route("/{path:path}", methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"])
|
| 61 |
-
async def proxy_streamlit(request: Request, path: str):
|
| 62 |
-
"""
|
| 63 |
-
Proxies all requests not handled by OpenEnv routes to the local Streamlit server.
|
| 64 |
-
This ensures the Streamlit Dashboard is the primary UI on port 7860.
|
| 65 |
-
"""
|
| 66 |
-
# Skip proxying for OpenEnv specific routes so the grader still works
|
| 67 |
-
openenv_routes = ["reset", "step", "docs", "openapi.json", "web", "assets"]
|
| 68 |
-
if any(path.startswith(r) for r in openenv_routes) or path == "":
|
| 69 |
-
if path == "":
|
| 70 |
-
# Redirect root to Streamlit
|
| 71 |
-
pass
|
| 72 |
-
else:
|
| 73 |
-
# Let FastAPI handle it
|
| 74 |
-
return
|
| 75 |
-
|
| 76 |
-
client = httpx.AsyncClient(base_url=STREAMLIT_URL)
|
| 77 |
-
url = httpx.URL(path=request.url.path, query=request.url.query.encode("utf-8"))
|
| 78 |
-
|
| 79 |
-
# Filter out headers that might cause issues with the proxy
|
| 80 |
-
headers = {k: v for k, v in request.headers.items() if k.lower() not in ["host", "connection"]}
|
| 81 |
-
|
| 82 |
-
# Handle the request body
|
| 83 |
-
body = await request.body()
|
| 84 |
-
|
| 85 |
-
# Forward the request to Streamlit
|
| 86 |
-
rp_resp = await client.request(
|
| 87 |
-
method=request.method,
|
| 88 |
-
url=url,
|
| 89 |
-
headers=headers,
|
| 90 |
-
content=body,
|
| 91 |
-
follow_redirects=True,
|
| 92 |
-
)
|
| 93 |
-
|
| 94 |
-
return StreamingResponse(
|
| 95 |
-
rp_resp.aiter_raw(),
|
| 96 |
-
status_code=rp_resp.status_code,
|
| 97 |
-
headers=dict(rp_resp.headers),
|
| 98 |
-
background=BackgroundTask(client.aclose)
|
| 99 |
-
)
|
| 100 |
-
|
| 101 |
-
@app.get("/", response_class=HTMLResponse)
|
| 102 |
-
async def root_redirect(request: Request):
|
| 103 |
-
"""Force the root to proxy to Streamlit."""
|
| 104 |
-
return await proxy_streamlit(request, "")
|
| 105 |
-
|
| 106 |
-
|
| 107 |
def main(port: int | None = None) -> None:
|
| 108 |
"""Start the PatchHawk OpenEnv server."""
|
| 109 |
import uvicorn
|
| 110 |
|
| 111 |
if port is None:
|
| 112 |
-
# Parse --port from CLI args
|
| 113 |
args = sys.argv[1:]
|
| 114 |
if "--port" in args:
|
| 115 |
idx = args.index("--port")
|
|
@@ -121,6 +49,5 @@ def main(port: int | None = None) -> None:
|
|
| 121 |
host = os.getenv("HOST", "0.0.0.0")
|
| 122 |
uvicorn.run(app, host=host, port=port)
|
| 123 |
|
| 124 |
-
|
| 125 |
if __name__ == "__main__":
|
| 126 |
main()
|
|
|
|
| 1 |
"""
|
| 2 |
PatchHawk OpenEnv server entry point.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
"""
|
| 4 |
|
| 5 |
from __future__ import annotations
|
|
|
|
| 14 |
sys.path.insert(0, _PROJECT_ROOT)
|
| 15 |
|
| 16 |
from openenv.core import create_app
|
|
|
|
| 17 |
from patchhawk.agent.environment import PatchHawkEnv
|
| 18 |
from patchhawk.env_models import PatchHawkAction, PatchHawkObservation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
def _env_factory() -> PatchHawkEnv:
|
| 21 |
"""Factory callable for create_app — returns a fresh PatchHawkEnv instance."""
|
| 22 |
scenarios_path = os.getenv("PATCHHAWK_SCENARIOS", "patchhawk/data/scenarios.json")
|
| 23 |
return PatchHawkEnv(scenarios_path=scenarios_path, use_docker=False)
|
| 24 |
|
|
|
|
| 25 |
def create_openenv_app():
|
| 26 |
"""Create the OpenEnv FastAPI application."""
|
| 27 |
return create_app(
|
|
|
|
| 31 |
env_name="PatchHawk",
|
| 32 |
)
|
| 33 |
|
|
|
|
| 34 |
app = create_openenv_app()
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
def main(port: int | None = None) -> None:
|
| 37 |
"""Start the PatchHawk OpenEnv server."""
|
| 38 |
import uvicorn
|
| 39 |
|
| 40 |
if port is None:
|
|
|
|
| 41 |
args = sys.argv[1:]
|
| 42 |
if "--port" in args:
|
| 43 |
idx = args.index("--port")
|
|
|
|
| 49 |
host = os.getenv("HOST", "0.0.0.0")
|
| 50 |
uvicorn.run(app, host=host, port=port)
|
| 51 |
|
|
|
|
| 52 |
if __name__ == "__main__":
|
| 53 |
main()
|
start.sh
CHANGED
|
@@ -1,7 +1,11 @@
|
|
| 1 |
#!/bin/bash
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
# Start the Streamlit Dashboard (User UI) in the background with Proxy-friendly settings
|
| 7 |
echo "Starting Streamlit Dashboard on port 8501..."
|
|
@@ -13,7 +17,6 @@ streamlit run patchhawk/app/dashboard.py \
|
|
| 13 |
--server.headless true \
|
| 14 |
--browser.gatherUsageStats false &
|
| 15 |
|
| 16 |
-
# Start
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
uvicorn server.app:app --host 0.0.0.0 --port 7860
|
|
|
|
| 1 |
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
API_PORT="${API_PORT:-8000}"
|
| 4 |
+
PORT="${PORT:-7860}"
|
| 5 |
+
|
| 6 |
+
# Start FastAPI on API_PORT
|
| 7 |
+
echo "Starting OpenEnv API server on port ${API_PORT}..."
|
| 8 |
+
uvicorn server.app:app --host 0.0.0.0 --port "${API_PORT}" &
|
| 9 |
|
| 10 |
# Start the Streamlit Dashboard (User UI) in the background with Proxy-friendly settings
|
| 11 |
echo "Starting Streamlit Dashboard on port 8501..."
|
|
|
|
| 17 |
--server.headless true \
|
| 18 |
--browser.gatherUsageStats false &
|
| 19 |
|
| 20 |
+
# Start Nginx in foreground on PORT
|
| 21 |
+
echo "Starting Nginx reverse proxy on ${PORT}..."
|
| 22 |
+
envsubst '${PORT}' < /etc/nginx/nginx.conf > /tmp/nginx.conf && nginx -c /tmp/nginx.conf -g "daemon off;"
|
|
|