# 多阶段构建：先编译 Go 后端，再使用最小运行时镜像
ARG GO_IMAGE=golang:1.25.8-alpine3.23

FROM ${GO_IMAGE} AS builder
WORKDIR /app

RUN apk add --no-cache git

COPY go.mod go.sum ./
RUN go env -w GOPROXY=https://goproxy.cn,direct && go mod download

COPY . ./
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o /app/stock-user-system ./cmd/api

FROM alpine:3.23
RUN apk add --no-cache ca-certificates tzdata
WORKDIR /app

COPY --from=builder /app/stock-user-system /app/stock-user-system

ENV DATABASE_URL=""
ENV JWT_SECRET=""
ENV JWT_EXPIRATION_HOURS="168"
ENV PORT="3019"
ENV GIN_MODE="release"

EXPOSE 3019
CMD ["/app/stock-user-system"]
