云开发容器通过符号链接和命名卷实现零碎文件持久化机制

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-18 14:31:47 +08:00
parent dce89ed79f
commit 66c96fd331
2 changed files with 36 additions and 0 deletions

View File

@@ -23,6 +23,8 @@ services:
- claude-code-router:/root/.claude-code-router
# SSH 配置
- ssh:/root/.ssh
# 零碎文件持久化
- persist:/root/.hair-keeper-persist
environment:
- NODE_ENV=development
- TZ=Asia/Shanghai
@@ -40,6 +42,12 @@ services:
memory: 4G
volumes:
code-server-config:
code-server-data:
claude:
claude-code-router:
ssh:
persist:
# node_modules 卷,避免主机和容器之间的文件系统差异
node_modules:
# pnpm store 卷,加速依赖安装

View File

@@ -1,5 +1,33 @@
#!/bin/bash
# ============================================
# 文件持久化:通过符号链接将零碎文件持久化到命名卷
# ============================================
PERSIST_DIR="/root/.hair-keeper-persist"
PERSIST_FILES=(
"/root/.claude.json"
"/root/.zsh_history"
"/root/.bash_history"
)
mkdir -p "$PERSIST_DIR"
for filepath in "${PERSIST_FILES[@]}"; do
filename=$(basename "$filepath")
persist_path="$PERSIST_DIR/$filename"
# 如果原路径是真实文件(非符号链接),迁移到持久化目录
if [ -f "$filepath" ] && [ ! -L "$filepath" ]; then
mv "$filepath" "$persist_path"
fi
# 确保持久化目录中存在该文件
[ -f "$persist_path" ] || touch "$persist_path"
# 创建符号链接
ln -sf "$persist_path" "$filepath"
done
# 设置默认密码
DEV_PASSWORD=${DEV_PASSWORD:-clouddev}