File size: 7,018 Bytes
a1e7f2f
a604189
19b7bc4
cad05d5
dca766c
5090700
dca766c
5090700
 
 
a604189
cad05d5
 
a1e7f2f
a604189
cad05d5
a604189
5090700
864d62a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ee0a899
 
864d62a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ee0a899
 
864d62a
ee0a899
cad05d5
864d62a
 
 
 
ee0a899
 
864d62a
a604189
0ab466c
864d62a
 
0ab466c
cad05d5
864d62a
 
ee0a899
cad05d5
19b7bc4
0ab466c
cad05d5
 
19b7bc4
0ab466c
ebdac77
cad05d5
 
b1bf74d
cad05d5
ee0a899
a604189
864d62a
a604189
cad05d5
 
 
 
 
 
864d62a
cad05d5
 
 
 
 
 
 
864d62a
cad05d5
 
 
 
864d62a
cad05d5
 
 
 
864d62a
cad05d5
 
 
864d62a
cad05d5
 
 
cc94aba
cad05d5
 
 
 
cc94aba
cad05d5
 
864d62a
 
 
 
5090700
dca766c
cad05d5
864d62a
cad05d5
cc94aba
 
 
 
 
 
 
 
dca766c
864d62a
 
 
 
 
dca766c
5090700
dca766c
0ab466c
864d62a
0ab466c
ebdac77
0ab466c
864d62a
19b7bc4
cc94aba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
FROM ubuntu:22.04

SHELL ["/bin/bash", "-o", "pipefail", "-c"]

ENV DEBIAN_FRONTEND=noninteractive \
    TZ=Asia/Shanghai \
    LANG=en_US.UTF-8 \
    LC_ALL=en_US.UTF-8 \
    PYTHONUNBUFFERED=1 \
    PIP_NO_CACHE_DIR=1 \
    HOME=/root \
    ZSH=/root/.oh-my-zsh \
    PORT=7860

