feat(docker): add Docker support with Dockerfile, docker-compose.yml, and .dockerignore; update README for Docker deployment instructions

This commit is contained in:
666ghj 2026-01-22 14:35:41 +08:00
parent 9556854fbf
commit 0efd9352a0
7 changed files with 156 additions and 9 deletions

23
.dockerignore Normal file
View file

@ -0,0 +1,23 @@
.git
.github
.gitignore
.cursor
.DS_Store
.env
node_modules
frontend/node_modules
backend/.venv
.venv
.python-version
__pycache__
*.pyc
.pytest_cache
.mypy_cache
.ruff_cache
frontend/dist
frontend/.vite
backend/uploads

49
.github/workflows/docker-image.yml vendored Normal file
View file

@ -0,0 +1,49 @@
name: Build and push Docker image
on:
push:
tags: ["*"]
workflow_dispatch:
permissions:
contents: read
packages: write
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository_owner }}/mirofish
tags: |
type=ref,event=tag
type=sha
type=raw,value=latest
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

29
Dockerfile Normal file
View file

@ -0,0 +1,29 @@
FROM python:3.11
# 安装 Node.js (满足 >=18及必要工具
RUN apt-get update \
&& apt-get install -y --no-install-recommends nodejs npm \
&& rm -rf /var/lib/apt/lists/*
# 从 uv 官方镜像复制 uv
COPY --from=ghcr.io/astral-sh/uv:0.9.26 /uv /uvx /bin/
WORKDIR /app
# 先复制依赖描述文件以利用缓存
COPY package.json package-lock.json ./
COPY frontend/package.json frontend/package-lock.json ./frontend/
COPY backend/pyproject.toml backend/uv.lock ./backend/
# 安装依赖Node + Python
RUN npm ci \
&& npm ci --prefix frontend \
&& cd backend && uv sync --frozen
# 复制项目源码
COPY . .
EXPOSE 3000 5001
# 同时启动前后端(开发模式)
CMD ["npm", "run", "dev"]

View file

@ -87,7 +87,9 @@ Click the image to watch MiroFish's deep prediction of the lost ending based on
## 🚀 Quick Start
### Prerequisites
### Option 1: Source Code Deployment (Recommended)
#### Prerequisites
| Tool | Version | Description | Check Installation |
|------|---------|-------------|-------------------|
@ -95,7 +97,7 @@ Click the image to watch MiroFish's deep prediction of the lost ending based on
| **Python** | ≥3.11, ≤3.12 | Backend runtime | `python --version` |
| **uv** | Latest | Python package manager | `uv --version` |
### 1. Configure Environment Variables
#### 1. Configure Environment Variables
```bash
# Copy the example configuration file
@ -119,7 +121,7 @@ LLM_MODEL_NAME=qwen-plus
ZEP_API_KEY=your_zep_api_key
```
### 2. Install Dependencies
#### 2. Install Dependencies
```bash
# One-click installation of all dependencies (root + frontend + backend)
@ -136,7 +138,7 @@ npm run setup
npm run setup:backend
```
### 3. Start Services
#### 3. Start Services
```bash
# Start both frontend and backend (run from project root)
@ -154,6 +156,20 @@ npm run backend # Start backend only
npm run frontend # Start frontend only
```
### Option 2: Docker Deployment
```bash
# 1. Configure environment variables (same as source deployment)
cp .env.example .env
# 2. Pull image and start
docker compose up -d
```
Reads `.env` from root directory by default, maps ports `3000 (frontend) / 5001 (backend)`
> Mirror address for faster pulling is provided as comments in `docker-compose.yml`, replace if needed.
## 📬 Join the Conversation
<div align="center">

View file

@ -87,7 +87,9 @@ MiroFish 致力于打造映射现实的群体智能镜像,通过捕捉个体
## 🚀 快速开始
### 前置要求
### 一、源码部署(推荐)
#### 前置要求
| 工具 | 版本要求 | 说明 | 安装检查 |
|------|---------|------|---------|
@ -95,7 +97,7 @@ MiroFish 致力于打造映射现实的群体智能镜像,通过捕捉个体
| **Python** | ≥3.11, ≤3.12 | 后端运行环境 | `python --version` |
| **uv** | 最新版 | Python 包管理器 | `uv --version` |
### 1. 配置环境变量
#### 1. 配置环境变量
```bash
# 复制示例配置文件
@ -119,7 +121,7 @@ LLM_MODEL_NAME=qwen-plus
ZEP_API_KEY=your_zep_api_key
```
### 2. 安装依赖
#### 2. 安装依赖
```bash
# 一键安装所有依赖(根目录 + 前端 + 后端)
@ -136,7 +138,7 @@ npm run setup
npm run setup:backend
```
### 3. 启动服务
#### 3. 启动服务
```bash
# 同时启动前后端(在项目根目录执行)
@ -154,6 +156,20 @@ npm run backend # 仅启动后端
npm run frontend # 仅启动前端
```
### 二、Docker 部署
```bash
# 1. 配置环境变量(同源码部署)
cp .env.example .env
# 2. 拉取镜像并启动
docker compose up -d
```
默认会读取根目录下的 `.env`,并映射端口 `3000前端/5001后端`
> 在 `docker-compose.yml` 中已通过注释提供加速镜像地址,可按需替换
## 📬 更多交流
<div align="center">

14
docker-compose.yml Normal file
View file

@ -0,0 +1,14 @@
services:
mirofish:
image: ghcr.io/666ghj/mirofish:latest
# 加速镜像(如拉取缓慢可替换上方地址)
# image: ghcr.nju.edu.cn/666ghj/mirofish:latest
container_name: mirofish
env_file:
- .env
ports:
- "3000:3000"
- "5001:5001"
restart: unless-stopped
volumes:
- ./backend/uploads:/app/backend/uploads

View file

@ -4,7 +4,7 @@
"version": "0.1.0",
"type": "module",
"scripts": {
"dev": "vite",
"dev": "vite --host",
"build": "vite build",
"preview": "vite preview"
},