添加docker
This commit is contained in:
62
.dockerignore
Normal file
62
.dockerignore
Normal file
@@ -0,0 +1,62 @@
|
||||
# Dependencies
|
||||
node_modules
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
prisma/node_modules
|
||||
|
||||
# Build output
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
prisma/dist
|
||||
prisma/dist-ssr
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
|
||||
# Environment variables
|
||||
.env
|
||||
.env.local
|
||||
.env.development
|
||||
.env.test
|
||||
.env.production
|
||||
*.env
|
||||
|
||||
# Git
|
||||
.git
|
||||
.gitignore
|
||||
.gitattributes
|
||||
|
||||
# Testing
|
||||
coverage
|
||||
*.test.ts
|
||||
*.spec.ts
|
||||
__tests__
|
||||
|
||||
# Documentation
|
||||
README.md
|
||||
LICENSE
|
||||
*.md
|
||||
docs
|
||||
|
||||
# Cache
|
||||
.cache
|
||||
.eslintcache
|
||||
.stylelintcache
|
||||
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
|
||||
# OS files
|
||||
Thumbs.db
|
||||
3
.env.example
Normal file
3
.env.example
Normal file
@@ -0,0 +1,3 @@
|
||||
# Gemini API Key
|
||||
# 获取方式: https://aistudio.google.com/app/apikey
|
||||
GEMINI_API_KEY=your_api_key_here
|
||||
61
Dockerfile
Normal file
61
Dockerfile
Normal file
@@ -0,0 +1,61 @@
|
||||
# Multi-stage Dockerfile for Prisma React App
|
||||
|
||||
# ============ Stage 1: Build ============
|
||||
FROM node:20-alpine AS builder
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Copy package files
|
||||
COPY prisma/package.json prisma/package-lock.json* ./
|
||||
|
||||
# Install dependencies
|
||||
RUN npm ci
|
||||
|
||||
# Copy source code
|
||||
COPY prisma/ .
|
||||
|
||||
# Build the application
|
||||
RUN npm run build
|
||||
|
||||
# ============ Stage 2: Production ============
|
||||
FROM node:20-alpine AS production
|
||||
|
||||
# Install serve globally
|
||||
RUN npm install -g serve
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Copy built files from builder stage
|
||||
COPY --from=builder /app/dist ./dist
|
||||
|
||||
# Expose port 3000
|
||||
EXPOSE 3000
|
||||
|
||||
# Health check
|
||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
||||
CMD wget --no-verbose --tries=1 --spider http://localhost:3000/ || exit 1
|
||||
|
||||
# Start the application with serve
|
||||
CMD ["serve", "-s", "dist", "-l", "3000"]
|
||||
|
||||
# ============ Stage 3: Development (optional) ============
|
||||
FROM node:20-alpine AS development
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy package files
|
||||
COPY prisma/package.json prisma/package-lock.json* ./
|
||||
|
||||
# Install dependencies
|
||||
RUN npm ci
|
||||
|
||||
# Copy source code
|
||||
COPY prisma/ .
|
||||
|
||||
# Expose port 3000
|
||||
EXPOSE 3000
|
||||
|
||||
# Start development server
|
||||
CMD ["npm", "run", "dev"]
|
||||
96
README.md
96
README.md
@@ -101,6 +101,102 @@ npm run dev
|
||||
|
||||
---
|
||||
|
||||
## 🐳 Docker 部署
|
||||
|
||||
使用 Docker 可以快速部署 Prisma,无需手动配置 Node.js 环境。
|
||||
|
||||
### 方式一:使用 Docker Compose(推荐)
|
||||
|
||||
#### 1. 配置环境变量
|
||||
```bash
|
||||
# 复制示例环境变量文件
|
||||
cp .env.example .env
|
||||
|
||||
# 编辑 .env 文件,填入你的 API Key
|
||||
# GEMINI_API_KEY=your_api_key_here
|
||||
```
|
||||
|
||||
#### 2. 启动生产环境
|
||||
```bash
|
||||
# 构建并启动容器
|
||||
docker-compose up -d prisma
|
||||
|
||||
# 查看日志
|
||||
docker-compose logs -f prisma
|
||||
```
|
||||
|
||||
#### 3. 启动开发环境(支持热重载)
|
||||
```bash
|
||||
# 构建并启动开发容器
|
||||
docker-compose up -d prisma-dev
|
||||
|
||||
# 查看日志
|
||||
docker-compose logs -f prisma-dev
|
||||
```
|
||||
|
||||
#### 4. 停止服务
|
||||
```bash
|
||||
# 停止并删除容器
|
||||
docker-compose down
|
||||
|
||||
# 停止并删除容器及镜像
|
||||
docker-compose down --rmi all
|
||||
```
|
||||
|
||||
### 方式二:使用 Docker 命令
|
||||
|
||||
#### 生产环境
|
||||
```bash
|
||||
# 构建镜像
|
||||
docker build -t prisma-app --target production .
|
||||
|
||||
# 运行容器
|
||||
docker run -d -p 3000:3000 \
|
||||
-e GEMINI_API_KEY=your_api_key_here \
|
||||
--name prisma-app \
|
||||
prisma-app
|
||||
```
|
||||
|
||||
#### 开发环境
|
||||
```bash
|
||||
# 构建镜像
|
||||
docker build -t prisma-dev --target development .
|
||||
|
||||
# 运行容器(挂载源代码以支持热重载)
|
||||
docker run -d -p 3000:3000 \
|
||||
-e GEMINI_API_KEY=your_api_key_here \
|
||||
-v $(pwd)/prisma:/app \
|
||||
-v /app/node_modules \
|
||||
--name prisma-dev \
|
||||
prisma-dev
|
||||
```
|
||||
|
||||
### 常用命令
|
||||
```bash
|
||||
# 查看运行中的容器
|
||||
docker ps
|
||||
|
||||
# 查看容器日志
|
||||
docker logs -f prisma-app
|
||||
|
||||
# 进入容器
|
||||
docker exec -it prisma-app sh
|
||||
|
||||
# 停止容器
|
||||
docker stop prisma-app
|
||||
|
||||
# 删除容器
|
||||
docker rm prisma-app
|
||||
|
||||
# 删除镜像
|
||||
docker rmi prisma-app
|
||||
```
|
||||
|
||||
### 访问应用
|
||||
部署成功后,访问 `http://localhost:3000` 即可使用 Prisma。
|
||||
|
||||
---
|
||||
|
||||
## 🛠️ 技术栈
|
||||
|
||||
| 模块 | 技术选型 | 说明 |
|
||||
|
||||
43
docker-compose.yml
Normal file
43
docker-compose.yml
Normal file
@@ -0,0 +1,43 @@
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
# Production service
|
||||
prisma:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
target: production
|
||||
container_name: prisma-app
|
||||
ports:
|
||||
- "3000:3000"
|
||||
environment:
|
||||
- NODE_ENV=production
|
||||
- GEMINI_API_KEY=${GEMINI_API_KEY}
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:3000/"]
|
||||
interval: 30s
|
||||
timeout: 3s
|
||||
start_period: 5s
|
||||
retries: 3
|
||||
|
||||
# Development service
|
||||
prisma-dev:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
target: development
|
||||
container_name: prisma-dev
|
||||
ports:
|
||||
- "3000:3000"
|
||||
environment:
|
||||
- NODE_ENV=development
|
||||
- GEMINI_API_KEY=${GEMINI_API_KEY}
|
||||
volumes:
|
||||
# Mount source code for hot reloading
|
||||
- ./prisma:/app:delegated
|
||||
# Use anonymous volumes for node_modules to prevent overwriting
|
||||
- /app/node_modules
|
||||
restart: unless-stopped
|
||||
stdin_open: true
|
||||
tty: true
|
||||
Reference in New Issue
Block a user