Compare commits

...

4 Commits

Author SHA1 Message Date
8b5f440e53 Add mise language manager to dev images
- Install mise and activate it in root's zshrc in Fedora and Ubuntu
- Add mise-data volume and mount at /root/.local/share/mise
- Add mise --version check to the Makefile self-check target
- Document mise-data volume in README
- Add DB packages: postgresql/redis/mariadb to Fedora and
  postgresql-client/redis-tools/default-mysql-client to Ubuntu
2026-06-23 00:29:20 +08:00
518eb5a90e Add Oh My Pi and improve dev container config
- Install @oh-my-pi/pi-coding-agent and move Go binaries to /usr/local/bin
- Add omp-data volume and make web port configurable via PORT_WEB
- Replace aider self-check with omp in Makefile
- Harden entrypoint: avoid exporting API keys to SSH env and overwrite
  mounted public key into authorized_keys
- Add .dockerignore, simplify .env.example, and document omp in README
2026-06-22 21:51:56 +08:00
a2eba73cef Install opencode and omp with Bun
- Combine Bun installs for opencode-ai and @oh-my-pi/pi-coding-agent
- Make Makefile include .env optional and silence sed errors
2026-06-22 20:33:01 +08:00
f77b2b1e99 Install oh-my-pi coding agent
- Install @oh-my-pi/pi-coding-agent globally via bun in Containerfile
- Persist agent config (~/.omp/) via compose volume (mounted at /root)
- Agent provides native Zed (ACP protocol) support
2026-06-22 20:19:55 +08:00
10 changed files with 134 additions and 88 deletions

View File

@@ -25,11 +25,11 @@ ENV PATH="$BUN_INSTALL/bin:$PATH"
# 安装 Bun
RUN curl -fsSL https://bun.sh/install | bash
# 使用 Bun 安装 opencode
RUN bun install -g opencode-ai
# 使用 Bun 安装 opencode 与 oh-my-pi (omp)
# - opencode: Vibe Coding 工具
# - omp: 终端 AI 编码 agent原生支持 Zed (ACP 协议)
# 配置目录 ~/.omp/ 由 compose.yml 中 /root 挂载卷持久化
RUN bun install -g opencode-ai @oh-my-pi/pi-coding-agent
# 3. 配置 SSH 服务
RUN mkdir /var/run/sshd && \
@@ -38,18 +38,9 @@ RUN mkdir /var/run/sshd && \
# 修复 SSH 登录后的环境变量问题
sed -i 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' /etc/pam.d/sshd
# 5. 安装 Opencode (Vibe Coding 工具)
# 假设 Opencode 是一个可以通过 curl 下载的二进制文件。
# 请将下方的 URL 替换为 Opencode 的真实下载链接。
# 如果 Opencode 是 npm 包,则需要先安装 nodejs。
# 这里演示二进制安装模式:
# RUN curl -L "https://path/to/opencode-linux-x64" -o /usr/local/bin/opencode && \
# chmod +x /usr/local/bin/opencode
# 6. 设置工作目录
# 4. 设置工作目录
WORKDIR /workspace
# 7. 配置容器启动命令
# 5. 配置容器启动命令
# 启动 SSH 服务并挂起容器
CMD ["/bin/sh", "-c", "/usr/sbin/sshd -D"]

View File

@@ -1,6 +1,6 @@
# 引用 .env 文件中的变量
include .env
export $(shell sed 's/=.*//' .env)
# 引用 .env 文件中的变量(文件不存在时也不报错)
-include .env
export $(shell sed 's/=.*//' .env 2>/dev/null)
.PHONY: help build up down restart logs shell clean ssh

30
vibe-dev/.dockerignore Normal file
View File

@@ -0,0 +1,30 @@
# 版本控制
.git
.gitignore
# 敏感文件 (防止意外打入镜像)
.env
.env.*
!.env.example
*.pem
id_rsa*
authorized_keys
# 构建产物
/target/
node_modules/
/dist/
/build/
# 编辑器与系统
.vscode/
.idea/
*.swp
*.swo
.DS_Store
Thumbnails.db
# 日志与临时
*.log
tmp/
temp/

View File

