Skip to content

Commit

Permalink
[Feat] ✨ Add Code-Server #1
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry-zklcdc committed Jan 15, 2025
1 parent 45089d5 commit 5aa0059
Show file tree
Hide file tree
Showing 11 changed files with 178 additions and 23 deletions.
13 changes: 10 additions & 3 deletions Dockerfile.pytorch-1.10.2_cuda-11.1_python-3.9_ubuntu-20.04
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ RUN sed -i 's/^#PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config &&
# 创建 SSH 运行时目录
RUN mkdir -p /var/run/sshd

# 安装 code-server
RUN curl -fsSL https://code-server.dev/install.sh | sh
COPY code-server.yaml /root/.config/code-server/config.yaml
COPY code-server /etc/init.d/code-server
RUN chmod +x /etc/init.d/code-server

# 安装 Prometheus Node-Exporter
RUN apt-get update && apt-get install -y --no-install-recommends prometheus prometheus-node-exporter && \
apt-get clean && rm -r /var/lib/apt/lists/*
Expand Down Expand Up @@ -96,10 +102,11 @@ RUN chown grafana:grafana /var/lib/grafana/grafana.db
RUN apt-get clean || true && \
rm -r /var/lib/apt/lists/* || true && \
conda clean -y --all || true && \
rm -r ~/.cache/pip/* || true
rm -r ~/.cache/pip/* || true && \
rm -r ~/.cache/code-server/* || true

# 暴露 Jupyter Notebook 的默认端口 8888 和 SSH 默认端口 22
EXPOSE 8888 22 3000
EXPOSE 8888 22 3000 8080

RUN echo -e 'export PATH="/usr/local/nvidia/bin:/usr/local/cuda/bin:$PATH"\nexport LANG="C.UTF-8"\n/etc/update-motd.d/10-help-text' >> /root/.bashrc

Expand All @@ -113,4 +120,4 @@ COPY .condarc /root/.condarc
RUN pip config set global.index-url https://pypi.mirrors.ustc.edu.cn/simple/

# 修改启动脚本
RUN sed -i ':a;$!{N;ba}; s|\necho\n|\necho\nrm -r /var/lib/prometheus/metrics2/*\nulimit -n 64000\nservice ssh start\nservice jupyter start\nservice prometheus start\nservice prometheus-node-exporter start\nservice nvidia_gpu_exporter start\nservice grafana-server start|' /opt/nvidia/nvidia_entrypoint.sh
RUN sed -i ':a;$!{N;ba}; s|\necho\n|\necho\nrm -r /var/lib/prometheus/metrics2/*\nulimit -n 64000\nservice ssh start\nservice jupyter start\nservice code-server start\nservice prometheus start\nservice prometheus-node-exporter start\nservice nvidia_gpu_exporter start\nservice grafana-server start|' /opt/nvidia/nvidia_entrypoint.sh
13 changes: 10 additions & 3 deletions Dockerfile.pytorch-1.13.1_cuda-11.7_python-3.10_ubuntu-22.04
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ RUN sed -i 's/^#PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config &&
# 创建 SSH 运行时目录
RUN mkdir -p /var/run/sshd

# 安装 code-server
RUN curl -fsSL https://code-server.dev/install.sh | sh
COPY code-server.yaml /root/.config/code-server/config.yaml
COPY code-server /etc/init.d/code-server
RUN chmod +x /etc/init.d/code-server

# 安装 Prometheus Node-Exporter
RUN apt-get update && apt-get install -y --no-install-recommends prometheus prometheus-node-exporter && \
apt-get clean && rm -r /var/lib/apt/lists/*
Expand Down Expand Up @@ -96,10 +102,11 @@ RUN chown grafana:grafana /var/lib/grafana/grafana.db
RUN apt-get clean || true && \
rm -r /var/lib/apt/lists/* || true && \
conda clean -y --all || true && \
rm -r ~/.cache/pip/* || true
rm -r ~/.cache/pip/* || true && \
rm -r ~/.cache/code-server/* || true

# 暴露 Jupyter Notebook 的默认端口 8888 和 SSH 默认端口 22
EXPOSE 8888 22 3000
EXPOSE 8888 22 3000 8080

RUN echo -e 'export PATH="/usr/local/nvidia/bin:/usr/local/cuda/bin:$PATH"\nexport LANG="C.UTF-8"\n/etc/update-motd.d/10-help-text' >> /root/.bashrc

Expand All @@ -113,4 +120,4 @@ COPY .condarc /root/.condarc
RUN pip config set global.index-url https://pypi.mirrors.ustc.edu.cn/simple/

# 修改启动脚本
RUN sed -i ':a;$!{N;ba}; s|\necho\n|\necho\nrm -r /var/lib/prometheus/metrics2/*\nulimit -n 64000\nservice ssh start\nservice jupyter start\nservice prometheus start\nservice prometheus-node-exporter start\nservice nvidia_gpu_exporter start\nservice grafana-server start|' /opt/nvidia/nvidia_entrypoint.sh
RUN sed -i ':a;$!{N;ba}; s|\necho\n|\necho\nrm -r /var/lib/prometheus/metrics2/*\nulimit -n 64000\nservice ssh start\nservice jupyter start\nservice code-server start\nservice prometheus start\nservice prometheus-node-exporter start\nservice nvidia_gpu_exporter start\nservice grafana-server start|' /opt/nvidia/nvidia_entrypoint.sh
13 changes: 10 additions & 3 deletions Dockerfile.pytorch-1.8.1_cuda-11.1_python-3.8_ubuntu-20.04
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ RUN sed -i 's/^#PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config &&
# 创建 SSH 运行时目录
RUN mkdir -p /var/run/sshd

# 安装 code-server
RUN curl -fsSL https://code-server.dev/install.sh | sh
COPY code-server.yaml /root/.config/code-server/config.yaml
COPY code-server /etc/init.d/code-server
RUN chmod +x /etc/init.d/code-server

# 安装 Prometheus Node-Exporter
RUN apt-get update && apt-get install -y --no-install-recommends prometheus prometheus-node-exporter && \
apt-get clean && rm -r /var/lib/apt/lists/*
Expand Down Expand Up @@ -96,10 +102,11 @@ RUN chown grafana:grafana /var/lib/grafana/grafana.db
RUN apt-get clean || true && \
rm -r /var/lib/apt/lists/* || true && \
conda clean -y --all || true && \
rm -r ~/.cache/pip/* || true
rm -r ~/.cache/pip/* || true && \
rm -r ~/.cache/code-server/* || true

# 暴露 Jupyter Notebook 的默认端口 8888 和 SSH 默认端口 22
EXPOSE 8888 22 3000
EXPOSE 8888 22 3000 8080

RUN echo -e 'export PATH="/usr/local/nvidia/bin:/usr/local/cuda/bin:$PATH"\nexport LANG="C.UTF-8"\n/etc/update-motd.d/10-help-text' >> /root/.bashrc

Expand All @@ -113,4 +120,4 @@ COPY .condarc /root/.condarc
RUN pip config set global.index-url https://pypi.mirrors.ustc.edu.cn/simple/

# 修改启动脚本
RUN sed -i ':a;$!{N;ba}; s|\necho\n|\necho\nrm -r /var/lib/prometheus/metrics2/*\nulimit -n 64000\nservice ssh start\nservice jupyter start\nservice prometheus start\nservice prometheus-node-exporter start\nservice nvidia_gpu_exporter start\nservice grafana-server start|' /opt/nvidia/nvidia_entrypoint.sh
RUN sed -i ':a;$!{N;ba}; s|\necho\n|\necho\nrm -r /var/lib/prometheus/metrics2/*\nulimit -n 64000\nservice ssh start\nservice jupyter start\nservice code-server start\nservice prometheus start\nservice prometheus-node-exporter start\nservice nvidia_gpu_exporter start\nservice grafana-server start|' /opt/nvidia/nvidia_entrypoint.sh
13 changes: 10 additions & 3 deletions Dockerfile.pytorch-2.0.1_cuda-11.8_python-3.10_ubuntu-22.04
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ RUN sed -i 's/^#PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config &&
# 创建 SSH 运行时目录
RUN mkdir -p /var/run/sshd

# 安装 code-server
RUN curl -fsSL https://code-server.dev/install.sh | sh
COPY code-server.yaml /root/.config/code-server/config.yaml
COPY code-server /etc/init.d/code-server
RUN chmod +x /etc/init.d/code-server

# 安装 Prometheus Node-Exporter
RUN apt-get update && apt-get install -y --no-install-recommends prometheus prometheus-node-exporter && \
apt-get clean && rm -r /var/lib/apt/lists/*
Expand Down Expand Up @@ -96,10 +102,11 @@ RUN chown grafana:grafana /var/lib/grafana/grafana.db
RUN apt-get clean || true && \
rm -r /var/lib/apt/lists/* || true && \
conda clean -y --all || true && \
rm -r ~/.cache/pip/* || true
rm -r ~/.cache/pip/* || true && \
rm -r ~/.cache/code-server/* || true

# 暴露 Jupyter Notebook 的默认端口 8888 和 SSH 默认端口 22
EXPOSE 8888 22 3000
EXPOSE 8888 22 3000 8080

RUN echo -e 'export PATH="/usr/local/nvidia/bin:/usr/local/cuda/bin:$PATH"\nexport LANG="C.UTF-8"\n/etc/update-motd.d/10-help-text' >> /root/.bashrc

Expand All @@ -113,4 +120,4 @@ COPY .condarc /root/.condarc
RUN pip config set global.index-url https://pypi.mirrors.ustc.edu.cn/simple/

# 修改启动脚本
RUN sed -i ':a;$!{N;ba}; s|\necho\n|\necho\nrm -r /var/lib/prometheus/metrics2/*\nulimit -n 64000\nservice ssh start\nservice jupyter start\nservice prometheus start\nservice prometheus-node-exporter start\nservice nvidia_gpu_exporter start\nservice grafana-server start|' /opt/nvidia/nvidia_entrypoint.sh
RUN sed -i ':a;$!{N;ba}; s|\necho\n|\necho\nrm -r /var/lib/prometheus/metrics2/*\nulimit -n 64000\nservice ssh start\nservice jupyter start\nservice code-server start\nservice prometheus start\nservice prometheus-node-exporter start\nservice nvidia_gpu_exporter start\nservice grafana-server start|' /opt/nvidia/nvidia_entrypoint.sh
13 changes: 10 additions & 3 deletions Dockerfile.pytorch-2.1.2_cuda-12.1_python-3.10_ubuntu-22.04
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ RUN sed -i 's/^#PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config &&
# 创建 SSH 运行时目录
RUN mkdir -p /var/run/sshd

# 安装 code-server
RUN curl -fsSL https://code-server.dev/install.sh | sh
COPY code-server.yaml /root/.config/code-server/config.yaml
COPY code-server /etc/init.d/code-server
RUN chmod +x /etc/init.d/code-server

# 安装 Prometheus Node-Exporter
RUN apt-get update && apt-get install -y --no-install-recommends prometheus prometheus-node-exporter && \
apt-get clean && rm -r /var/lib/apt/lists/*
Expand Down Expand Up @@ -97,10 +103,11 @@ RUN chown grafana:grafana /var/lib/grafana/grafana.db
RUN apt-get clean || true && \
rm -r /var/lib/apt/lists/* || true && \
conda clean -y --all || true && \
rm -r ~/.cache/pip/* || true
rm -r ~/.cache/pip/* || true && \
rm -r ~/.cache/code-server/* || true

# 暴露 Jupyter Notebook 的默认端口 8888 和 SSH 默认端口 22
EXPOSE 8888 22 3000
EXPOSE 8888 22 3000 8080

RUN echo -e 'export PATH="/usr/local/nvidia/bin:/usr/local/cuda/bin:$PATH"\nexport LANG="C.UTF-8"\n/etc/update-motd.d/10-help-text' >> /root/.bashrc

Expand All @@ -114,4 +121,4 @@ COPY .condarc /root/.condarc
RUN pip config set global.index-url https://pypi.mirrors.ustc.edu.cn/simple/

# 修改启动脚本
RUN sed -i ':a;$!{N;ba}; s|\necho\n|\necho\nrm -r /var/lib/prometheus/metrics2/*\nulimit -n 64000\nservice ssh start\nservice jupyter start\nservice prometheus start\nservice prometheus-node-exporter start\nservice nvidia_gpu_exporter start\nservice grafana-server start|' /opt/nvidia/nvidia_entrypoint.sh
RUN sed -i ':a;$!{N;ba}; s|\necho\n|\necho\nrm -r /var/lib/prometheus/metrics2/*\nulimit -n 64000\nservice ssh start\nservice jupyter start\nservice code-server start\nservice prometheus start\nservice prometheus-node-exporter start\nservice nvidia_gpu_exporter start\nservice grafana-server start|' /opt/nvidia/nvidia_entrypoint.sh
13 changes: 10 additions & 3 deletions Dockerfile.pytorch-2.3.1_cuda-12.1_python-3.11_ubuntu-22.04
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ RUN sed -i 's/^#PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config &&
# 创建 SSH 运行时目录
RUN mkdir -p /var/run/sshd

# 安装 code-server
RUN curl -fsSL https://code-server.dev/install.sh | sh
COPY code-server.yaml /root/.config/code-server/config.yaml
COPY code-server /etc/init.d/code-server
RUN chmod +x /etc/init.d/code-server

# 安装 Prometheus Node-Exporter
RUN apt-get update && apt-get install -y --no-install-recommends prometheus prometheus-node-exporter && \
apt-get clean && rm -r /var/lib/apt/lists/*
Expand Down Expand Up @@ -97,10 +103,11 @@ RUN chown grafana:grafana /var/lib/grafana/grafana.db
RUN apt-get clean || true && \
rm -r /var/lib/apt/lists/* || true && \
conda clean -y --all || true && \
rm -r ~/.cache/pip/* || true
rm -r ~/.cache/pip/* || true && \
rm -r ~/.cache/code-server/* || true

# 暴露 Jupyter Notebook 的默认端口 8888 和 SSH 默认端口 22
EXPOSE 8888 22 3000
EXPOSE 8888 22 3000 8080

RUN echo -e 'export PATH="/usr/local/nvidia/bin:/usr/local/cuda/bin:$PATH"\nexport LANG="C.UTF-8"\n/etc/update-motd.d/10-help-text' >> /root/.bashrc

Expand All @@ -114,4 +121,4 @@ COPY .condarc /root/.condarc
RUN pip config set global.index-url https://pypi.mirrors.ustc.edu.cn/simple/

# 修改启动脚本
RUN sed -i ':a;$!{N;ba}; s|\necho\n|\necho\nrm -r /var/lib/prometheus/metrics2/*\nulimit -n 64000\nservice ssh start\nservice jupyter start\nservice prometheus start\nservice prometheus-node-exporter start\nservice nvidia_gpu_exporter start\nservice grafana-server start|' /opt/nvidia/nvidia_entrypoint.sh
RUN sed -i ':a;$!{N;ba}; s|\necho\n|\necho\nrm -r /var/lib/prometheus/metrics2/*\nulimit -n 64000\nservice ssh start\nservice jupyter start\nservice code-server start\nservice prometheus start\nservice prometheus-node-exporter start\nservice nvidia_gpu_exporter start\nservice grafana-server start|' /opt/nvidia/nvidia_entrypoint.sh
13 changes: 10 additions & 3 deletions Dockerfile.pytorch-2.4.0_cuda-12.1_python-3.12_ubuntu-22.04
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ RUN sed -i 's/^#PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config &&
# 创建 SSH 运行时目录
RUN mkdir -p /var/run/sshd

# 安装 code-server
RUN curl -fsSL https://code-server.dev/install.sh | sh
COPY code-server.yaml /root/.config/code-server/config.yaml
COPY code-server /etc/init.d/code-server
RUN chmod +x /etc/init.d/code-server

# 安装 Prometheus Node-Exporter
RUN apt-get update && apt-get install -y --no-install-recommends prometheus prometheus-node-exporter && \
apt-get clean && rm -r /var/lib/apt/lists/*
Expand Down Expand Up @@ -96,10 +102,11 @@ RUN chown grafana:grafana /var/lib/grafana/grafana.db
RUN apt-get clean || true && \
rm -r /var/lib/apt/lists/* || true && \
conda clean -y --all || true && \
rm -r ~/.cache/pip/* || true
rm -r ~/.cache/pip/* || true && \
rm -r ~/.cache/code-server/* || true

# 暴露 Jupyter Notebook 的默认端口 8888 和 SSH 默认端口 22
EXPOSE 8888 22 3000
EXPOSE 8888 22 3000 8080

RUN echo -e 'export PATH="/usr/local/nvidia/bin:/usr/local/cuda/bin:$PATH"\nexport LANG="C.UTF-8"\n/etc/update-motd.d/10-help-text' >> /root/.bashrc

Expand All @@ -113,4 +120,4 @@ COPY .condarc /root/.condarc
RUN pip config set global.index-url https://pypi.mirrors.ustc.edu.cn/simple/

# 修改启动脚本
RUN sed -i ':a;$!{N;ba}; s|\necho\n|\necho\nrm -r /var/lib/prometheus/metrics2/*\nulimit -n 64000\nservice ssh start\nservice jupyter start\nservice prometheus start\nservice prometheus-node-exporter start\nservice nvidia_gpu_exporter start\nservice grafana-server start|' /opt/nvidia/nvidia_entrypoint.sh
RUN sed -i ':a;$!{N;ba}; s|\necho\n|\necho\nrm -r /var/lib/prometheus/metrics2/*\nulimit -n 64000\nservice ssh start\nservice jupyter start\nservice code-server start\nservice prometheus start\nservice prometheus-node-exporter start\nservice nvidia_gpu_exporter start\nservice grafana-server start|' /opt/nvidia/nvidia_entrypoint.sh
11 changes: 9 additions & 2 deletions Dockerfile.ubuntu-22.04
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ RUN sed -i 's/^#PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config &&
# 创建 SSH 运行时目录
RUN mkdir -p /var/run/sshd

# 安装 code-server
RUN curl -fsSL https://code-server.dev/install.sh | sh
COPY code-server.yaml /root/.config/code-server/config.yaml
COPY code-server /etc/init.d/code-server
RUN chmod +x /etc/init.d/code-server

# 安装 Prometheus Node-Exporter
RUN apt-get update && apt-get install -y --no-install-recommends prometheus prometheus-node-exporter && \
apt-get clean && rm -r /var/lib/apt/lists/*
Expand Down Expand Up @@ -87,10 +93,11 @@ RUN chown grafana:grafana /var/lib/grafana/grafana.db
RUN apt-get clean || true && \
rm -r /var/lib/apt/lists/* || true && \
conda clean -y --all || true && \
rm -r ~/.cache/pip/* || true
rm -r ~/.cache/pip/* || true && \
rm -r ~/.cache/code-server/* || true

# 暴露 Jupyter Notebook 的默认端口 8888 和 SSH 默认端口 22
EXPOSE 8888 22 3000
EXPOSE 8888 22 3000 8080

RUN echo -e 'export LANG="C.UTF-8"\n/etc/update-motd.d/10-help-text' >> /root/.bashrc

Expand Down
1 change: 1 addition & 0 deletions Ubuntu-22.04/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ service prometheus start
service prometheus-node-exporter start
service nvidia_gpu_exporter start
service grafana-server start
service code-server start

tail -f /dev/null

94 changes: 94 additions & 0 deletions code-server
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/bin/bash
### BEGIN INIT INFO
# Provides: jupyter
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Code Server service
# Description: Start and stop the Code Server server
### END INIT INFO

set -e

DESC="Code Server service"
NAME=code-server
DAEMON=/usr/bin/code-server
DAEMON_OPTS=""
PIDFILE=/run/code-server.pid
LOGFILE=/var/log/code-server.log
WORKDIR=/root/
PATH=/root/miniconda3/bin:/root/miniconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

. /lib/lsb/init-functions

start_jupyter() {
cd $WORKDIR
nohup $DAEMON $DAEMON_OPTS >> $LOGFILE 2>&1 &
echo $! > $PIDFILE
}

do_start() {
log_daemon_msg "Starting $DESC" "$NAME"
if [ -f $PIDFILE ]; then
PID=$(cat $PIDFILE)
if ps -p $PID > /dev/null && grep -q "$DAEMON" /proc/$PID/cmdline; then
log_progress_msg "Code Server is already running."
else
start_jupyter
log_end_msg 0
fi
else
start_jupyter
log_end_msg 0
fi
}

do_stop() {
log_daemon_msg "Stopping $DESC" "$NAME"
if [ -f $PIDFILE ]; then
PID=$(cat $PIDFILE)
if ps -p $PID > /dev/null && grep -q "$DAEMON" /proc/$PID/cmdline; then
kill -9 $PID
rm -f $PIDFILE
log_end_msg 0
else
log_end_msg 0
fi
# else
# log_progress_msg "Code Server is not running."
# log_end_msg 1
fi
}

do_restart() {
log_daemon_msg "Restarting $DESC" "$NAME"
do_stop
sleep 2
do_start
}

do_status() {
status_of_proc -p $PIDFILE $DAEMON $NAME && exit 0 || exit $?
}

case "$1" in
start)
do_start
;;
stop)
do_stop
;;
restart|force-reload)
do_restart
;;
status)
do_status
;;
*)
echo "Usage: $0 {start|stop|restart|force-reload|status}"
exit 1
;;
esac

exit 0
4 changes: 4 additions & 0 deletions code-server.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bind-addr: 0.0.0.0:8080
auth: password
password: CHANGETHIS
cert: false

0 comments on commit 5aa0059

Please sign in to comment.