fix add missing files
This commit is contained in:
@ -1,20 +1,33 @@
|
||||
FROM golang:1.23-alpine AS builder
|
||||
# Context: project root
|
||||
# docker build -f server/Dockerfile -t containarr-server .
|
||||
|
||||
# ── Stage 1 : build SvelteKit ─────────────────────────────────────────────────
|
||||
FROM node:20-alpine AS web-builder
|
||||
WORKDIR /web
|
||||
COPY web/package*.json ./
|
||||
RUN npm ci
|
||||
COPY web/ ./
|
||||
RUN npm run build
|
||||
# Output: /web/build/
|
||||
|
||||
# ── Stage 2 : build Go server ─────────────────────────────────────────────────
|
||||
FROM golang:1.23-alpine AS go-builder
|
||||
RUN apk add --no-cache gcc musl-dev
|
||||
|
||||
WORKDIR /src
|
||||
COPY go.mod go.sum ./
|
||||
COPY . .
|
||||
RUN go mod tidy && CGO_ENABLED=1 GOOS=linux go build -ldflags="-s -w" -o /bin/containarr-server ./cmd/server
|
||||
COPY server/go.mod server/go.sum ./
|
||||
RUN go mod download
|
||||
COPY server/ ./
|
||||
RUN CGO_ENABLED=1 GOOS=linux go build -ldflags="-s -w" -o /bin/containarr-server ./cmd/server
|
||||
|
||||
# ── Runtime ───────────────────────────────────────────────────────────────────
|
||||
# ── Stage 3 : image finale ────────────────────────────────────────────────────
|
||||
FROM alpine:3.20
|
||||
|
||||
RUN apk add --no-cache ca-certificates tzdata
|
||||
|
||||
COPY --from=builder /bin/containarr-server /usr/local/bin/containarr-server
|
||||
WORKDIR /app
|
||||
COPY --from=go-builder /bin/containarr-server ./containarr-server
|
||||
COPY --from=web-builder /web/build ./web/build
|
||||
|
||||
VOLUME ["/data"]
|
||||
EXPOSE 8080 9090
|
||||
|
||||
ENTRYPOINT ["containarr-server"]
|
||||
ENTRYPOINT ["/app/containarr-server"]
|
||||
|
||||
@ -2,11 +2,33 @@ package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-chi/chi/v5/middleware"
|
||||
)
|
||||
|
||||
const webBuildDir = "./web/build"
|
||||
|
||||
// spaHandler serves static files from dir and falls back to index.html for
|
||||
// any path that does not match an existing file on disk. This supports
|
||||
// SvelteKit (adapter-static, fallback: "index.html") running as a SPA.
|
||||
func spaHandler(dir string) http.HandlerFunc {
|
||||
fs := http.FileServer(http.Dir(dir))
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
// Resolve the requested path inside the build directory.
|
||||
abs := filepath.Join(dir, filepath.Clean("/"+r.URL.Path))
|
||||
if info, err := os.Stat(abs); err == nil && !info.IsDir() {
|
||||
// File exists — serve it normally (assets, icons, _app/*, …).
|
||||
fs.ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
// No matching file found: serve the SPA entry point.
|
||||
http.ServeFile(w, r, filepath.Join(dir, "index.html"))
|
||||
}
|
||||
}
|
||||
|
||||
func NewRouter(h *Handler) http.Handler {
|
||||
r := chi.NewRouter()
|
||||
r.Use(middleware.Logger)
|
||||
@ -29,7 +51,7 @@ func NewRouter(h *Handler) http.Handler {
|
||||
})
|
||||
})
|
||||
|
||||
r.Handle("/*", http.FileServer(http.Dir("./web/dist")))
|
||||
r.Handle("/*", spaHandler(webBuildDir))
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user