Skip to content

Commit 59b97e4

Browse files
authored
Update Dockerfile
1 parent 9255ad6 commit 59b97e4

1 file changed

Lines changed: 31 additions & 10 deletions

File tree

Dockerfile

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# - Root & Coder Access: All tools are available for all users.
1414
# - Optimization (China): Timezone set to Asia/Shanghai, PyPI mirror configured.
1515
# - Pre-installed Libraries: A minimal set (numpy, pandas, matplotlib).
16+
# - Extensions Persistence: Extensions installed to system-wide location.
1617
# ==============================================================================
1718

1819
# --- Build Stage ---
@@ -27,6 +28,8 @@ ARG NODE_VERSION=20
2728
ENV CONDA_DIR=/opt/conda
2829
ENV PATH=${CONDA_DIR}/bin:${PATH}
2930
ENV TZ=Asia/Shanghai
31+
# 设置扩展安装到系统目录
32+
ENV VSCODE_EXTENSIONS_DIR=/opt/code-server/extensions
3033

3134
# --- Installation Phase (as root) ---
3235
USER root
@@ -70,13 +73,30 @@ RUN \
7073
pandas \
7174
matplotlib \
7275
\
73-
# 7. Ensure the 'coder' user home directory exists and has correct ownership.
76+
# 7. Create system-wide extensions directory
77+
&& mkdir -p ${VSCODE_EXTENSIONS_DIR} \
78+
&& chmod 755 ${VSCODE_EXTENSIONS_DIR} \
79+
\
80+
# 8. Ensure the 'coder' user home directory exists and has correct ownership.
7481
&& mkdir -p /home/coder && chown -R coder:coder /home/coder \
7582
\
76-
# 8. Clean up to reduce image size.
83+
# 9. Clean up to reduce image size.
7784
&& apt-get clean \
7885
&& rm -rf /var/lib/apt/lists/*
7986

87+
# --- Extensions Installation Phase (as root) ---
88+
# 以 root 身份安装扩展到系统目录
89+
RUN \
90+
# 安装 Python 相关扩展到系统目录
91+
code-server --extensions-dir=${VSCODE_EXTENSIONS_DIR} \
92+
--install-extension ms-python.python \
93+
--install-extension detachhead.basedpyright \
94+
--install-extension ms-python.autopep8 \
95+
--install-extension ms-python.flake8 \
96+
\
97+
# 设置扩展目录权限,让 coder 用户也能读取
98+
&& chown -R root:root ${VSCODE_EXTENSIONS_DIR} \
99+
&& chmod -R 755 ${VSCODE_EXTENSIONS_DIR}
80100

81101
# --- User Configuration Phase (as coder) ---
82102
USER coder
@@ -86,17 +106,14 @@ RUN \
86106
mkdir -p ~/.config/uv && \
87107
printf 'index-url = "https://mirrors.aliyun.com/pypi/simple"\n' > ~/.config/uv/uv.toml && \
88108
\
89-
### --- [ NEW FEATURE: PRE-INSTALL EXTENSIONS ] --- ###
90-
# 2. Install essential VS Code extensions for a rich Python experience.
91-
# This must be run as the 'coder' user.
92-
code-server --install-extension ms-python.python \
93-
--install-extension detachhead.basedpyright \
109+
# 2. 创建 code-server 配置目录和配置文件
110+
mkdir -p ~/.config/code-server && \
111+
printf 'bind-addr: 0.0.0.0:8080\nauth: none\ncert: false\nextensions-dir: %s\n' "${VSCODE_EXTENSIONS_DIR}" > ~/.config/code-server/config.yaml && \
94112
\
95113
# 3. Configure the user's shell to auto-activate the system-wide environment.
96114
conda init bash && \
97115
echo "conda activate py${PYTHON_VERSION}" >> ~/.bashrc
98116

99-
100117
# --- Verification and Final Stage ---
101118
FROM builder
102119

@@ -107,6 +124,8 @@ RUN echo "Verifying root environment..." && \
107124
uv --version && \
108125
npm -v && \
109126
node -v && \
127+
echo "Installed extensions:" && \
128+
ls -la ${VSCODE_EXTENSIONS_DIR} && \
110129
echo "Root environment check PASSED!"
111130

112131
# Final check as CODER.
@@ -115,8 +134,10 @@ RUN echo "Verifying coder environment..." && \
115134
. ~/.bashrc && \
116135
python --version && \
117136
uv --version && \
118-
# Also verify that extensions are installed by checking the directory.
119-
ls -l ~/.local/share/code-server/extensions && \
137+
echo "Extensions directory accessible:" && \
138+
ls -l ${VSCODE_EXTENSIONS_DIR} && \
139+
echo "Code-server config:" && \
140+
cat ~/.config/code-server/config.yaml && \
120141
echo "Coder environment check PASSED!"
121142

122143
# The base image's CMD is inherited automatically.

0 commit comments

Comments
 (0)