# 官网 - Next.js 静态导出
FROM node:20-alpine AS website-builder
WORKDIR /app
COPY pnpm-workspace.yaml pnpm-lock.yaml package.json ./
COPY packages/ ./packages/
COPY apps/official-website/ ./apps/official-website/
RUN npm install -g pnpm@8 && pnpm install --frozen-lockfile
RUN cd apps/official-website && pnpm run build

FROM nginx:alpine AS website
COPY --from=website-builder /app/apps/official-website/out /usr/share/nginx/html
RUN echo 'server { \
    listen 80; \
    server_name _; \
    root /usr/share/nginx/html; \
    index index.html; \
    location / { \
        try_files $uri $uri.html $uri/ =404; \
    } \
    location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ { \
        expires 30d; \
        add_header Cache-Control "public, immutable"; \
    } \
    gzip on; \
    gzip_types text/plain text/css application/json application/javascript text/xml application/xml text/javascript; \
    gzip_min_length 1024; \
}' > /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