# ------------------------------------------------------------
# 1) 安装系统基础依赖与 Playwright 运行环境
# ------------------------------------------------------------
RUN apt-get update && apt-get install -y --no-install-recommends \
    ca-certificates \
    curl \
    wget \
    git \
    git-lfs \
    sudo \
    zsh \
    locales \
    tzdata \
    gnupg \
    vim \
    nano \
    jq \
    tree \
    htop \
    tmux \
    zip \
    unzip \
    tar \
    xz-utils \
    build-essential \
    python3 \
    python3-pip \
    python3-dev \
    python-is-python3 \
    libasound2 \
    libatk-bridge2.0-0 \
    libatk1.0-0 \
    libc6 \
    libcairo2 \
    libcups2 \
    libdbus-1-3 \
    libdrm2 \
    libexpat1 \
    libgbm1 \
    libgcc-s1 \
    libglib2.0-0 \
    libgtk-3-0 \
    libnspr4 \
    libnss3 \
    libpango-1.0-0 \
    libpangocairo-1.0-0 \
    libstdc++6 \
    libx11-6 \
    libx11-xcb1 \
    libxcb1 \
    libxcomposite1 \
    libxcursor1 \
    libxdamage1 \
    libxext6 \
    libxfixes3 \
    libxi6 \
    libxkbcommon0 \
    libxrandr2 \
    libxrender1 \
    libxshmfence1 \
    libxss1 \
    libxtst6 \
    libatspi2.0-0 \
    libwayland-client0 \
    libwayland-cursor0 \
    libwayland-egl1 \
 && locale-gen en_US.UTF-8 \
 && update-locale LANG=en_US.UTF-8 \
 && rm -rf /var/lib/apt/lists/*

# ------------------------------------------------------------
# 2) 安装最新 Node.js 25 / pnpm / npm / Claude Code
# ------------------------------------------------------------
RUN curl -fsSL https://deb.nodesource.com/setup_25.x | bash - \
 && apt-get update \
 && apt-get install -y --no-install-recommends nodejs \
 && npm install -g npm@latest pnpm@latest @anthropic-ai/claude-code \
 && npm cache clean --force \
 && rm -rf /var/lib/apt/lists/*

# ------------------------------------------------------------
# 3) 安装 GitHub CLI (gh)
# ------------------------------------------------------------
RUN mkdir -p -m 755 /etc/apt/keyrings \
 && curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg \
    | gpg --dearmor -o /etc/apt/keyrings/githubcli-archive-keyring.gpg \
 && chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg \
 && echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" \
    > /etc/apt/sources.list.d/github-cli.list \
 && apt-get update \
 && apt-get install -y --no-install-recommends gh \
 && rm -rf /var/lib/apt/lists/*

# ------------------------------------------------------------
# 4) 安装 code-server & Playwright
# ------------------------------------------------------------
RUN curl -fsSL https://code-server.dev/install.sh | sh \
 && python3 -m pip install --no-cache-dir --upgrade pip setuptools wheel \
 && python3 -m pip install --no-cache-dir playwright \
 && python3 -m playwright install chromium \
 && rm -rf /root/.cache/pip

# ------------------------------------------------------------
# 5) Zsh 极简主题配置 (去框、去除主机名、仅显示 user:path)
# ------------------------------------------------------------
RUN git clone --depth=1 https://github.com/ohmyzsh/ohmyzsh.git "${ZSH}" \
 && git clone --depth=1 https://github.com/zsh-users/zsh-autosuggestions "${ZSH}/custom/plugins/zsh-autosuggestions" \
 && git clone --depth=1 https://github.com/zsh-users/zsh-syntax-highlighting "${ZSH}/custom/plugins/zsh-syntax-highlighting"

RUN mkdir -p "${ZSH}/custom/themes" \
 && echo 'PROMPT="%F{green}%n%f:%F{cyan}%~%f > "' > "${ZSH}/custom/themes/minimal.zsh-theme" \
 && echo 'RPROMPT="%F{240}[%*]%f"' >> "${ZSH}/custom/themes/minimal.zsh-theme"

RUN cat > /root/.zshrc <<'EOF'
export ZSH="$HOME/.oh-my-zsh"
zstyle ':omz:update' mode disabled
ZSH_THEME="minimal"
plugins=(git zsh-autosuggestions zsh-syntax-highlighting)
source $ZSH/oh-my-zsh.sh
alias ll='ls -alF --color=auto'
alias c='clear'
alias backup='python3 /root/persistence.py --backup'
alias restore='python3 /root/persistence.py --restore'
bindkey '^ ' autosuggest-accept
EOF

# ------------------------------------------------------------
# 6) 数据持久化脚本 (智能排除依赖库)
# ------------------------------------------------------------
RUN cat > /root/persistence.py <<'EOF'
import os, sys, tarfile

BACKUP_NAME = "space_source_backup.tar.gz"

EXCLUDE_DIRS = {
    "node_modules", ".npm", ".pnpm-store", ".cache",
    "__pycache__", "venv", ".venv", ".pytest_cache",
    "CachedExtensionVSIXs", "workspaceStorage", "logs"
}

def filter_function(tarinfo):
    name = os.path.basename(tarinfo.name)
    if name in EXCLUDE_DIRS:
        print(f" -> Skipping: {tarinfo.name}")
        return None
    return tarinfo

def backup():
    print("[*] 正在执行智能备份 (已排除 node_modules/venv 等依赖)...")
    with tarfile.open(BACKUP_NAME, "w:gz") as tar:
        for item in os.listdir("/root"):
            if item != BACKUP_NAME:
                tar.add(os.path.join("/root", item), arcname=item, filter=filter_function)

    size_mb = os.path.getsize(BACKUP_NAME) / (1024 * 1024)
    print(f"[+] 备份成功!体积:{size_mb:.2f} MB")
    print(f"[!] 请在侧边栏右键点击 {BACKUP_NAME} 选择 'Download' 下载。")
    print("[提示] 下次还原后,只需重新执行 npm/pnpm install 或 pip install 即可。")

def restore():
    if not os.path.exists(BACKUP_NAME):
        print(f"[!] 错误:找不到备份文件 {BACKUP_NAME}。请先上传。")
        return
    print("[*] 正在还原源代码和配置...")
    with tarfile.open(BACKUP_NAME, "r:gz") as tar:
        tar.extractall(path="/root")
    print("[+] 还原成功!请重新安装项目依赖。")

if __name__ == "__main__":
    if "--backup" in sys.argv:
        backup()
    elif "--restore" in sys.argv:
        restore()
EOF

# ------------------------------------------------------------
# 7) code-server 设置
# ------------------------------------------------------------
RUN mkdir -p /root/.config/code-server /root/.local/share/code-server/User

RUN cat > /root/.config/code-server/config.yaml <<'EOF'
bind-addr: 0.0.0.0:7860
auth: none
EOF

RUN cat > /root/.local/share/code-server/User/settings.json <<'EOF'
{
  "workbench.startupEditor": "none",
  "telemetry.telemetryLevel": "off",
  "terminal.integrated.defaultProfile.linux": "zsh",
  "security.workspace.trust.enabled": false,
  "workbench.colorTheme": "Default Dark+"
}
EOF

# ------------------------------------------------------------
# 8) 最终配置
# ------------------------------------------------------------
WORKDIR /root
EXPOSE 7860
RUN chsh -s "$(which zsh)" root

ENTRYPOINT ["code-server", "--bind-addr", "0.0.0.0:7860", "--auth", "none", "/root"]