135 lines
5.2 KiB
Go
135 lines
5.2 KiB
Go
# 此文件为远程开发环境配置文件
|
||
FROM debian:bookworm
|
||
|
||
# ==========================================
|
||
# 1. 基础环境变量
|
||
# ==========================================
|
||
ENV GO_VERSION=1.25.0
|
||
ENV GOPATH=/root/go
|
||
ENV PATH=/usr/local/go/bin:${GOPATH}/bin:${PATH}
|
||
ENV LC_ALL=zh_CN.UTF-8
|
||
ENV LANG=zh_CN.UTF-8
|
||
ENV LANGUAGE=zh_CN.UTF-8
|
||
ENV XDG_DATA_HOME=/var/lib
|
||
ENV XDG_CACHE_HOME=/workspace/.cache
|
||
ENV GOCACHE=/workspace/.cache/go-build
|
||
ENV GOMODCACHE=/workspace/.cache/gomod
|
||
|
||
# ==========================================
|
||
# 2. Codex 配置 (更换时修改这里,重新 build)
|
||
# ==========================================
|
||
ENV CODEX_BASE_URL="https://api.jucode.cn/v1"
|
||
|
||
ENV CODEX_MODEL="gpt-5.4"
|
||
|
||
ENV OPENAI_API_KEY="sk-E0ZZIFNnD0RkhMC9pT2AGMutz9vNy2VLNrgyyobT5voa81pQ"
|
||
|
||
# ==========================================
|
||
# 3. 安装系统依赖、Golang、Code-server
|
||
# ==========================================
|
||
RUN set -ex; \
|
||
apt update && \
|
||
apt install -y --no-install-recommends \
|
||
wget rsync unzip openssh-server vim lsof git git-lfs \
|
||
locales libgit2-1.5 libgit2-dev net-tools jq curl ca-certificates sudo gnupg lsb-release xz-utils && \
|
||
curl -fsSLO "https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz" && \
|
||
rm -rf /usr/local/go && tar -C /usr/local -xzf "go${GO_VERSION}.linux-amd64.tar.gz" && \
|
||
rm -f "go${GO_VERSION}.linux-amd64.tar.gz" && \
|
||
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.54.2 && \
|
||
curl -fsSL https://code-server.dev/install.sh | sh && \
|
||
apt clean && rm -rf /var/lib/apt/lists/*
|
||
|
||
# ==========================================
|
||
# 4. 安装工具链 (国内加速版)
|
||
# ==========================================
|
||
RUN set -ex; \
|
||
go install -v golang.org/x/tools/gopls@latest && \
|
||
go install -v github.com/cweill/gotests/gotests@latest && \
|
||
go install -v github.com/josharian/impl@latest && \
|
||
go install -v github.com/haya14busa/goplay/cmd/goplay@latest && \
|
||
go install -v github.com/go-delve/delve/cmd/dlv@latest && \
|
||
go install github.com/goreleaser/goreleaser/v2@latest && \
|
||
wget -q "https://npmmirror.com/mirrors/node/v22.11.0/node-v22.11.0-linux-x64.tar.xz" -O /tmp/node.tar.xz && \
|
||
tar -xJf /tmp/node.tar.xz -C /usr/local --strip-components=1 && \
|
||
rm -f /tmp/node.tar.xz && \
|
||
npm config set registry https://registry.npmmirror.com/ && \
|
||
npm install -g @openai/codex
|
||
|
||
# ==========================================
|
||
# 5. 生成 Codex 配置文件 (独立 RUN 块,彻底规避格式报错)
|
||
# ==========================================
|
||
RUN mkdir -p /root/.codex
|
||
|
||
RUN cat > /root/.codex/config.toml <<EOF
|
||
model_provider = "OpenAI"
|
||
model = "${CODEX_MODEL}"
|
||
model_reasoning_effort = "high"
|
||
disable_response_storage = true
|
||
|
||
[model_providers.OpenAI]
|
||
name = "OpenAI"
|
||
base_url = "${CODEX_BASE_URL}"
|
||
wire_api = "responses"
|
||
requires_openai_auth = true
|
||
# 自动压缩触发阈值(token数)
|
||
model_auto_compact_token_limit = 100000 # 超过此值自动压缩
|
||
# 上下文窗口大小(根据模型调整)
|
||
model_context_window = 128000
|
||
# 压缩后保留的最小上下文
|
||
model_compact_min_keep_tokens = 20000
|
||
# 自动压缩开关(默认true)
|
||
model_auto_compact = true
|
||
EOF
|
||
|
||
RUN cat > /root/.codex/auth.json <<EOF
|
||
{
|
||
"auth_mode": "apikey",
|
||
"OPENAI_API_KEY": "${OPENAI_API_KEY}"
|
||
}
|
||
EOF
|
||
|
||
RUN chmod 600 /root/.codex/auth.json && \
|
||
echo "export OPENAI_API_KEY=\"${OPENAI_API_KEY}\"" >> /root/.bashrc && \
|
||
echo "export CODEX_API_KEY=\"${OPENAI_API_KEY}\"" >> /root/.bashrc
|
||
|
||
# ==========================================
|
||
# 6. 安装 code-server 插件
|
||
# ==========================================
|
||
RUN set -eux; \
|
||
USER_DATA_DIR=/var/lib/code-server; \
|
||
EXTENSIONS_DIR="${USER_DATA_DIR}/extensions"; \
|
||
mkdir -p "${EXTENSIONS_DIR}" /root/.vscode-server; \
|
||
FAILED_EXTENSIONS=""; \
|
||
for ext in \
|
||
dbaeumer.vscode-eslint \
|
||
redhat.vscode-yaml \
|
||
esbenp.prettier-vscode \
|
||
golang.go \
|
||
eamodio.gitlens \
|
||
waderyan.gitblame \
|
||
donjayamanne.githistory \
|
||
mhutchie.git-graph \
|
||
tencent-cloud.coding-copilot\
|
||
; do \
|
||
if ! /usr/bin/code-server --install-extension "${ext}" --user-data-dir "${USER_DATA_DIR}" --extensions-dir "${EXTENSIONS_DIR}"; then \
|
||
FAILED_EXTENSIONS="${FAILED_EXTENSIONS} ${ext}"; \
|
||
echo "WARN: extension install failed: ${ext}"; \
|
||
fi; \
|
||
done; \
|
||
rm -rf /root/.vscode-server/extensions /root/extensions; \
|
||
ln -s "${EXTENSIONS_DIR}" /root/.vscode-server/extensions; \
|
||
ln -s "${EXTENSIONS_DIR}" /root/extensions; \
|
||
chmod -R a+rwX "${USER_DATA_DIR}"; \
|
||
chmod -R a+rX /root/.vscode-server; \
|
||
[ -z "${FAILED_EXTENSIONS}" ] && echo "所有插件安装完成 ✅" || echo "以下插件安装失败:${FAILED_EXTENSIONS}"
|
||
|
||
# ==========================================
|
||
# 7. 统一缓存目录 & 环境变量
|
||
# ==========================================
|
||
RUN mkdir -p /workspace/.cache/go-build /workspace/.cache/gomod /workspace/.cache/goimports && \
|
||
chmod -R a+rwx /workspace/.cache && \
|
||
printf '%s\n' \
|
||
'export XDG_CACHE_HOME=/workspace/.cache' \
|
||
'export GOCACHE=/workspace/.cache/go-build' \
|
||
'export GOMODCACHE=/workspace/.cache/gomod' \
|
||
>> /etc/profile |