# ================
# 1. 构建阶段
# ================
FROM node:18-slim AS builder

WORKDIR /app

RUN apt-get update -y && apt-get install -y openssl

# 先复制依赖文件并安装
COPY package*.json ./
COPY tsconfig.json ./
COPY tailwind.config.ts postcss.config.js ./
RUN npm install

# 复制所有代码
COPY . .

# 构建 Next.js 应用
RUN npm run build

# ================
# 2. 运行阶段
# ================
FROM node:18-slim AS runner

WORKDIR /app
ENV NODE_ENV=production
ENV PORT=3000

# 只复制运行需要的文件
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package*.json ./
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/public ./public
COPY --from=builder /app/prisma ./prisma
COPY --from=builder /app/src ./src
COPY --from=builder /app/tsconfig.json ./tsconfig.json

EXPOSE 3000

CMD ["npm", "start"]
