build: make build and an image with the web app inside; README describes it

make build builds the app and then sondad with -tags webui. The Dockerfile builds the app in a Node stage and embeds it in the Go build, so the image serves it with no Node on the host. README: how to build, what the image holds, the policy of the page, and how to work on the interface with the dev server.
This commit is contained in:
tgiachi 2026-11-12 15:56:36 +01:00
commit 95c1fa3e27

View file

@ -1,7 +1,17 @@
# syntax=docker/dockerfile:1
# The web app: built once here, written (by its Vite config) to /src/internal/webui/dist, where the Go
# build below embeds it. Nothing of Node reaches the final image.
FROM node:24-alpine AS web
WORKDIR /src/web
COPY web/package.json web/package-lock.json ./
RUN npm ci
COPY web ./
RUN npm run build
# Build: Sonda has no CGO (SQLite, PostgreSQL and the tag reader are pure Go), so the binary
# is static and the final image needs nothing but it and the CA certificates.
# is static and the final image needs nothing but it and the CA certificates. The web app is inside it
# (-tags webui), so sondad serves it on / and the API on /api.
FROM golang:1.27-alpine AS build
WORKDIR /src
COPY go.mod go.sum ./
@ -9,7 +19,8 @@ RUN go mod download
COPY cmd ./cmd
COPY internal ./internal
COPY migrations ./migrations
RUN CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /out/sondad ./cmd/sondad
COPY --from=web /src/internal/webui/dist ./internal/webui/dist
RUN CGO_ENABLED=0 go build -tags webui -trimpath -ldflags="-s -w" -o /out/sondad ./cmd/sondad
FROM alpine:3.22
LABEL org.opencontainers.image.title="Sonda" \