Skip to content

Commit cea8ccd

Browse files
authored
Update Dockerfile
1 parent 60487cb commit cea8ccd

1 file changed

Lines changed: 12 additions & 70 deletions

File tree

Dockerfile

Lines changed: 12 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
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.
17-
# - Auto Git Config: Automatically configures git user from environment variables.
1816
# ==============================================================================
1917

2018
# --- Build Stage ---
@@ -29,9 +27,6 @@ ARG NODE_VERSION=20
2927
ENV CONDA_DIR=/opt/conda
3028
ENV PATH=${CONDA_DIR}/bin:${PATH}
3129
ENV TZ=Asia/Shanghai
32-
# 设置扩展安装到系统目录
33-
ENV VSCODE_EXTENSIONS_DIR=/opt/code-server/extensions
34-
# Git 配置默认值
3530
ENV GIT_USER_EMAIL="code-server@fjy8018.top"
3631
ENV GIT_USER_NAME="fjy8018"
3732

@@ -50,6 +45,8 @@ RUN \
5045
gnupg \
5146
\
5247
&& ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone \
48+
&& git config --global user.email "$GIT_EMAIL" \
49+
&& git config --global user.name "$GIT_NAME" \
5350
\
5451
# Install Node.js from official repository.
5552
&& mkdir -p /etc/apt/keyrings \
@@ -77,36 +74,14 @@ RUN \
7774
pandas \
7875
matplotlib \
7976
\
80-
# 7. Create system-wide extensions directory
81-
&& mkdir -p ${VSCODE_EXTENSIONS_DIR} \
82-
&& chmod 755 ${VSCODE_EXTENSIONS_DIR} \
83-
\
84-
# 8. Ensure the 'coder' user home directory exists and has correct ownership.
77+
# 7. Ensure the 'coder' user home directory exists and has correct ownership.
8578
&& mkdir -p /home/coder && chown -R coder:coder /home/coder \
8679
\
87-
# 9. Clean up to reduce image size.
80+
# 8. Clean up to reduce image size.
8881
&& apt-get clean \
8982
&& rm -rf /var/lib/apt/lists/*
9083

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

105-
# --- Git Configuration Script ---
106-
# 创建 Git 配置脚本
107-
RUN git config --global user.email "$GIT_EMAIL" \
108-
&& git config --global user.name "$GIT_NAME"
109-
11085
# --- User Configuration Phase (as coder) ---
11186
USER coder
11287

@@ -115,39 +90,16 @@ RUN \
11590
mkdir -p ~/.config/uv && \
11691
printf 'index-url = "https://mirrors.aliyun.com/pypi/simple"\n' > ~/.config/uv/uv.toml && \
11792
\
118-
# 2. 创建 code-server 配置目录和配置文件
119-
mkdir -p ~/.config/code-server && \
120-
printf 'bind-addr: 0.0.0.0:8080\nauth: none\ncert: false\nextensions-dir: %s\n' "${VSCODE_EXTENSIONS_DIR}" > ~/.config/code-server/config.yaml && \
93+
### --- [ NEW FEATURE: PRE-INSTALL EXTENSIONS ] --- ###
94+
# 2. Install essential VS Code extensions for a rich Python experience.
95+
# This must be run as the 'coder' user.
96+
code-server --install-extension ms-python.python \
97+
--install-extension detachhead.basedpyright \
12198
\
12299
# 3. Configure the user's shell to auto-activate the system-wide environment.
123100
conda init bash && \
124-
echo "conda activate py${PYTHON_VERSION}" >> ~/.bashrc && \
125-
\
126-
# 4. 在用户的 .bashrc 中添加 Git 配置初始化
127-
echo "" >> ~/.bashrc && \
128-
echo "# Auto-configure Git on first login" >> ~/.bashrc && \
129-
echo "if [ ! -f ~/.git-configured ]; then" >> ~/.bashrc && \
130-
echo " /usr/local/bin/setup-git.sh" >> ~/.bashrc && \
131-
echo " touch ~/.git-configured" >> ~/.bashrc && \
132-
echo "fi" >> ~/.bashrc
101+
echo "conda activate py${PYTHON_VERSION}" >> ~/.bashrc
133102

134-
# --- Startup Script ---
135-
# 创建启动脚本来处理环境变量
136-
USER root
137-
RUN cat > /usr/local/bin/entrypoint.sh << 'EOF'
138-
#!/bin/bash
139-
140-
# 运行 Git 配置脚本
141-
/usr/local/bin/setup-git.sh
142-
143-
# 切换到 coder 用户并启动 code-server
144-
exec gosu coder "$@"
145-
EOF
146-
147-
RUN chmod +x /usr/local/bin/entrypoint.sh
148-
149-
# 安装 gosu(如果基础镜像没有的话)
150-
RUN apt-get update && apt-get install -y gosu && apt-get clean && rm -rf /var/lib/apt/lists/*
151103

152104
# --- Verification and Final Stage ---
153105
FROM builder
@@ -159,10 +111,6 @@ RUN echo "Verifying root environment..." && \
159111
uv --version && \
160112
npm -v && \
161113
node -v && \
162-
echo "Installed extensions:" && \
163-
ls -la ${VSCODE_EXTENSIONS_DIR} && \
164-
echo "Git setup script:" && \
165-
ls -la /usr/local/bin/setup-git.sh && \
166114
echo "Root environment check PASSED!"
167115

168116
# Final check as CODER.
@@ -171,14 +119,8 @@ RUN echo "Verifying coder environment..." && \
171119
. ~/.bashrc && \
172120
python --version && \
173121
uv --version && \
174-
echo "Extensions directory accessible:" && \
175-
ls -l ${VSCODE_EXTENSIONS_DIR} && \
176-
echo "Code-server config:" && \
177-
cat ~/.config/code-server/config.yaml && \
122+
# Also verify that extensions are installed by checking the directory.
123+
ls -l ~/.local/share/code-server/extensions && \
178124
echo "Coder environment check PASSED!"
179125

180-
# 设置入口点
181-
USER root
182-
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
183-
184126
# The base image's CMD is inherited automatically.

0 commit comments

Comments
 (0)