ianalin123 commited on
Commit
3e49cf9
·
1 Parent(s): 0e80e35

Serve renderer at root and build frontend in Docker

Browse files
Files changed (2) hide show
  1. Dockerfile +10 -1
  2. openenv_server/app.py +23 -0
Dockerfile CHANGED
@@ -1,8 +1,17 @@
 
 
 
 
 
 
 
 
 
1
  FROM ghcr.io/meta-pytorch/openenv-base:latest
2
 
3
  WORKDIR /app
4
-
5
  COPY . /app
 
6
 
7
  RUN pip install --no-cache-dir -r requirements.txt \
8
  && pip install --no-cache-dir "openenv-core[core]>=0.2.1"
 
1
+ FROM node:20-alpine AS web-builder
2
+
3
+ WORKDIR /web
4
+ COPY package*.json ./
5
+ RUN npm install --no-audit --no-fund
6
+ COPY public ./public
7
+ COPY src ./src
8
+ RUN npm run build
9
+
10
  FROM ghcr.io/meta-pytorch/openenv-base:latest
11
 
12
  WORKDIR /app
 
13
  COPY . /app
14
+ COPY --from=web-builder /web/build /app/build
15
 
16
  RUN pip install --no-cache-dir -r requirements.txt \
17
  && pip install --no-cache-dir "openenv-core[core]>=0.2.1"
openenv_server/app.py CHANGED
@@ -1,5 +1,9 @@
1
  from __future__ import annotations
2
 
 
 
 
 
3
  from openenv.core.env_server.http_server import create_app
4
 
5
  from openenv_runtime.environment import OpenEnvOrigamiEnvironment
@@ -12,3 +16,22 @@ app = create_app(
12
  observation_cls=OrigamiObservation,
13
  env_name="optigami",
14
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from __future__ import annotations
2
 
3
+ from pathlib import Path
4
+
5
+ from fastapi.responses import HTMLResponse
6
+ from fastapi.staticfiles import StaticFiles
7
  from openenv.core.env_server.http_server import create_app
8
 
9
  from openenv_runtime.environment import OpenEnvOrigamiEnvironment
 
16
  observation_cls=OrigamiObservation,
17
  env_name="optigami",
18
  )
19
+
20
+ _BUILD_DIR = Path(__file__).resolve().parent.parent / "build"
21
+
22
+ if _BUILD_DIR.exists():
23
+ # Serve compiled React dashboard at "/" while preserving existing OpenEnv API routes.
24
+ app.mount("/", StaticFiles(directory=str(_BUILD_DIR), html=True), name="renderer")
25
+ else:
26
+ @app.get("/", include_in_schema=False)
27
+ def missing_renderer_build() -> HTMLResponse:
28
+ return HTMLResponse(
29
+ """
30
+ <html><body style="font-family: sans-serif; margin: 24px;">
31
+ <h3>Renderer build not found</h3>
32
+ <p>No <code>build/</code> directory is present in the container.</p>
33
+ <p>OpenEnv API docs are available at <a href="/docs">/docs</a>.</p>
34
+ </body></html>
35
+ """,
36
+ status_code=200,
37
+ )