Commit Graph
14 Commits
Author SHA1 Message Date
Rene Nochebuena d6665047d8 fix(mime): register application/manifest+json for .webmanifest (+ webp/avif); v1.7.1
Go's MIME table has no .webmanifest entry, so http.FileServer sniffed the PWA web
app manifest as text/plain. mime.AddExtensionType at package load makes TypeByExtension
authoritative. A correctness nit (the manifest spec parses by content and nosniff does
not reject manifests), but a PWA server should label its manifest correctly.
2026-08-18 18:43:55 -06:00
Rene Nochebuena b73b9ee022 feat: per-file Cache-Control, navigation-scoped SPA fallback, nosniff, non-root image; v1.7.0
- Cache-Control per file: no-cache for index.html + service workers, immutable 1y for
  content-hashed assets, 1h for the rest (Vite/CRA/Angular). Closes the stale-release
  trap at the HTTP layer that the v1.6.0 image fix closed at the container layer.
- SPA fallback scoped to navigation: a missing asset (path w/ extension) or a non-HTML
  Accept now returns 404 instead of index.html (no more HTML-as-JS 'Unexpected token <').
- X-Content-Type-Options: nosniff on every response.
- Image runs as a non-root 'spa' user.
- README: caching table, fallback contract, and the Angular dist/<project>/browser/ note.
2026-08-18 17:55:56 -06:00
Rene Nochebuena bbc588d933 fix(docker): drop inherited VOLUME /srv/www that caused silent stale deploys
VOLUME ["/srv/www"] created an anonymous volume that docker compose reuses across
container recreation, shadowing a freshly COPY'd SPA bundle with the previous build
— up -d --build exited 0 while serving the old bundle (and poisoned the PWA service
worker's ngsw.json). A child image cannot un-declare an inherited VOLUME, so it must
not be declared: removing it makes the COPY case deterministic and leaves the runtime
bind-mount case unaffected. Also refreshed the README FROM tag v1.0.0 -> v1.6.0.
2026-08-18 17:27:04 -06:00
Rene Nochebuena e4f3ba1882 release: v1.6.0 (coordinated lockstep bump) 2026-08-13 23:12:57 -06:00
Rene Nochebuena b708ca527b chore(spa-server): framework version alignment to v1.5.0 2026-08-12 17:56:36 -06:00
Rene Nochebuena 09b5133f91 chore(spa-server): dependency refresh; framework version alignment to v1.4.0 2026-08-12 15:30:07 -06:00
Rene Nochebuena 59ff806a3a chore(spa-server): framework version alignment to v1.3.0 2026-08-08 10:49:11 -06:00
Rene Nochebuena 6511d84f15 chore(spa-server): framework version alignment to v1.2.0 2026-08-08 02:25:39 -06:00
Rene Nochebuena d8ed4cd78c chore(spa-server): framework version alignment to v1.1.3 2026-08-08 01:27:12 -06:00
Rene Nochebuena 804243d45a chore(spa-server): framework version alignment to v1.1.2 2026-08-08 00:44:07 -06:00
Rene Nochebuena 5d2d7641ec chore(spa-server): framework version alignment to v1.1.1 2026-08-07 23:33:06 -06:00
Rene Nochebuena 4d88dd4f71 chore(spa-server): bump einherjar deps to v1.1.0 (framework version alignment) (#1)
Patch of the coordinated framework release: einherjar modules move to v1.1.0
in lockstep, so spa-server is bumped alongside the rest.

- go.mod: contracts, core -> v1.1.0 (via go get + go mod tidy)

No code or API changes. ModuleVersion() reports v1.1.0 automatically from
build info once tagged. Badge bumped to v1.1.0.

Reviewed-on: #1
Co-authored-by: Rene Nochebuena Guerrero <rene@nochebuena.dev>
Co-committed-by: Rene Nochebuena Guerrero <rene@nochebuena.dev>
2026-08-07 19:17:31 -06:00
Rene Nochebuena fa04364413 chore(spa-server): add Makefile and OCI image labels to Dockerfile
Makefile:
- dry-run target (default) shows registry, branch, SHA, version, all computed
  image tags, and build args — no side effects
- build/push/release targets wire docker build and docker push
- Branch-aware tag strategy:
    main        → <version> + latest
    develop     → <version>-dev-<short-sha>
    release/*   → <version>-qa-<short-sha>
- Version resolved from the highest semver tag at HEAD; falls back to the most
  recent reachable tag via git describe
- BASE_DIGEST resolved at build time from the local Docker daemon; dry-run
  prints a hint when the base image is not yet pulled
- Note: case/esac cannot be used inside $(shell) — Make's parser matches the
  pattern ")" as the function's closing paren before the shell sees it;
  if/elif/else/fi used instead

Dockerfile:
- OCI standard labels added to the final stage via build args (VERSION, GIT_SHA,
  BASE_DIGEST):
    org.opencontainers.image.source    — repo URL
    org.opencontainers.image.version   — semver tag
    org.opencontainers.image.revision  — git commit SHA
    org.opencontainers.image.base.name — alpine:3.21
    org.opencontainers.image.base.digest — digest of base image at build time
- Custom label:
    dev.nochebuena.healthz — /health
2026-06-02 19:07:31 +00:00
Rene Nochebuena e978d60851 feat(spa-server): initial implementation — SPA/PWA container server (v1.0.0)
Introduces code.nochebuena.dev/einherjar/spa-server — a container-first HTTP
server for single-page applications and progressive web apps. Produces a Docker
base image; downstream SPA Dockerfiles require only a single COPY instruction.

Interfaces and types (CT-6: one TypeSpec per file):
- Config — Port (EINHERJAR_SPA_PORT, default 8080) and StaticDir
  (EINHERJAR_SPA_STATIC_DIR, default /srv/www); parsed via os.Getenv
- Server — implements lifecycle.Component; registered with launcher.New

Implementation:
- NewServer(logger, cfg) *Server — returns a lifecycle-managed HTTP server
- OnInit: builds http.NewServeMux with GET /health and /* routes
- OnStart: binds TCP listener synchronously via net.Listen (port conflicts
  surface immediately), then serves in a background goroutine
- OnStop: graceful shutdown via http.Server.Shutdown with 10s timeout

spa.NewHandler(logger, staticDir) http.Handler:
- Uses http.Dir.Open for path sanitisation (prevents directory traversal)
- File exists and is not a directory → served by http.FileServer
- File missing or is a directory → serves index.html (SPA router owns all routes)
- Directory listing is disabled

health.NewHandler(logger) http.Handler:
- Always responds 200 {"status":"UP","components":{}}
- Wire format matches web/health.Response without importing the web module
- No external checks — process reachability is the only meaningful health signal

Config (EINHERJAR_SPA_* env vars):
  Port(8080), StaticDir(/srv/www)

Docker:
- Multi-stage: golang:1.26-alpine builder → alpine:3.21 runtime
- Image published as:
    code.nochebuena.dev/einherjar/spa-server:v1.0.0
    code.nochebuena.dev/einherjar/spa-server:latest
- VOLUME ["/srv/www"] declared; consumer overrides via COPY or volume mount

No external dependencies beyond contracts, core, and the Go standard library.
2026-06-02 18:49:05 +00:00