@@ -1,51 +1,33 @@
# =================================================================
# Vibe Coding 开发环境 - 环境变量模板
# 使用说明:
# 1. 复制此文件并重命名为 .env
# 2. 在 .env 中填写你真实的 API Key 和配置
# 3. 注意:不要将 .env 文件上传到 Git 仓库!
# =================================================================
# ========================================
# Vibe Coding 环境配置模板
# ========================================
# 使用方法: cp .env.example .env然后填入实际值
# --- [SSH 配置] ---
# 宿主机连接容器时使用的端口
SSH_PORT=2222
# --- [AI 工具 API Keys] ---
# Aider / OpenCode-AI 需要使用的模型密钥
# 常用模型提供商Anthropic (Claude), OpenAI (GPT), 智谱AI (GLM)
# Anthropic API (用于 Claude 3.5 Sonnet, Aider 强烈推荐)
ANTHROPIC_API_KEY=your_anthropic_key_here
# OpenAI API (用于 GPT-4o 等)
OPENAI_API_KEY=your_openai_key_here
# OpenCode-AI 专用 (例如智谱 AI Key)
OPENCODE_API_KEY=your_opencode_provider_key_here
# --- [开发环境设置 (可选)] ---
# 你可以在这里指定镜像构建时使用的版本(如果 Dockerfile 支持 args
RUST_VERSION=stable
BUN_VERSION=latest
# --- [其他工具配置] ---
# 例如某些工具需要的环境变量
# GITHUB_TOKEN=your_github_pat_here
# 开发者信息
# GIT_USER_NAME=YourName
# GIT_USER_EMAIL=youremail@example.com
# --- [路径配置] ---
# 宿主机项目代码目录 (默认为当前目录 .)
# --- 工作区路径 ---
# 宿主机项目路径 (会被挂载到容器的 /workspace)
HOST_PROJECT_PATH=.
# 容器内工作目录绝对路径 (建议保持为 /workspace)
# 容器内工作目录
CONTAINER_WORKSPACE_PATH=/workspace
# --- [SSH 密钥配置] ---
# 指定你宿主机上的私钥文件名 (例如 id_ed25519 或 id_rsa)
SSH_KEY_NAME=id_ed25519
# 宿主机上公钥的完整路径 (用于 Compose 挂载)
# --- SSH 配置 ---
# SSH 端口映射 (宿主机:容器)
SSH_PORT=2222
# 宿主机公钥路径 (会被自动注入到容器 authorized_keys)
# 持久化公钥请通过此变量配置,手动 make add-key 添加的公钥重启后会丢失
SSH_PUB_KEY_PATH=~/.ssh/id_ed25519.pub
# --- 服务端口 ---
# Web 服务端口映射 (宿主机:容器,容器内默认监听 3000)
PORT_WEB=6300
# --- AI Provider API Keys (按需填写,全部默认注释) ---
# Anthropic (Claude) - opencode / omp 支持
# ANTHROPIC_API_KEY=sk-ant-xxx
# OpenAI - opencode / omp 支持
# OPENAI_API_KEY=sk-xxx
# OpenCode 自定义配置
# OPENCODE_API_KEY=xxx

View File

