- 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
36 lines
1018 B
Docker
36 lines
1018 B
Docker
# ─── 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
|
|
COPY go.mod go.sum ./
|
|
RUN go mod download
|
|
COPY . .
|
|
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o /sub-store .
|
|
|
|
# ─── 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
|
|
|
|
ENTRYPOINT ["/app/sub-store"]
|
|
CMD ["serve", "-c", "/app/config/config.yaml"]
|