Compare commits

..

2 Commits

Author SHA1 Message Date
b250a3693b fix: keep bun, opencode coommand in env 2025-12-25 17:27:28 +08:00
35034f5e2d Remove .env from tracking 2025-12-25 17:26:32 +08:00
5 changed files with 16 additions and 55 deletions

View File

@@ -1,52 +0,0 @@
# =================================================================
# Vibe Coding 开发环境 - 环境变量模板
# 使用说明:
# 1. 复制此文件并重命名为 .env
# 2. 在 .env 中填写你真实的 API Key 和配置
# 3. 注意:不要将 .env 文件上传到 Git 仓库!
# =================================================================
# --- [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
# --- [路径配置] ---
# 宿主机项目代码目录 (默认为当前目录 .)
HOST_PROJECT_PATH=/workspace
# 容器内的工作目录绝对路径 (建议保持为 /workspace)
CONTAINER_WORKSPACE_PATH=/workspace
# --- [SSH 密钥配置] ---
# 指定你宿主机上的私钥文件名 (例如 id_ed25519 或 id_rsa)
SSH_KEY_NAME=id_ed25519
# 宿主机上公钥的完整路径 (用于 Compose 挂载)
SSH_PUB_KEY_PATH=~/.ssh/id_ed25519.pub

View File

@@ -8,12 +8,15 @@ RUN dnf update -y && dnf install -y \
openssh-server tar gzip \ openssh-server tar gzip \
&& dnf clean all && dnf clean all
# 2. 环境变量配置 # 2. 环境变量配置
ENV CARGO_HOME=/usr/local/cargo \ ENV CARGO_HOME=/usr/local/cargo \
RUSTUP_HOME=/usr/local/rustup \ RUSTUP_HOME=/usr/local/rustup \
BUN_INSTALL="/root/.bun" BUN_INSTALL="/root/.bun"
ENV PATH="$BUN_INSTALL/bin:/usr/local/cargo/bin:${PATH}" ENV PATH="$BUN_INSTALL/bin:/usr/local/cargo/bin:${PATH}"
RUN chsh -s /bin/zsh root
# 3. 安装 Rust & Bun # 3. 安装 Rust & Bun
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y 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://bun.sh/install | bash
@@ -26,7 +29,7 @@ RUN ssh-keygen -A && \
mkdir -p /root/.zed /root/.local/share/zed && \ mkdir -p /root/.zed /root/.local/share/zed && \
sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
# 6. Shell 美化 RUN sed -i 's/#PermitUserEnvironment no/PermitUserEnvironment yes/' /etc/ssh/sshd_config
RUN sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended RUN sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
# 接收来自 compose 的参数 # 接收来自 compose 的参数

View File

@@ -12,6 +12,7 @@ ENV CARGO_HOME=/usr/local/cargo \
RUSTUP_HOME=/usr/local/rustup \ RUSTUP_HOME=/usr/local/rustup \
BUN_INSTALL="/root/.bun" BUN_INSTALL="/root/.bun"
ENV PATH="$BUN_INSTALL/bin:/usr/local/cargo/bin:${PATH}" ENV PATH="$BUN_INSTALL/bin:/usr/local/cargo/bin:${PATH}"
RUN chsh -s /bin/zsh root
# 3. 安装 Rust & Bun # 3. 安装 Rust & Bun
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
@@ -25,6 +26,7 @@ RUN ssh-keygen -A && \
mkdir -p /root/.zed /root/.local/share/zed && \ mkdir -p /root/.zed /root/.local/share/zed && \
sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config 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 美化 # 6. Shell 美化
RUN sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended RUN sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended

View File

@@ -8,28 +8,34 @@ services:
# 将路径传递给 Dockerfile 阶段 # 将路径传递给 Dockerfile 阶段
CONTAINER_WORKSPACE: ${CONTAINER_WORKSPACE_PATH:-/workspace} CONTAINER_WORKSPACE: ${CONTAINER_WORKSPACE_PATH:-/workspace}
container_name: vibe-coding-env container_name: vibe-coding-env
hostname: vibe-coding
env_file: .env env_file: .env
environment: environment:
# 让容器内部程序也能感知工作目录 # 让容器内部程序也能感知工作目录
- WORKSPACE=${CONTAINER_WORKSPACE_PATH:-/workspace} - WORKSPACE=${CONTAINER_WORKSPACE_PATH:-/workspace}
- SHELL=/bin/zsh
- TERM=xterm-256color
ports: ports:
- "${SSH_PORT:-2222}:22" - "${SSH_PORT:-2222}:22"
- "6300:3000" - "6300:3000"
- "6173-6175:5173-5175" - "6173-6175:5173-5175"
volumes: volumes:
- ${HOST_PROJECT_PATH:-.}:${CONTAINER_WORKSPACE_PATH:-/workspace}:cached - ${HOST_PROJECT_PATH:-.}:${CONTAINER_WORKSPACE_PATH:-/workspace}:cached
# 1. 使用命名卷持久化整个 .ssh 目录
- ssh-data:/root/.ssh
- ${SSH_PUB_KEY_PATH:-~/.ssh/id_ed25519.pub}:/tmp/host_id_ed25519.pub:ro - ${SSH_PUB_KEY_PATH:-~/.ssh/id_ed25519.pub}:/tmp/host_id_ed25519.pub:ro
- cargo-cache:/usr/local/cargo/registry - cargo-cache:/usr/local/cargo/registry
- bun-cache:/root/.bun/install/cache - bun-cache:/root/.bun/install/cache
# --- 新增Zed 远程开发缓存 --- # --- 新增Zed 远程开发缓存 ---
- zed-server:/root/.zed - zed-server:/root/.zed_server
- zed-share:/root/.local/share/zed - zed-share:/root/.local/share/zed
stdin_open: true stdin_open: true
tty: true tty: true
restart: always restart: always
volumes: volumes:
ssh-data:
cargo-cache: cargo-cache:
bun-cache: bun-cache:
zed-server: zed-server:

View File

@@ -5,7 +5,9 @@ set -e
mkdir -p /root/.ssh mkdir -p /root/.ssh
chmod 700 /root/.ssh chmod 700 /root/.ssh
touch /root/.ssh/authorized_keys 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. 动态注入挂载的公钥 (解决只读冲突的核心逻辑) # 2. 动态注入挂载的公钥 (解决只读冲突的核心逻辑)
if [ -f /tmp/host_id_ed25519.pub ]; then if [ -f /tmp/host_id_ed25519.pub ]; then
echo "检测到挂载的公钥,正在注入..." echo "检测到挂载的公钥,正在注入..."
@@ -20,7 +22,7 @@ fi
# 3. 强制修复权限 (SSH 对此非常敏感) # 3. 强制修复权限 (SSH 对此非常敏感)
chmod 600 /root/.ssh/authorized_keys chmod 600 /root/.ssh/authorized_keys
chown root:root /root/.ssh/authorized_keys chown -R root:root /root/.ssh
# 根据不同 OS 启动 SSH # 根据不同 OS 启动 SSH