Spaces:
dss11
/
Paused

File size: 7,266 Bytes
26cb7ad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
783e3ea
26cb7ad
 
 
 
 
 
 
 
 
 
 
 
f4da2fb
783e3ea
26cb7ad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
783e3ea
26cb7ad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bc487d1
 
 
 
783e3ea
 
26cb7ad
783e3ea
 
26cb7ad
783e3ea
 
26cb7ad
783e3ea
26cb7ad
 
 
 
 
 
 
 
 
 
 
 
 
 
952ef98
26cb7ad
783e3ea
 
 
 
26cb7ad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
783e3ea
26cb7ad
 
783e3ea
26cb7ad
783e3ea
 
 
 
 
 
 
 
 
9c0d834
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
783e3ea
 
 
 
c030d8a
 
 
783e3ea
 
7122dbd
 
783e3ea
 
7122dbd
 
c030d8a
783e3ea
 
 
 
 
 
 
 
26cb7ad
 
c030d8a
783e3ea
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
FROM archlinux:latest

RUN echo -e "[multilib]\nInclude = /etc/pacman.d/mirrorlist" >> /etc/pacman.conf \
    && echo -e "[archlinuxcn]\nServer = https://mirrors.aliyun.com/archlinuxcn/\$arch" >> /etc/pacman.conf \
    && echo -e "[chaotic-aur]\nServer = https://geo-mirror.chaotic.cx/\$repo/\$arch" >> /etc/pacman.conf \
    && echo -e "[atri]\nServer = https://repo.apeiria.net/\$arch" >> /etc/pacman.conf

RUN pacman-key --init \
    && pacman-key --lsign-key "farseerfc@archlinux.org" \
    && pacman-key --recv-key 3056513887B78AEB --keyserver keyserver.ubuntu.com \
    && pacman-key --lsign-key 3056513887B78AEB \
    && pacman-key --recv-keys 293B93D8A471059F85D716A65BA92099D9BE2DAA \
    && pacman-key --lsign-key 293B93D8A471059F85D716A65BA92099D9BE2DAA \
    && pacman -Sy --noconfirm archlinuxcn-keyring

RUN pacman -Syu --noconfirm yay

