# 仅后端 API 镜像（前端自行部署）
# 国内服务器拉取慢时，可加 --build-arg REGISTRY=docker.m.daocloud.io/library
ARG REGISTRY=
FROM ${REGISTRY}node:20-slim

RUN npm config set registry https://registry.npmmirror.com

# Debian 12 使用 sources.list.d，改为国内源避免 build 时连接超时
RUN rm -f /etc/apt/sources.list.d/debian.sources && \
    echo 'deb http://mirrors.aliyun.com/debian bookworm main' > /etc/apt/sources.list && \
    echo 'deb http://mirrors.aliyun.com/debian bookworm-updates main' >> /etc/apt/sources.list && \
    echo 'deb http://mirrors.aliyun.com/debian-security bookworm-security main' >> /etc/apt/sources.list && \
    apt-get update && apt-get install -y --no-install-recommends python3 make g++ && \
    rm -rf /var/lib/apt/lists/*


WORKDIR /app

COPY package*.json ./
RUN npm ci --omit=dev

COPY server ./server

ENV NODE_ENV=production
ENV API_PORT=3001
ENV DB_PATH=/data/data.db
EXPOSE 3001

COPY docker-entrypoint.sh ./
RUN chmod +x docker-entrypoint.sh
ENTRYPOINT ["./docker-entrypoint.sh"]
