fsanyoto commited on
Commit
c8e9b8b
Β·
verified Β·
1 Parent(s): 092334a

Deploy AIOS web (React glide grid + FastAPI slice)

Browse files
Files changed (1) hide show
  1. Dockerfile +67 -62
Dockerfile CHANGED
@@ -1,62 +1,67 @@
1
- # AIOS web β€” the React shell + FastAPI over the royalimports_os data layer. THE CANONICAL IMAGE:
2
- # this is the one that actually runs, and the one a host migration re-points (C1e).
3
- #
4
- # β›” WHY A SECOND DOCKERFILE EXISTS (ops/Dockerfile.api), stated here so nobody "tidies" the wrong
5
- # one away. It is NOT a duplicated service β€” it is the SAME service built from a DIFFERENT BUILD
6
- # CONTEXT:
7
- # * HF Spaces: the context is the Space repo root, which `deploy_web.py` uploads FLATTENED β€”
8
- # `api/`, `web/`, `royalimports_os/`, `requirements.txt` all at top level. Hence the paths here.
9
- # * ops/compose.yml: the context is the local repo root, where the same files live at
10
- # `aios-web/api/`, `aios-web/web/`, `royalimports_os/`. Different prefixes, same content.
11
- # β‡’ THE REAL FIX, and it is a follow-up rather than something to do the day of a first deploy:
12
- # make `deploy_web.py` upload with the REPO layout so both contexts are identical, then this file
13
- # serves both and `ops/Dockerfile.api` is deleted. Until then `ops/verify_portability.py` gates
14
- # the two against each other on every property that matters (same app object, same launcher
15
- # contract, non-root, healthchecked, no baked secrets), so they cannot drift silently.
16
- #
17
- # Two stages: node builds the React bundle, python serves it + the JSON API. Login is the app's own
18
- # branded page over a signed session cookie (wave 1 removed the HTTP Basic gate).
19
-
20
- # ---- stage 1: build the React bundle ----
21
- FROM node:22-slim AS web
22
- WORKDIR /web
23
- # Resolve deps FRESH from the public registry (the local lockfile pinned a mirror-only lodash
24
- # 4.18.1 that isn't on npmjs.org; a fresh install gets the public 4.17.x that glide accepts).
25
- COPY web/package.json ./
26
- RUN npm install --no-audit --no-fund --no-package-lock
27
- COPY web/ ./
28
- RUN rm -f package-lock.json && npm run build # -> /web/dist
29
-
30
- # ---- stage 2: python API serving the bundle ----
31
- FROM python:3.12-slim
32
- WORKDIR /app
33
- COPY requirements.txt ./
34
- RUN pip install --no-cache-dir -r requirements.txt
35
- COPY api/ ./api/
36
- COPY royalimports_os/ ./royalimports_os/ # the reused data layer (modules/core/harness)
37
- COPY --from=web /web/dist ./web/dist
38
-
39
- # Run unprivileged β€” the C2 security baseline, and matched to ops/Dockerfile.api so the two images
40
- # do not differ on a property that would only surface after a migration. uid 1000 is what HF
41
- # Spaces expects.
42
- RUN useradd --create-home --uid 1000 user && chown -R user:user /app
43
- USER user
44
-
45
- ENV RI_DIR=/app/royalimports_os \
46
- PORT=7860 \
47
- PYTHONUNBUFFERED=1
48
- # β›” AIOS_INSECURE_SSL is deliberately NOT set. It disables TLS verification for every outbound
49
- # call in the process and exists for one developer laptop. ops/verify_portability.py fails if any
50
- # deploy config sets it.
51
- EXPOSE 7860
52
-
53
- # Liveness via stdlib rather than curl β€” it keeps the image free of an apt layer that exists only
54
- # for the healthcheck.
55
- HEALTHCHECK --interval=30s --timeout=5s --start-period=60s --retries=3 \
56
- CMD python -c "import os,urllib.request,sys; sys.exit(0 if urllib.request.urlopen(f'http://127.0.0.1:{os.environ.get(\"PORT\",\"7860\")}/api/health',timeout=4).status==200 else 1)"
57
-
58
- # ⚠ THE PORT COMES FROM THE ENVIRONMENT, ALWAYS. The application itself reads PORT nowhere β€” it is
59
- # a launcher argument β€” which is what makes moving hosts a config change instead of a code change.
60
- # Secrets (Odoo creds, APP_PASSWORD, AIOS_SESSION_SECRET, APP_BASE_URL) arrive as env at RUN time
61
- # and are never baked; the repo-root .dockerignore drops **/.env from the build context.
62
- CMD ["sh", "-c", "uvicorn api.main:app --host 0.0.0.0 --port ${PORT}"]
 
 
 
 
 
 
1
+ # AIOS web β€” the React shell + FastAPI over the royalimports_os data layer. THE CANONICAL IMAGE:
2
+ # this is the one that actually runs, and the one a host migration re-points (C1e).
3
+ #
4
+ # β›” WHY A SECOND DOCKERFILE EXISTS (ops/Dockerfile.api), stated here so nobody "tidies" the wrong
5
+ # one away. It is NOT a duplicated service β€” it is the SAME service built from a DIFFERENT BUILD
6
+ # CONTEXT:
7
+ # * HF Spaces: the context is the Space repo root, which `deploy_web.py` uploads FLATTENED β€”
8
+ # `api/`, `web/`, `royalimports_os/`, `requirements.txt` all at top level. Hence the paths here.
9
+ # * ops/compose.yml: the context is the local repo root, where the same files live at
10
+ # `aios-web/api/`, `aios-web/web/`, `royalimports_os/`. Different prefixes, same content.
11
+ # β‡’ THE REAL FIX, and it is a follow-up rather than something to do the day of a first deploy:
12
+ # make `deploy_web.py` upload with the REPO layout so both contexts are identical, then this file
13
+ # serves both and `ops/Dockerfile.api` is deleted. Until then `ops/verify_portability.py` gates
14
+ # the two against each other on every property that matters (same app object, same launcher
15
+ # contract, non-root, healthchecked, no baked secrets), so they cannot drift silently.
16
+ #
17
+ # Two stages: node builds the React bundle, python serves it + the JSON API. Login is the app's own
18
+ # branded page over a signed session cookie (wave 1 removed the HTTP Basic gate).
19
+
20
+ # ---- stage 1: build the React bundle ----
21
+ FROM node:22-slim AS web
22
+ WORKDIR /web
23
+ # Resolve deps FRESH from the public registry (the local lockfile pinned a mirror-only lodash
24
+ # 4.18.1 that isn't on npmjs.org; a fresh install gets the public 4.17.x that glide accepts).
25
+ COPY web/package.json ./
26
+ RUN npm install --no-audit --no-fund --no-package-lock
27
+ COPY web/ ./
28
+ RUN rm -f package-lock.json && npm run build # -> /web/dist
29
+
30
+ # ---- stage 2: python API serving the bundle ----
31
+ FROM python:3.12-slim
32
+ WORKDIR /app
33
+ COPY requirements.txt ./
34
+ RUN pip install --no-cache-dir -r requirements.txt
35
+ COPY api/ ./api/
36
+ # the reused data layer (modules/core/harness)
37
+ # β›” COMMENT ON ITS OWN LINE. Docker does NOT support a trailing comment on an instruction:
38
+ # it parsed `# the reused data layer ...` as extra SOURCE PATHS and the first build ever run
39
+ # died with `failed to calculate checksum ... "/the": not found`. Only RUN tolerates it, and
40
+ # only because the shell eats the `#`. Gated in ops/verify_portability.py.
41
+ COPY royalimports_os/ ./royalimports_os/
42
+ COPY --from=web /web/dist ./web/dist
43
+
44
+ # Run unprivileged β€” the C2 security baseline, and matched to ops/Dockerfile.api so the two images
45
+ # do not differ on a property that would only surface after a migration. uid 1000 is what HF
46
+ # Spaces expects.
47
+ RUN useradd --create-home --uid 1000 user && chown -R user:user /app
48
+ USER user
49
+
50
+ ENV RI_DIR=/app/royalimports_os \
51
+ PORT=7860 \
52
+ PYTHONUNBUFFERED=1
53
+ # β›” AIOS_INSECURE_SSL is deliberately NOT set. It disables TLS verification for every outbound
54
+ # call in the process and exists for one developer laptop. ops/verify_portability.py fails if any
55
+ # deploy config sets it.
56
+ EXPOSE 7860
57
+
58
+ # Liveness via stdlib rather than curl β€” it keeps the image free of an apt layer that exists only
59
+ # for the healthcheck.
60
+ HEALTHCHECK --interval=30s --timeout=5s --start-period=60s --retries=3 \
61
+ CMD python -c "import os,urllib.request,sys; sys.exit(0 if urllib.request.urlopen(f'http://127.0.0.1:{os.environ.get(\"PORT\",\"7860\")}/api/health',timeout=4).status==200 else 1)"
62
+
63
+ # ⚠ THE PORT COMES FROM THE ENVIRONMENT, ALWAYS. The application itself reads PORT nowhere β€” it is
64
+ # a launcher argument β€” which is what makes moving hosts a config change instead of a code change.
65
+ # Secrets (Odoo creds, APP_PASSWORD, AIOS_SESSION_SECRET, APP_BASE_URL) arrive as env at RUN time
66
+ # and are never baked; the repo-root .dockerignore drops **/.env from the build context.
67
+ CMD ["sh", "-c", "uvicorn api.main:app --host 0.0.0.0 --port ${PORT}"]