FROM docker.m.daocloud.io/library/node:22-bookworm AS builder

ARG NPM_REGISTRY=https://registry.npmmirror.com

ENV TZ=Asia/Shanghai
ENV NPM_CONFIG_REGISTRY=${NPM_REGISTRY}

WORKDIR /app

COPY apps/frontend/package.json apps/frontend/package-lock.json ./
RUN --mount=type=cache,target=/root/.npm,sharing=locked \
    npm ci

COPY apps/frontend/ ./
RUN npm run build

FROM docker.m.daocloud.io/library/caddy:2-alpine

# 阿里云公共源（全国可达）；也可构建时覆盖：--build-arg ALPINE_MIRROR=mirrors.cloud.aliyuncs.com
ARG ALPINE_MIRROR=mirrors.aliyun.com

ENV TZ=Asia/Shanghai

RUN sed -i "s|https://dl-cdn.alpinelinux.org/alpine|https://${ALPINE_MIRROR}/alpine|g" /etc/apk/repositories \
  && apk add --no-cache tzdata \
  && ln -snf /usr/share/zoneinfo/${TZ} /etc/localtime \
  && echo ${TZ} > /etc/timezone

COPY deploy/caddy/Caddyfile /etc/caddy/Caddyfile
COPY --from=builder /app/dist /srv
