Skip to content

Commit 39c687f

Browse files
author
Nils Bars
committed
Wire the spa-frontend service into compose, ctrl.sh, and settings
- Add a `spa-frontend` service to the compose template that bind-mounts the host sources and toggles between `vite dev` and `vite preview` via `HOT_RELOADING`. - Publish the container port through `SPA_HOST_PORT` (default 5173) and teach `prepare.py` to render it into `settings.env`. - Extend `--hot-reloading` help in `ctrl.sh` to mention the SPA Vite HMR. - Ignore `spa-frontend/node_modules/` and `spa-frontend/dist/`.
1 parent 2fbffe2 commit 39c687f

4 files changed

Lines changed: 42 additions & 2 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ tests/failure_logs/
2929
tests/.coverage
3030

3131
ssh-reverse-proxy/target/
32+
33+
spa-frontend/node_modules/
34+
spa-frontend/dist/
3235
docker-compose.ref_e2e_*.yml
3336
.docker-cache/
3437
todo.md

ctrl.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ Commands:
6363
--debug-toolbar Enable the debug toolbar (never use in production).
6464
--maintenance Only allow admin users to login.
6565
--disable-telegram Disable error reporting via telegram.
66-
--hot-reloading Enable hot reloading of the server (except .html, .js, .sh files).
66+
--hot-reloading Enable hot reloading of the web server (Python)
67+
and of the spa-frontend container (Vite HMR).
6768
6869
down
6970
Stop and delete all services and networks. Disconnects all users and orphans running instances.

docker-compose.template.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,36 @@ services:
113113
- db
114114
cgroup_parent: "{{ cgroup_parent }}-core.slice"
115115

116+
# Vue 3 + Vuetify SPA that serves the student-facing pages under /v2/
117+
# (registration, restore-key, scoreboard). In dev (HOT_RELOADING=true)
118+
# runs `vite dev` with HMR against the host bind-mounted source;
119+
# otherwise runs `vite build && vite preview`. Either way the
120+
# container's port 5173 is mapped to SPA_HOST_PORT on the host, and
121+
# Vite's proxy forwards /api, /student/download, and /static to the
122+
# web container over the web-host network.
123+
spa-frontend:
124+
init: true
125+
hostname: spa-frontend
126+
build:
127+
context: ./spa-frontend
128+
environment:
129+
- HOT_RELOADING=${HOT_RELOADING:-false}
130+
volumes:
131+
# Bind-mount the host source so Vite sees live edits. The
132+
# anonymous volume below shields node_modules from the overlay
133+
# so deps installed at build time remain available.
134+
- ./spa-frontend/:/spa-frontend
135+
- /spa-frontend/node_modules
136+
{% if not testing %}
137+
ports:
138+
- "${SPA_HOST_PORT:-5173}:5173"
139+
{% endif %}
140+
networks:
141+
- web-host
142+
depends_on:
143+
- web
144+
cgroup_parent: "{{ cgroup_parent }}-core.slice"
145+
116146
# Rust-based SSH reverse proxy
117147
ssh-reverse-proxy:
118148
init: true

prepare.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def build_default_settings() -> Dict[str, Any]:
5252
"ports": {
5353
"ssh_host_port": 2222,
5454
"http_host_port": 8000,
55+
"spa_host_port": 5173,
5556
},
5657
"paths": {
5758
"data": "./data",
@@ -151,6 +152,9 @@ def write_settings_yaml(settings: Dict[str, Any]) -> None:
151152

152153

153154
BACKFILL_DEFAULTS: Dict[str, Dict[str, Any]] = {
155+
"ports": {
156+
"spa_host_port": 5173,
157+
},
154158
"paths": {
155159
"data": "./data",
156160
"exercises": "./exercises",
@@ -207,9 +211,11 @@ def render_settings_env(settings: Dict[str, Any]) -> None:
207211
"# the docker group on the host (getent group docker).",
208212
f"DOCKER_GROUP_ID={settings['docker_group_id']}",
209213
"",
210-
"# Host ports published by the ssh-reverse-proxy and web services.",
214+
"# Host ports published by the ssh-reverse-proxy, web, and spa-frontend",
215+
"# services.",
211216
f"SSH_HOST_PORT={settings['ports']['ssh_host_port']}",
212217
f"HTTP_HOST_PORT={settings['ports']['http_host_port']}",
218+
f"SPA_HOST_PORT={settings['ports']['spa_host_port']}",
213219
"",
214220
"# Flask session / CSRF signing key. Rotating invalidates all",
215221
"# existing user sessions.",

0 commit comments

Comments
 (0)