Embed web assets into the Go binary

Serve /static from embedded assets when no static path override is configured, add static route coverage, and update Docker/docs to reflect embedded-by-default behavior.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
GitHub Copilot
2026-02-14 22:14:39 +00:00
parent ff60bc94ed
commit 73f162075e
6 changed files with 31 additions and 4 deletions
-3
View File
@@ -17,9 +17,6 @@ RUN apk add --no-cache ca-certificates docker-cli
WORKDIR /app
COPY --from=builder /out/webterm /usr/local/bin/webterm
COPY go/webterm/static /app/static
ENV WEBTERM_STATIC_PATH=/app/static
EXPOSE 8080
+1 -1
View File
@@ -120,5 +120,5 @@ docker build -t webterm .
docker run -v /var/run/docker.sock:/var/run/docker.sock -p 8080:8080 webterm --docker-watch
```
The image sets `WEBTERM_STATIC_PATH=/app/static` and serves assets from `go/webterm/static`.
Web assets are embedded in the Go binary by default (you can still override with `WEBTERM_STATIC_PATH`).
The Dockerfile uses a minimal Alpine runtime stage and only installs `ca-certificates` plus `docker-cli`.
+1
View File
@@ -48,6 +48,7 @@ The server resolves static files from:
1. `WEBTERM_STATIC_PATH` (if set)
2. local repository-relative fallbacks rooted at `go/webterm/static`
3. embedded assets bundled into the Go binary
## Docker integration
+18
View File
@@ -0,0 +1,18 @@
package webterm
import (
"embed"
"io/fs"
"net/http"
)
//go:embed static static/* static/js/* static/icons/*
var embeddedStaticAssets embed.FS
func embeddedStaticFS() (http.FileSystem, bool) {
sub, err := fs.Sub(embeddedStaticAssets, "static")
if err != nil {
return nil, false
}
return http.FS(sub), true
}
+2
View File
@@ -1466,6 +1466,8 @@ func (s *LocalServer) Handler() http.Handler {
mux.HandleFunc("/", s.handleRoot)
if strings.TrimSpace(s.staticPath) != "" {
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir(s.staticPath))))
} else if staticFS, ok := embeddedStaticFS(); ok {
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(staticFS)))
}
return s.loggingMiddleware(s.gzipMiddleware(mux))
}
+9
View File
@@ -221,6 +221,15 @@ func TestRootTerminalPageAndSparklineValidation(t *testing.T) {
t.Fatalf("unexpected root page: %q", text)
}
respStatic, err := http.Get(httpServer.URL + "/static/manifest.json")
if err != nil {
t.Fatalf("static request error = %v", err)
}
_ = respStatic.Body.Close()
if respStatic.StatusCode != http.StatusOK {
t.Fatalf("expected 200 for static manifest, got %d", respStatic.StatusCode)
}
resp2, err := http.Get(httpServer.URL + "/cpu-sparkline.svg")
if err != nil {
t.Fatalf("sparkline request error = %v", err)