Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
c972959cee
55
README.md
55
README.md
@ -47,6 +47,61 @@ pnpm build
|
||||
pnpm start
|
||||
```
|
||||
|
||||
### 使用 Docker
|
||||
|
||||
我们提供了两种 Docker 环境配置:开发环境和生产环境。所有 Docker 相关文件都位于 `docker` 目录下。
|
||||
|
||||
#### 开发环境
|
||||
|
||||
使用 Docker Compose 启动开发环境(支持热重载):
|
||||
|
||||
```bash
|
||||
# 启动开发环境
|
||||
docker compose -f docker/docker-compose.yml up
|
||||
|
||||
# 在后台运行
|
||||
docker compose -f docker/docker-compose.yml up -d
|
||||
|
||||
# 停止服务
|
||||
docker compose -f docker/docker-compose.yml down
|
||||
```
|
||||
|
||||
#### 生产环境
|
||||
|
||||
```bash
|
||||
# 构建生产镜像
|
||||
docker build -t neurapress:prod -f docker/Dockerfile.prod .
|
||||
|
||||
# 运行生产容器
|
||||
docker run -p 3000:3000 neurapress:prod
|
||||
```
|
||||
|
||||
#### 发布到 Docker Hub
|
||||
|
||||
```bash
|
||||
# 登录到 Docker Hub
|
||||
docker login
|
||||
|
||||
# 构建并标记镜像
|
||||
docker build -t [your-dockerhub-username]/neurapress:latest -f docker/Dockerfile.prod .
|
||||
|
||||
# 推送到 Docker Hub
|
||||
docker push [your-dockerhub-username]/neurapress:latest
|
||||
```
|
||||
|
||||
#### 从 Docker Hub 拉取和运行
|
||||
|
||||
```bash
|
||||
# 拉取镜像
|
||||
docker pull [your-dockerhub-username]/neurapress:latest
|
||||
|
||||
# 运行容器
|
||||
docker run -p 3000:3000 [your-dockerhub-username]/neurapress:latest
|
||||
```
|
||||
|
||||
注意:
|
||||
- 使用 Docker Hub 时,请将 `[your-dockerhub-username]` 替换为你的 Docker Hub 用户名
|
||||
|
||||
## 使用指南
|
||||
|
||||
1. **编辑内容**
|
||||
|
58
docker/.dockerignore
Normal file
58
docker/.dockerignore
Normal file
@ -0,0 +1,58 @@
|
||||
# Dependencies
|
||||
node_modules
|
||||
.pnpm-store
|
||||
.npm
|
||||
.yarn
|
||||
|
||||
# Next.js build output
|
||||
.next
|
||||
out
|
||||
build
|
||||
|
||||
# Testing
|
||||
coverage
|
||||
.nyc_output
|
||||
|
||||
# Debug
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
.pnpm-debug.log*
|
||||
|
||||
# Local env files
|
||||
.env*.local
|
||||
.env
|
||||
.env.development
|
||||
.env.test
|
||||
.env.production
|
||||
|
||||
# Version control
|
||||
.git
|
||||
.gitignore
|
||||
.gitattributes
|
||||
|
||||
# IDE
|
||||
.idea
|
||||
.vscode
|
||||
*.swp
|
||||
*.swo
|
||||
*.swn
|
||||
.DS_Store
|
||||
|
||||
# Docker
|
||||
docker/
|
||||
Dockerfile*
|
||||
docker-compose*
|
||||
.dockerignore
|
||||
|
||||
# Cursor
|
||||
.cursor
|
||||
|
||||
# Misc
|
||||
*.log
|
||||
.cache
|
||||
.eslintcache
|
||||
.stylelintcache
|
||||
*.bak
|
||||
*.tmp
|
||||
*~
|
22
docker/Dockerfile.dev
Normal file
22
docker/Dockerfile.dev
Normal file
@ -0,0 +1,22 @@
|
||||
FROM node:20-alpine
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Install pnpm
|
||||
RUN npm install -g pnpm
|
||||
|
||||
# Copy package files
|
||||
COPY package.json pnpm-lock.yaml ./
|
||||
|
||||
# Install dependencies with cache optimization
|
||||
RUN --mount=type=cache,target=/root/.local/share/pnpm/store \
|
||||
pnpm install --frozen-lockfile
|
||||
|
||||
# Copy source code
|
||||
COPY . .
|
||||
|
||||
# Expose port
|
||||
EXPOSE 3000
|
||||
|
||||
# Start development server
|
||||
CMD ["pnpm", "dev"]
|
60
docker/Dockerfile.prod
Normal file
60
docker/Dockerfile.prod
Normal file
@ -0,0 +1,60 @@
|
||||
# Build stage
|
||||
FROM node:20-alpine AS builder
|
||||
|
||||
# Add a non-root user
|
||||
RUN addgroup -g 1001 -S nodejs && \
|
||||
adduser -S nextjs -u 1001
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Install pnpm
|
||||
RUN npm install -g pnpm
|
||||
|
||||
# Copy package files
|
||||
COPY package.json pnpm-lock.yaml ./
|
||||
|
||||
# Install dependencies with cache optimization
|
||||
RUN --mount=type=cache,target=/root/.local/share/pnpm/store \
|
||||
pnpm install --frozen-lockfile
|
||||
|
||||
# Copy source code
|
||||
COPY . .
|
||||
|
||||
# Build application
|
||||
RUN pnpm build
|
||||
|
||||
# Production stage
|
||||
FROM node:20-alpine AS runner
|
||||
|
||||
# Add a non-root user
|
||||
RUN addgroup -g 1001 -S nodejs && \
|
||||
adduser -S nextjs -u 1001
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Install pnpm
|
||||
RUN npm install -g pnpm
|
||||
|
||||
# Set production environment
|
||||
ENV NODE_ENV=production
|
||||
ENV PORT=3000
|
||||
|
||||
# Copy necessary files from builder
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/package.json .
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/pnpm-lock.yaml .
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/next.config.js .
|
||||
|
||||
# Install production dependencies only
|
||||
RUN --mount=type=cache,target=/root/.local/share/pnpm/store \
|
||||
pnpm install --prod --frozen-lockfile
|
||||
|
||||
# Switch to non-root user
|
||||
USER nextjs
|
||||
|
||||
# Expose port
|
||||
EXPOSE 3000
|
||||
|
||||
# Start the application
|
||||
CMD ["pnpm", "start"]
|
16
docker/docker-compose.yml
Normal file
16
docker/docker-compose.yml
Normal file
@ -0,0 +1,16 @@
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
app:
|
||||
build:
|
||||
context: ..
|
||||
dockerfile: docker/Dockerfile.dev
|
||||
ports:
|
||||
- "3000:3000"
|
||||
volumes:
|
||||
- ..:/app
|
||||
- /app/node_modules
|
||||
- /app/.next
|
||||
environment:
|
||||
- NODE_ENV=development
|
||||
command: pnpm dev
|
Loading…
Reference in New Issue
Block a user