@@ -2,10 +2,11 @@ FROM fedora:latest
# 1. 系统工具与编译环境
RUN dnf update -y && dnf install -y \
curl git wget unzip procps-ng shellcheck\
gcc gcc-c++ make cmake openssl-devel jq tmux vim\
curl git wget unzip procps-ng shellcheck \
gcc gcc-c++ make cmake openssl-devel jq tmux vim \
zsh sudo python3 python3-pip \
openssh-server tar gzip \
postgresql redis mariadb \
&& dnf clean all
@@ -23,12 +24,17 @@ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
RUN curl -fsSL https://bun.sh/install | bash
RUN curl -fsSL https://go.dev/dl/go1.24.4.linux-amd64.tar.gz | tar -C /usr/local -xzf - \
&& go install golang.org/x/tools/gopls@latest \
&& go install github.com/go-delve/delve/cmd/dlv@latest
&& go install github.com/go-delve/delve/cmd/dlv@latest \
&& mv /root/go/bin/* /usr/local/bin/
# 4. 全局安装 AI 工具 (Vibe Coding 核心)
RUN bun install -g opencode-ai
# 4. 全局安装 AI 工具 (Vibe Coding 核心: opencode + oh-my-pi)
RUN bun install -g opencode-ai @oh-my-pi/pi-coding-agent
# 5. SSH & ZSH 配置
# 5. 安装 mise (多语言版本管理器,用于按需管理 Node/Python/Ruby 等)
RUN curl -fsSL https://mise.run | MISE_INSTALL_PATH=/usr/local/bin/mise sh \
&& echo 'eval "$(mise activate zsh)"' >> /root/.zshrc
# 6. SSH & ZSH 配置
RUN ssh-keygen -A && \
mkdir -p /root/.zed /root/.local/share/zed && \
sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config

View File

@@ -5,6 +5,7 @@ RUN apt-get update && apt-get install -y \
curl git wget unzip procps tar gzip shellcheck vim \
gcc g++ make cmake libssl-dev tmux jq \
zsh sudo python3 python3-pip openssh-server \
postgresql-client redis-tools default-mysql-client \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
# 2. 环境变量
@@ -20,18 +21,23 @@ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
RUN curl -fsSL https://bun.sh/install | bash
RUN curl -fsSL https://go.dev/dl/go1.24.4.linux-amd64.tar.gz | tar -C /usr/local -xzf - \
&& go install golang.org/x/tools/gopls@latest \
&& go install github.com/go-delve/delve/cmd/dlv@latest
&& go install github.com/go-delve/delve/cmd/dlv@latest \
&& mv /root/go/bin/* /usr/local/bin/
# 4. 全局安装 AI 工具
RUN bun install -g opencode-ai
# 4. 全局安装 AI 工具 (opencode + oh-my-pi)
RUN bun install -g opencode-ai @oh-my-pi/pi-coding-agent
# 5. SSH & 目录预设 (为 Zed 准备)
# 5. 安装 mise (多语言版本管理器,用于按需管理 Node/Python/Ruby 等)
RUN curl -fsSL https://mise.run | MISE_INSTALL_PATH=/usr/local/bin/mise sh \
&& echo 'eval "$(mise activate zsh)"' >> /root/.zshrc
# 6. SSH & 目录预设 (为 Zed 准备)
RUN ssh-keygen -A && \
mkdir -p /root/.zed /root/.local/share/zed && \
sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN sed -i 's/#PermitUserEnvironment no/PermitUserEnvironment yes/' /etc/ssh/sshd_config
# 6. Shell 美化
# 7. Shell 美化
RUN sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
# 接收来自 compose 的参数

View File

@@ -67,8 +67,9 @@ check:
@docker exec -it $(CONTAINER_NAME) rustc --version || echo "❌ Rust 未就绪"
@docker exec -it $(CONTAINER_NAME) go version || echo "❌ Go 未就绪"
@docker exec -it $(CONTAINER_NAME) bun --version || echo "❌ Bun 未就绪"
@docker exec -it $(CONTAINER_NAME) aider --version || echo "❌ Aider 未就绪"
@docker exec -it $(CONTAINER_NAME) opencode version || echo "❌ OpenCode 未就绪"
@docker exec -it $(CONTAINER_NAME) omp --version || echo "❌ Oh My Pi 未就绪"
@docker exec -it $(CONTAINER_NAME) mise --version || echo "❌ mise 未就绪"
@echo "✨ 自检完成!"
add-key:

View File

@@ -72,6 +72,28 @@ opencode "优化当前目录下 main.rs 的错误处理逻辑"
```
### 使用 Oh My Pi (交互式 AI Coding Agent)
[oh-my-pi](https://github.com/can1357/oh-my-pi)(命令名 `omp`)是一个终端优先的 AI Coding Agent内置 LSP / DAP / 浏览器 / 子代理 / Hindsight 记忆等能力,与 Zed 通过 ACP 协议深度集成。
```bash
# 首次使用:登录某个 provider (Anthropic / OpenAI / Codex / Cursor 等)
omp /login
# 交互式启动 (默认进入 TUI)
omp
# 单次指令模式
omp -p "为当前 Cargo 项目补全 unit test"
# 指定模型
omp --model anthropic/sonnet-4.5
```
* 配置与登录态保存在 `/root/.omp`(已挂载为命名卷 `omp-data``docker compose down` 后不会丢失。
* 若已在 `.env` 中配置了 `ANTHROPIC_API_KEY` / `OPENAI_API_KEY`omp 会自动识别,可跳过 `/login`
---
## 🚀 性能说明
@@ -82,6 +104,7 @@ opencode "优化当前目录下 main.rs 的错误处理逻辑"
* **Bun 依赖加速**`bun-cache` 避免了重复下载 node_modules 依赖。
* **Zed 启动加速**`zed-server` 卷缓存了远程后端二进制文件。
* **工具持久化**:通过 `bun -g` 安装的工具在容器重建后依然可用。
* **mise 语言版本**`mise-data` 卷保留了通过 `mise use` 安装的 Node/Python/Ruby 等语言版本。
## 🧹 常用维护命令
@@ -89,7 +112,6 @@ opencode "优化当前目录下 main.rs 的错误处理逻辑"
| 任务 | 命令 |
| --- | --- |
| **彻底重启环境** | `docker compose restart` |
| **更新 AI 工具 (Aider)** | `pip install --upgrade aider-chat` (容器内运行) |
| **更换基础镜像 (OS)** | 修改 `docker-compose.yml` 中的 `dockerfile` 后运行 `docker compose up --build` |
| **清理所有构建缓存** | `docker compose down -v` (警告:这将清空 Cargo/Bun 缓存) |

View File

@@ -17,8 +17,8 @@ services:
- TERM=xterm-256color
ports:
- "${SSH_PORT:-2222}:22"
- "6300:3000"
- "6173-6175:5173-5175"
- "${PORT_WEB:-6300}:3000"
- "6173-6179:5173-5179"
volumes:
- ${HOST_PROJECT_PATH:-.}:${CONTAINER_WORKSPACE_PATH:-/workspace}:cached
# 1. 使用命名卷持久化整个 .ssh 目录
@@ -31,6 +31,10 @@ services:
# --- 新增Zed 远程开发缓存 ---
- zed-server:/root/.zed_server
- zed-share:/root/.local/share/zed
# --- 新增Oh My Pi 配置/记忆/OAuth 登录态持久化 ---
- omp-data:/root/.omp
# --- 新增mise 多语言版本管理器数据持久化 ---
- mise-data:/root/.local/share/mise
stdin_open: true
tty: true
restart: always
@@ -42,3 +46,5 @@ volumes:
go-cache:
zed-server:
zed-share:
omp-data:
mise-data:

View File

@@ -7,17 +7,19 @@ chmod 700 /root/.ssh
touch /root/.ssh/authorized_keys
touch /root/.ssh/environment
printenv | grep -E '^(PATH|BUN|CARGO|RUST|ANTHROPIC|OPENAI|OPENCODE|TERM|SHELL|WORKSPACE)' > /root/.ssh/environment
# 2. 动态注入挂载的公钥 (解决只读冲突的核心逻辑)
# 仅同步非敏感环境变量到 SSH environment
# (API Keys 通过 compose env_file 注入进程环境,不落盘,避免明文泄露)
printenv | grep -E '^(PATH|BUN|CARGO|RUST|TERM|SHELL|WORKSPACE)' > /root/.ssh/environment
# 2. 动态注入挂载的公钥 (每次启动重建 authorized_keys避免旧公钥残留)
# 持久化公钥请通过 .env 的 SSH_PUB_KEY_PATH 配置
if [ -f /tmp/host_id_ed25519.pub ]; then
echo "检测到挂载的公钥,正在注入..."
# 仅当公钥不存在时才追加,避免重复
if ! grep -qf /tmp/host_id_ed25519.pub /root/.ssh/authorized_keys 2>/dev/null; then
cat /tmp/host_id_ed25519.pub >> /root/.ssh/authorized_keys
cp /tmp/host_id_ed25519.pub /root/.ssh/authorized_keys
echo "✅ 公钥注入成功"
else
echo " 公钥已存在,无需重复注入"
fi
else
# 没有挂载公钥时保留已有 authorized_keys (用户可能用 make add-key 手动加过)
touch /root/.ssh/authorized_keys
fi
# 3. 强制修复权限 (SSH 对此非常敏感)