# 生产镜像：使用本机预编译的 Linux amd64 二进制（避免在服务器 docker build 时再跑 go build）
# Windows: 先双击运行 build-linux-amd64.bat，生成 dist/mengyaping-backend 后再执行:
#   docker compose build
# 若需在容器内编译，请使用: docker build -f Dockerfile.source .

FROM alpine:3.21

RUN apk --no-cache add ca-certificates tzdata wget

RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
    echo "Asia/Shanghai" > /etc/timezone

RUN addgroup -g 1000 appuser && \
    adduser -D -u 1000 -G appuser appuser

WORKDIR /app

COPY dist/mengyaping-backend /app/mengyaping-backend

RUN chmod +x /app/mengyaping-backend && \
    mkdir -p /app/data && \
    chown -R appuser:appuser /app

USER appuser

EXPOSE 8080

HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
    CMD wget --no-verbose --tries=1 --spider http://localhost:8080/api/health || exit 1

CMD ["./mengyaping-backend"]
