From 4282982c2203735a2a1b12346279f9abcc2bd140 Mon Sep 17 00:00:00 2001 From: Dict Xiong Date: Tue, 3 Sep 2024 12:19:26 +0800 Subject: [PATCH] feat: add nasp-ubuntu-neo which provides cuda 12.2 --- nasp-ubuntu-neo/Dockerfile | 18 ++++++++++++++++++ nasp-ubuntu-neo/code.sh | 23 +++++++++++++++++++++++ nasp-ubuntu-neo/startup.sh | 28 ++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 nasp-ubuntu-neo/Dockerfile create mode 100755 nasp-ubuntu-neo/code.sh create mode 100755 nasp-ubuntu-neo/startup.sh diff --git a/nasp-ubuntu-neo/Dockerfile b/nasp-ubuntu-neo/Dockerfile new file mode 100644 index 0000000..745d381 --- /dev/null +++ b/nasp-ubuntu-neo/Dockerfile @@ -0,0 +1,18 @@ +FROM docker.io/nvidia/cuda:12.2.2-devel-ubuntu22.04 + +# Install dependencies +RUN ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ + && sed -i "s@http://.*archive.ubuntu.com@http://192.168.16.118/mirrors@g" /etc/apt/sources.list \ + && apt-get update -y && DEBIAN_FRONTEND=noninteractive apt-get install -yq \ + -o Acquire::BrokenProxy="true" -o Acquire::http::No-Cache="true" -o Acquire::http::Pipeline-Depth="0" \ + build-essential cmake openssh-server git-all sudo ssh sshpass pciutils \ + python3 python3-dev python3-pip curl ca-certificates vim zsh tmux bash \ + inetutils-ping less wget dialog net-tools dnsutils netcat traceroute \ + cron htop zip openssl \ + && curl -fsSL https://code-server.dev/install.sh | sh \ + && rm -rf /var/lib/apt/list/* + +# startup +COPY startup.sh /etc/startup.sh +COPY code.sh /usr/bin/code.sh +ENTRYPOINT ["/etc/startup.sh"] diff --git a/nasp-ubuntu-neo/code.sh b/nasp-ubuntu-neo/code.sh new file mode 100755 index 0000000..b896353 --- /dev/null +++ b/nasp-ubuntu-neo/code.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +set -e + +FMT_RED=$(printf '\033[31m') +FMT_GREEN=$(printf '\033[32m') +FMT_YELLOW=$(printf '\033[33m') +FMT_BLUE=$(printf '\033[34m') +FMT_BOLD=$(printf '\033[1m') +FMT_RESET=$(printf '\033[0m') + +if [[ -d /home2/run && -x $(command -v code-server) ]]; then + if ps -ef | grep -v grep | grep -q code-server; then + sockpath=$(basename $(grep "socket:" ~/.config/code-server/config.yaml | awk -F' ' '{print $2}') .sock) + password=$(grep "password:" ~/.config/code-server/config.yaml | awk -F' ' '{print $2}') + echo "${FMT_GREEN}code-server is running${FMT_RESET}" + echo "visit: https://proxy.nasp.fit/$(hostname)/$sockpath/" + echo "password: $password" + else + echo "${FMT_RED}code-server is not running${FMT_RESET}" + fi +else + echo "${FMT_RED}code-server is not set up${FMT_RESET}" +fi diff --git a/nasp-ubuntu-neo/startup.sh b/nasp-ubuntu-neo/startup.sh new file mode 100755 index 0000000..5d7e383 --- /dev/null +++ b/nasp-ubuntu-neo/startup.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +set -e + +error() { + echo $@ + return 1 +} + +/etc/init.d/ssh start || echo "Failed to start sshd. Maybe the port is already in use, and please check your sshd_config. This is not an error if it's the first time you run this container." +if [[ ! -e /root/.config/code-server/config.yaml ]]; then + mkdir -p /root/.config/code-server + sockname=$(openssl rand -hex 12) + test "${#sockname}" = "24" || error "invalid sock name: ${sockname}" + password=$(openssl rand -base64 15) + test -n "$password" || error "invalid password: ${password}" + cat << EOF > /root/.config/code-server/config.yaml +socket: /home2/run/$sockname.sock +socket-mode: 777 +auth: password +password: $password +cert: false +EOF +fi +if [[ -d /home2/run && -x $(command -v code-server) ]]; then + code-server +else + bash +fi