Spaces:
Sleeping
Sleeping
| ## 使用官方的 Nginx 镜像 | |
| #FROM nginxinc/nginx-unprivileged:stable-alpine | |
| #RUN apk add --no-cache nodejs npm | |
| ## 创建必要的目录并设置权限 | |
| #RUN mkdir -p /var/cache/nginx/client_temp && \ | |
| # chown -R nginx:nginx /var/cache/nginx | |
| # | |
| ## 复制自定义的 Nginx 配置文件 | |
| #COPY nginx.conf /etc/nginx/nginx.conf | |
| ## 复制自定义的 index.html 页面 | |
| # | |
| ## 设置工作目录 | |
| ## 设置工作目录 | |
| #WORKDIR /app | |
| #RUN mkdir /app/frontend | |
| #COPY frontend/package*.json /app/frontend/ | |
| #RUN cd /app/frontend | |
| #RUN npm install -g pnpm | |
| #RUN pnpm install | |
| #COPY frontend/ /app/frontend/ | |
| #RUN npm run build | |
| # | |
| #RUN mkdir /app/backend | |
| #RUN cd /app/backend | |
| #COPY backend/package*.json /app/backend/ | |
| #RUN npm install -g pnpm | |
| #RUN pnpm install | |
| # | |
| #COPY backend/ /app/backend/ | |
| #RUN rm -f database.sqlite | |
| #RUN npm run build | |
| ## 设置默认命令 | |
| #COPY docker-entrypoint.sh /app/ | |
| #RUN chmod +x /app/docker-entrypoint.sh | |
| # | |
| ## 启动服务 | |
| #ENTRYPOINT ["/app/docker-entrypoint.sh"] | |
| FROM node:20-alpine AS builder | |
| # 设置工作目录 | |
| WORKDIR /app | |
| # 复制并安装前端依赖 | |
| COPY frontend/package*.json ./frontend/ | |
| RUN cd frontend && npm install | |
| # 构建前端应用 | |
| COPY frontend/ ./frontend/ | |
| RUN cd frontend && npm run build | |
| # 复制并安装后端依赖 | |
| COPY backend/package*.json ./backend/ | |
| RUN cd backend && npm install | |
| # 构建后端应用 | |
| COPY backend/ ./backend/ | |
| RUN cd backend && npm run build | |
| FROM nginxinc/nginx-unprivileged:stable-alpine | |
| # 设置工作目录 | |
| WORKDIR /app | |
| # 复制构建好的前端和后端应用 | |
| COPY --from=builder /app/frontend/dist /usr/share/nginx/html | |
| COPY --from=builder /app/backend /app | |
| # 设置工作目录 | |
| WORKDIR /app | |
| USER root | |
| RUN apk add --no-cache nodejs npm | |
| RUN mkdir -p /app/logs /app/config /app/data && \ | |
| chmod -R 777 /app/logs /app/config /app/data | |
| # 复制入口脚本并设置执行权限 | |
| COPY docker-entrypoint.sh /app/docker-entrypoint.sh | |
| RUN chmod +x /app/docker-entrypoint.sh | |
| COPY nginx.conf /etc/nginx/nginx.conf | |
| # 切换回非 root 用户 | |
| USER nginx | |
| # 复制自定义的 Nginx 配置文件 | |
| # 设置默认命令 | |
| ENTRYPOINT ["/app/docker-entrypoint.sh"] | |