Skip to content

Commit 885aa83

Browse files
author
Hakan Kaya
committed
release: ship Web UI in Debian package for v0.1.1
1 parent 0e09d19 commit 885aa83

13 files changed

Lines changed: 283 additions & 24 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
run: |
3434
sudo apt-get update
3535
sudo apt-get install -y --no-install-recommends \
36-
build-essential cmake pkg-config libfuse3-dev dpkg-dev
36+
build-essential cmake pkg-config libfuse3-dev dpkg-dev curl
3737
3838
- name: Validate release version
3939
id: version
@@ -73,6 +73,7 @@ jobs:
7373
run: |
7474
set -euo pipefail
7575
sudo apt-get install -y "./dist/vds4e_${{ steps.version.outputs.version }}_amd64.deb"
76+
command -v vds4e
7677
command -v vds-server
7778
command -v vds-cli
7879
test -x /usr/bin/vds4e-spi-cuse
@@ -81,9 +82,34 @@ jobs:
8182
test -x /usr/bin/vds4e-uart-pty
8283
test -f /etc/vds4e/vds-server.yaml
8384
test -f /usr/share/vds4e/web/index.html
85+
test -f /lib/systemd/system/vds4e.service
86+
vds4e --help >/dev/null
8487
vds-server --help >/dev/null
8588
vds-cli --help >/dev/null
8689
90+
VDS4E_WEB_ROOT=/usr/share/vds4e/web \
91+
vds-server --config /etc/vds4e/vds-server.yaml \
92+
>"$RUNNER_TEMP/vds-server.log" 2>&1 &
93+
server_pid=$!
94+
trap 'kill "$server_pid" 2>/dev/null || true' EXIT
95+
ready=false
96+
for _ in $(seq 1 100); do
97+
if curl -fsS http://127.0.0.1:8080/api/v1/health >/dev/null; then
98+
ready=true
99+
break
100+
fi
101+
sleep 0.1
102+
done
103+
if [[ "$ready" != true ]]; then
104+
cat "$RUNNER_TEMP/vds-server.log"
105+
exit 1
106+
fi
107+
curl -fsS http://127.0.0.1:8080/ | grep -q '<div id="root">'
108+
curl -fsS http://127.0.0.1:8080/devices | grep -q '<div id="root">'
109+
kill "$server_pid"
110+
wait "$server_pid" || true
111+
trap - EXIT
112+
87113
- name: Publish GitHub Release
88114
env:
89115
GH_TOKEN: ${{ github.token }}

‎CHANGELOG.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.1.1] - 2026-10-07
11+
12+
### Added
13+
- The packaged server serves the bundled React Web UI from the same control-plane
14+
address, including SPA route fallback.
15+
- The Debian package installs a `vds4e` launcher and a `vds4e.service` systemd
16+
unit. The service is installed but is not enabled automatically.
17+
18+
### Fixed
19+
- Debian installs no longer leave Web UI assets unused under
20+
`/usr/share/vds4e/web`; opening `http://127.0.0.1:8080/` now loads the UI.
21+
- Release smoke testing starts the installed server and verifies both the REST
22+
health endpoint and Web UI routes.
23+
24+
1025
### Added
1126
- Debian `amd64` package builder and tag-driven GitHub Release workflow that
1227
publishes the `.deb` and SHA-256 checksum.

