# 中心服务：HTTP/WebSocket + gRPC（纯 Go / modernc SQLite，CGO_ENABLED=0）
# 镜像内进程为明文 HTTP；HTTPS 请在宿主机 Nginx 等反代层配置，内网直连本端口即可。
FROM golang:1.22-alpine AS build
WORKDIR /src
RUN apk add --no-cache git
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /central .

FROM alpine:3.20
RUN apk add --no-cache ca-certificates tzdata
WORKDIR /app
# 与 config 默认一致； compose 中可覆盖
ENV HOST=0.0.0.0
ENV PORT=9393
ENV GRPC_PORT=9394
ENV DB_PATH=/app/data/servers.db
COPY --from=build /central /app/central
EXPOSE 9393 9394
ENTRYPOINT ["/app/central"]
