From 420768318c1c050a46f9802dc503409d8d002c90 Mon Sep 17 00:00:00 2001 From: Admin <1+admin@noreply.git.dcntrlized.org> Date: Sun, 16 Aug 2026 03:27:17 +0100 Subject: [PATCH] =?UTF-8?q?fix(dev):=20serve=20web=20UI=20in=20debug=20mod?= =?UTF-8?q?e=20=E2=80=94=20real=20frontend=20embed=20+=20data=20mounts=20i?= =?UTF-8?q?n=20debug=20compose?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile.debug | 45 ++++++++++++++++++++++++++++++++------- docker-compose.debug.yaml | 3 +++ src/main.go | 10 ++++----- 3 files changed, 44 insertions(+), 14 deletions(-) diff --git a/Dockerfile.debug b/Dockerfile.debug index 0670108..23b5a44 100644 --- a/Dockerfile.debug +++ b/Dockerfile.debug @@ -1,15 +1,44 @@ -FROM golang:1.26-alpine -WORKDIR /app +# Copyright (C) 2026 Dcntrlized +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# Debug build: same embedded UI as the prod Dockerfile, but the final stage +# keeps the golang:alpine base (shell + tooling) for live debugging. Rebuild +# this image when the frontend changes; Air handles Go hot-reload at runtime. + +# Stage 1: Build the UI bundle +FROM oven/bun:1.3.9-alpine AS frontend-builder +WORKDIR /app +# Copy the lockfile so `bun ci` can accurately install +COPY src/frontend/package.json src/frontend/bun.lock ./ +RUN bun ci +COPY src/frontend/ ./ +RUN bun run build + +# Stage 2: Build the static Go binary +FROM golang:1.26-alpine AS go-builder +WORKDIR /app COPY src/go.mod src/go.sum ./ RUN go mod download COPY src/ . - -# Satisfy go:embed during debug builds -RUN mkdir -p frontend/dist && touch frontend/dist/.placeholder - -# Output the binary directly to /server to match the ENTRYPOINT +# Copy the built UI into the frontend folder so go:embed finds it +COPY --from=frontend-builder /app/dist ./frontend/dist RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o /server . +# Stage 3: Debug-final image (alpine base, not scratch, for shell access) +FROM golang:1.26-alpine +RUN apk add --no-cache ca-certificates +COPY --from=go-builder /server /server EXPOSE 8080 -ENTRYPOINT ["/server"] \ No newline at end of file +ENTRYPOINT ["/server"] diff --git a/docker-compose.debug.yaml b/docker-compose.debug.yaml index d5e23e0..fd8d73a 100644 --- a/docker-compose.debug.yaml +++ b/docker-compose.debug.yaml @@ -6,6 +6,8 @@ services: - "8080:8080" volumes: - "/var/run/docker.sock:/var/run/docker.sock" + - "${XDG_DATA_HOME:-${HOME}}/.dcntrlized:/data/.dcntrlized" + - "${HOME}:/host-home:ro" networks: - dcntrlized_net build: @@ -15,6 +17,7 @@ services: - DEV_MODE=true - DCNTRLIZED_DEV=true - INSECURE_INTERNAL=1 + - XDG_DATA_HOME=/data - GITEA_URL=${GITEA_URL:-http://192.168.122.183:3000} - GITEA_REGISTRY_RO_TOKEN=${GITEA_REGISTRY_RO_TOKEN} - GITEA_RW_PACKAGE_TOKEN=${GITEA_RW_PACKAGE_TOKEN} diff --git a/src/main.go b/src/main.go index 6921866..bb8f27c 100644 --- a/src/main.go +++ b/src/main.go @@ -102,13 +102,11 @@ func main() { mux.HandleFunc("/api/peers/approve", peersHandler.Approve) mux.HandleFunc("/api/peers/revoke", peersHandler.Revoke) - if os.Getenv("DEV_MODE") != "true" { - frontendDir, err := fs.Sub(embeddedFrontend, "frontend/dist") - if err != nil { - log.Fatalf("Failed to parse embedded frontend subtree: %v", err) - } - mux.Handle("/", http.FileServer(http.FS(frontendDir))) + frontendDir, err := fs.Sub(embeddedFrontend, "frontend/dist") + if err != nil { + log.Fatalf("Failed to parse embedded frontend subtree: %v", err) } + mux.Handle("/", http.FileServer(http.FS(frontendDir))) port := os.Getenv("PORT") if port == "" {