‎Cargo.lock‎

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ members = [
1313
resolver = "3"
1414

1515
[workspace.package]
16-
version = "0.1.0"
16+
version = "0.1.1"
1717
edition = "2024"
1818
rust-version = "1.91.1"
1919
license = "Apache-2.0"

‎README.md‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,24 +74,35 @@ Tagged releases publish an `amd64` Debian package and SHA-256 checksum.
7474
Download the package from [GitHub Releases](https://github.com/haknkayaa/VirtualDeviceSimulatorForEmbedded/releases), then install it:
7575

7676
```shell
77-
sudo apt install ./vds4e_0.1.0_amd64.deb
77+
sudo apt install ./vds4e_0.1.1_amd64.deb
7878
```
7979

8080
Validate the installed configuration:
8181

8282
```shell
83-
vds-server --config /etc/vds4e/vds-server.yaml --check-config
83+
vds4e --check-config
8484
```
8585

86-
Start the runtime:
86+
Start VDS4E:
8787

8888
```shell
89-
vds-server --config /etc/vds4e/vds-server.yaml
89+
vds4e
9090
```
9191

92+
Then open `http://127.0.0.1:8080/`. The same process serves the Web UI,
93+
REST API, WebSocket event stream, and Unix-socket transaction data plane.
94+
95+
To run it as a system service instead:
96+
97+
```shell
98+
sudo systemctl enable --now vds4e
99+
```
100+
101+
The package installs the unit but does not enable or start it automatically.
102+
92103
The package installs:
93104

94-
- `vds-server` and `vds-cli`
105+
- `vds4e`, `vds-server` and `vds-cli`
95106
- SPI, I²C, GPIO and UART host adapters
96107
- the built Web UI assets
97108
- schemas and bundled example device models

‎apps/vds-server/src/http/mod.rs‎

Lines changed: 122 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,19 @@ use events::events;
2929
use std::{
3030
collections::HashMap,
3131
fs,
32-
path::{Component, PathBuf},
32+
path::{Component, Path as FsPath, PathBuf},
3333
sync::{Arc, RwLock},
3434
time::{SystemTime, UNIX_EPOCH},
3535
};
3636

3737
use axum::{
3838
Json, Router,
39+
body::Body,
3940
extract::{
4041
DefaultBodyLimit, Path, Query, State,
4142
ws::{Message, WebSocket, WebSocketUpgrade},
4243
},
43-
http::{StatusCode, header},
44+
http::{StatusCode, Uri, header},
4445
response::{IntoResponse, Response},
4546
routing::{delete, get, post},
4647
};
@@ -77,6 +78,7 @@ pub struct ApiState {
7778
device_template_instances: Arc<RwLock<HashMap<String, String>>>,
7879
clock: Arc<dyn SimulatorClock>,
7980
host_telemetry: Arc<std::sync::Mutex<host_telemetry::HostTelemetrySampler>>,
81+
web_root: Option<PathBuf>,
8082
}
8183

8284
impl ApiState {
@@ -176,6 +178,7 @@ impl ApiState {
176178
host_telemetry: Arc::new(std::sync::Mutex::new(
177179
host_telemetry::HostTelemetrySampler::new(),
178180
)),
181+
web_root: discover_web_root(),
179182
})
180183
}
181184
}
@@ -228,9 +231,103 @@ pub fn router(state: ApiState) -> Router {
228231
.route("/api/v1/faults/{id}/disable", post(disable_fault))
229232
.route("/api/v1/telemetry/buses", get(telemetry::bus_telemetry))
230233
.route("/api/v1/events", get(events))
234+
.fallback(serve_web)
231235
.with_state(state)
232236
}
233237