RUN yay -S --noconfirm \
    aria2 \
    base-devel \
    clang \
    cmake \
    cloudflared \
    code-server \
    code-server-marketplace \
    curl \
    deno \
    direnv \
    fisher \
    fish \
    gcc \
    git \
    git-lfs \
    go \
    intel-oneapi-basekit \
    jq \
    nginx \
    nix \
    nodejs \
    openblas64 \
    openssh \
    p7zip \
    pkgconf \
    pkgfile \
    pypy \
    python \
    python-pip \
    ruff \
    rust \
    rye \
    screen \
    tinygo \
    unzip \
    uv \
    uvx \
    wget \
    xmake \
    zig \
    zip \
    && yay -Scc --noconfirm \
    && rm -rf /var/cache/pacman/*

RUN aria2c -c -x16 https://hf-mirror.com/hfd/hfd.sh \
    && chmod a+x hfd.sh \
    && mv hfd.sh /usr/bin/hfd

RUN pkgfile --update

RUN git lfs install

RUN corepack prepare pnpm@latest \
    && corepack enable pnpm

COPY fish-oneapi /usr/bin/fish-oneapi

RUN chmod +x /usr/bin/fish-oneapi

# 创建符合 HF Spaces 要求的用户 (user ID 1000)
RUN useradd -m -u 1000 user

# 切换到用户
USER user

# 设置工作目录
WORKDIR /home/user

RUN mkdir -p /home/user/.ssh

RUN plugins=( \
    "danhper/fish-ssh-agent" \
    "jethrokuan/z" \
    "franciscolourenco/done" \
    "jorgebucaran/autopair.fish" \
) \
&& for plugin in "${plugins[@]}"; do \
    fish -c "fisher install $plugin"; \
done

RUN rye toolchain register /usr/bin/python \
    && rye toolchain register /usr/bin/pypy

RUN fish -c 'SHELL=/usr/bin/fish pnpm setup'

# 配置 code-server (HF Spaces 默认端口 7860)
RUN mkdir -p /home/user/.config/code-server/ \
    && touch /home/user/.config/code-server/config.yaml \
    && echo -e "bind-addr: 0.0.0.0:7860\nauth: password\ncert: false" > /home/user/.config/code-server/config.yaml

RUN extensions=( \
    "aaron-bond.better-comments" \
    "ahmadalli.vscode-nginx-conf" \
    "alefragnani.bookmarks" \
    "antfu.browse-lite" \
    "antfu.vite" \
    "arrterian.nix-env-selector" \
    "bbenoist.nix" \
    "bierner.lit-html" \
    "christian-kohler.npm-intellisense" \
    "christian-kohler.path-intellisense" \
    "claui.packaging" \
    "codezombiech.gitignore" \
    "dart-code.dart-code" \
    "dart-code.flutter" \
    "davidanson.vscode-markdownlint" \
    "dbaeumer.vscode-eslint" \
    "denoland.vscode-deno" \
    "donjayamanne.githistory" \
    "eamodio.gitlens" \
    "editorconfig.editorconfig" \
    "esbenp.prettier-vscode" \
    "fill-labs.dependi" \
    "formulahendry.auto-close-tag" \
    "formulahendry.auto-rename-tag" \
    "gera2ld.markmap-vscode" \
    "get-snippets.get-snippets" \
    "github.codespaces" \
    "github.remotehub" \
    "github.vscode-github-actions" \
    "golang.go" \
    "graphql.vscode-graphql-syntax" \
    "gruntfuggly.todo-tree" \
    "jeff-hykin.better-dockerfile-syntax" \
    "jnoortheen.nix-ide" \
    "justjavac.vscode-deno-extensionpack" \
    "laurencebahiirwa.deno-std-lib-snippets" \
    "lit.lit-snippets" \
    "matthewpi.caddyfile-support" \
    "mechatroner.rainbow-csv" \
    "mhutchie.git-graph" \
    "mirone.milkdown" \
    "misterj.vue-volar-extention-pack" \
    "mkhl.direnv" \
    "mrmlnc.vscode-json5" \
    "ms-dotnettools.csdevkit" \
    "ms-dotnettools.csharp" \
    "ms-dotnettools.vscode-dotnet-runtime" \
    "ms-dotnettools.vscodeintellicode-csharp" \
    "ms-python.black-formatter" \
    "ms-python.debugpy" \
    "ms-python.python" \
    "ms-python.vscode-pylance" \
    "ms-toolsai.jupyter" \
    "ms-toolsai.jupyter-keymap" \
    "ms-toolsai.jupyter-renderers" \
    "ms-toolsai.vscode-jupyter-cell-tags" \
    "ms-toolsai.vscode-jupyter-slideshow" \
    "ms-vscode.azure-repos" \
    "ms-vscode.cmake-tools" \
    "ms-vscode.cpptools" \
    "ms-vscode.cpptools-extension-pack" \
    "ms-vscode.cpptools-themes" \
    "ms-vscode.remote-repositories" \
    "msyrus.go-doc" \
    "njpwerner.autodocstring" \
    "oderwat.indent-rainbow" \
    "pinage404.nix-extension-pack" \
    "redhat.vscode-xml" \
    "redhat.vscode-yaml" \
    "rust-lang.rust-analyzer" \
    "rxliuli.tsx" \
    "sibiraj-s.vscode-scss-formatter" \
    "swellaby.rust-pack" \
    "syler.sass-indented" \
    "tamasfe.even-better-toml" \
    "timonwong.shellcheck" \
    "twxs.cmake" \
    "visualstudioexptteam.intellicode-api-usage-examples" \
    "visualstudioexptteam.vscodeintellicode" \
    "visualstudioexptteam.vscodeintellicode-completions" \
    "vitaliymaz.vscode-svg-previewer" \
    "vitest.explorer" \
    "vue.volar" \
    "wayou.vscode-todo-highlight" \
) \
&& for extension in "${extensions[@]}"; do \
    code-server --config /home/user/.config/code-server/config.yaml --install-extension "$extension"; \
done

RUN code-server --config /home/user/.config/code-server/config.yaml --uninstall-extension "serayuzgur.crates"

# 切换回 root 用户进行系统配置
USER root

# 配置 nginx (使用高端口,符合 HF Spaces 要求)
RUN mkdir -p /var/www/html
RUN echo '<html><head><title>Hello World</title></head><body><h1>Hello World</h1><p>Welcome to my server!</p></body></html>' > /var/www/html/index.html

# 创建 nginx 配置 (监听端口 8080,符合 HF 要求)
RUN mkdir -p /etc/nginx/sites-available /etc/nginx/sites-enabled
RUN echo 'server {\
    listen 8080;\
    server_name _;\
    root /var/www/html;\
    index index.html;\
    \
    location / {\
        try_files $uri $uri/ =404;\
    }\
    \
    # 隐藏的 VSCode 访问入口(通过 Cloudflare Tunnel 访问)\
    location /admin-vscode {\
        proxy_pass http://127.0.0.1:7860;\
        proxy_set_header Host $host;\
        proxy_set_header X-Real-IP $remote_addr;\
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\
        proxy_set_header X-Forwarded-Proto $scheme;\
    }\
}' > /etc/nginx/sites-available/default

RUN ln -sf /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default

# 给用户 nginx 权限
RUN mkdir -p /var/log/nginx /var/lib/nginx /run/nginx
RUN chown -R user:user /var/www/html /var/log/nginx /var/lib/nginx /run/nginx 2>/dev/null || true
RUN chmod -R 755 /var/www/html

# 复制启动脚本
COPY start-services.sh /usr/bin/start-services.sh
RUN chmod +x /usr/bin/start-services.sh

# 验证脚本是否正确复制
RUN ls -la /usr/bin/start-services.sh

# 切换回用户
USER user

# 设置环境变量
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH

EXPOSE 7860
EXPOSE 8080

# 启动多服务脚本
CMD ["/usr/bin/start-services.sh"]