# syntax=docker/dockerfile:1

FROM node:20-alpine AS builder
WORKDIR /app

# 先复制依赖清单，利用 Docker layer cache
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile

# 再复制源码并构建
COPY . .
RUN yarn build

FROM nginx:1.27-alpine AS runner
WORKDIR /usr/share/nginx/html

# 使用官方 Nginx 模板能力，在容器启动时注入 API_UPSTREAM
COPY nginx.conf /etc/nginx/templates/default.conf.template

# 仅拷贝构建产物，减小镜像体积
COPY --from=builder /app/dist ./

EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