238+
fn discover_web_root() -> Option<PathBuf> {
239+
if let Some(path) = std::env::var_os("VDS4E_WEB_ROOT").map(PathBuf::from) {
240+
return path.join("index.html").is_file().then_some(path);
241+
}
242+
[
243+
PathBuf::from("build/web"),
244+
PathBuf::from("/usr/local/share/vds4e/web"),
245+
PathBuf::from("/usr/share/vds4e/web"),
246+
]
247+
.into_iter()
248+
.find(|path| path.join("index.html").is_file())
249+
}
250+
251+
async fn serve_web(State(state): State<ApiState>, uri: Uri) -> Response {
252+
if uri.path() == "/api" || uri.path().starts_with("/api/") {
253+
return StatusCode::NOT_FOUND.into_response();
254+
}
255+
let Some(root) = state.web_root.as_ref() else {
256+
return StatusCode::NOT_FOUND.into_response();
257+
};
258+
let Some(relative) = safe_web_path(uri.path()) else {
259+
return StatusCode::NOT_FOUND.into_response();
260+
};
261+
262+
let requested = root.join(&relative);
263+
let selected = if relative.as_os_str().is_empty() {
264+
root.join("index.html")
265+
} else if tokio::fs::metadata(&requested)
266+
.await
267+
.is_ok_and(|metadata| metadata.is_file())
268+
{
269+
requested
270+
} else if relative.extension().is_none() {
271+
root.join("index.html")
272+
} else {
273+
return StatusCode::NOT_FOUND.into_response();
274+
};
275+
276+
match tokio::fs::read(&selected).await {
277+
Ok(bytes) => {
278+
let cache_control = if uri.path().starts_with("/assets/") {
279+
"public, max-age=31536000, immutable"
280+
} else {
281+
"no-cache"
282+
};
283+
Response::builder()
284+
.status(StatusCode::OK)
285+
.header(header::CONTENT_TYPE, web_content_type(&selected))
286+
.header(header::CACHE_CONTROL, cache_control)
287+
.body(Body::from(bytes))
288+
.unwrap_or_else(|_| StatusCode::INTERNAL_SERVER_ERROR.into_response())
289+
}
290+
Err(error) if error.kind() == std::io::ErrorKind::NotFound => {
291+
StatusCode::NOT_FOUND.into_response()
292+
}
293+
Err(_) => StatusCode::INTERNAL_SERVER_ERROR.into_response(),
294+
}
295+
}
296+
297+
fn safe_web_path(path: &str) -> Option<PathBuf> {
298+
let trimmed = path.trim_start_matches('/');
299+
if trimmed.is_empty() {
300+
return Some(PathBuf::new());
301+
}
302+
let path = PathBuf::from(trimmed);
303+
path.components()
304+
.all(|component| matches!(component, Component::Normal(_)))
305+
.then_some(path)
306+
}
307+
308+
fn web_content_type(path: &FsPath) -> &'static str {
309+
match path
310+
.extension()
311+
.and_then(|extension| extension.to_str())
312+
.map(str::to_ascii_lowercase)
313+
.as_deref()
314+
{
315+
Some("html") => "text/html; charset=utf-8",
316+
Some("css") => "text/css; charset=utf-8",
317+
Some("js" | "mjs") => "text/javascript; charset=utf-8",
318+
Some("json" | "map") => "application/json; charset=utf-8",
319+
Some("svg") => "image/svg+xml",
320+
Some("png") => "image/png",
321+
Some("jpg" | "jpeg") => "image/jpeg",
322+
Some("webp") => "image/webp",
323+
Some("gif") => "image/gif",
324+
Some("ico") => "image/x-icon",
325+
Some("woff") => "font/woff",
326+
Some("woff2") => "font/woff2",
327+
_ => "application/octet-stream",
328+
}
329+
}
330+
234331
#[derive(Serialize)]
235332
struct Health {
236333
status: &'static str,
@@ -365,3 +462,26 @@ impl IntoResponse for ApiError {
365462
.into_response()
366463
}
367464
}
465+
466+
467+
#[cfg(test)]
468+
mod web_asset_tests {
469+
use super::{safe_web_path, web_content_type};
470+
use std::path::Path;
471+
472+
#[test]
473+
fn web_paths_reject_parent_traversal() {
474+
assert!(safe_web_path("/assets/app.js").is_some());
475+
assert!(safe_web_path("/devices/example").is_some());
476+
assert!(safe_web_path("/../etc/passwd").is_none());
477+
assert!(safe_web_path("/assets/../secret").is_none());
478+
}
479+
480+
#[test]
481+
fn web_content_types_cover_vite_assets() {
482+
assert_eq!(web_content_type(Path::new("index.html")), "text/html; charset=utf-8");
483+
assert_eq!(web_content_type(Path::new("assets/app.js")), "text/javascript; charset=utf-8");
484+
assert_eq!(web_content_type(Path::new("assets/app.css")), "text/css; charset=utf-8");
485+
assert_eq!(web_content_type(Path::new("assets/logo.svg")), "image/svg+xml");
486+
}
487+
}

‎apps/vds-web/package-lock.json‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎apps/vds-web/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@vds4e/web",
33
"private": true,
4-
"version": "0.1.0",
4+
"version": "0.1.1",
55
"type": "module",
66
"scripts": {
77
"dev": "vite",

0 commit comments

Comments
 (0)