feat: single Docker image with frontend served from backend
- Dockerfile: 3-stage build (frontend npm build → backend go build → alpine runtime) - Frontend dist files served from disk at /app/frontend/dist - server.go: catch-all GET handler serves static files with SPA fallback to index.html - config.go: new server.frontend_dir option (env: SUB_STORE_SERVER_FRONTEND_DIR) - API routes (/api/*), download routes, and /health take priority over static serving
This commit is contained in:
+12
-2
@@ -1,4 +1,12 @@
|
||||
# ─── Stage 1: Build backend ───
|
||||
# ─── Stage 1: Build frontend ───
|
||||
FROM node:22-alpine AS frontend-builder
|
||||
WORKDIR /frontend
|
||||
COPY frontend/package.json frontend/package-lock.json ./
|
||||
RUN npm ci --production=false
|
||||
COPY frontend/ .
|
||||
RUN npm run build
|
||||
|
||||
# ─── Stage 2: Build backend ───
|
||||
FROM golang:1.26-alpine AS backend-builder
|
||||
RUN apk add --no-cache git ca-certificates
|
||||
WORKDIR /app
|
||||
@@ -7,17 +15,19 @@ RUN go mod download
|
||||
COPY . .
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o /sub-store .
|
||||
|
||||
# ─── Stage 2: Runtime ───
|
||||
# ─── Stage 3: Runtime ───
|
||||
FROM alpine:3.21
|
||||
RUN apk add --no-cache ca-certificates tzdata
|
||||
WORKDIR /app
|
||||
COPY --from=backend-builder /sub-store /app/sub-store
|
||||
COPY --from=frontend-builder /frontend/dist /app/frontend/dist
|
||||
COPY config/config.example.yaml /app/config/config.example.yaml
|
||||
|
||||
RUN mkdir -p /app/data
|
||||
|
||||
ENV TZ=Asia/Shanghai
|
||||
ENV SUB_STORE_CONFIG=/app/config/config.yaml
|
||||
ENV SUB_STORE_FRONTEND_DIR=/app/frontend/dist
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
|
||||
Reference in New Issue
Block a user