From e8a339ea309507a43394629c9fad46c017ef4801 Mon Sep 17 00:00:00 2001 From: Vladimir Protsenko Date: Thu, 3 Aug 2023 18:34:04 +0400 Subject: [PATCH 01/24] Vscode template --- Dockerfile | 25 ++++++++++++++++++++----- daemon.sh | 4 ---- interactively.sh | 4 ---- readme.md | 14 +++++--------- stop.sh | 4 ++++ vscode.sh | 21 +++++++++++++++++++++ 6 files changed, 50 insertions(+), 22 deletions(-) delete mode 100755 daemon.sh delete mode 100755 interactively.sh create mode 100755 stop.sh create mode 100755 vscode.sh diff --git a/Dockerfile b/Dockerfile index 3e2296e..834d3aa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,23 +1,38 @@ FROM pytorch/pytorch:2.0.0-cuda11.7-cudnn8-runtime -#FROM tensorflow/tensorflow:2.12.0-gpu +ENV TZ=Europe/Samara +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone ARG USER ARG GROUP ARG UID ARG GID +RUN apt update +RUN apt install sudo -y +RUN sed -i 's/^%sudo.*/%sudo ALL=(ALL) NOPASSWD: ALL/' /etc/sudoers + RUN groupadd --gid ${GID} ${GROUP} -RUN useradd --shell /bin/bash --uid ${UID} --gid ${GID} --create-home ${USER} +RUN useradd --shell /bin/bash --uid ${UID} --gid ${GID} -G sudo --create-home ${USER} RUN mkdir /wd RUN chown ${USER}:${GROUP} /wd -# SYSTEM INITIALIZATION -# RUN pip install jupyter +# SYSTEM CONFIGURATION +RUN apt install vim htop mc curl wget git tree -y +RUN curl -fsSL https://code-server.dev/install.sh | sh +RUN code-server --install-extension ms-python.python + USER ${USER} -# USER INITIALIZATION +# USER CONFIGURATION # RUN ... +RUN openssl req -x509 -newkey rsa:4096 -keyout /home/${USER}/key.pem -out /home/${USER}/cert.pem -sha256 -nodes -days 365 -subj "/C=RU/ST=SamaraRegion/L=Samara/O=SSAU/OU=LIAV/CN=vscode.ssau.ru/" +RUN mkdir -p /home/${USER}/.config/code-server +RUN echo 'bind-addr: 0.0.0.0:8443' >> /home/${USER}/.config/code-server/config.yaml +RUN echo "cert: /home/${USER}/cert.pem" >> /home/${USER}/.config/code-server/config.yaml +RUN echo "cert-key: /home/${USER}/key.pem" >> /home/${USER}/.config/code-server/config.yaml + +ENV SHELL=/bin/bash SHELL ["/bin/bash", "--login", "-i", "-c"] WORKDIR /wd diff --git a/daemon.sh b/daemon.sh deleted file mode 100755 index 6e8d780..0000000 --- a/daemon.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -CURDIRNAME=${PWD##*/} - -docker run -d --gpus "device=0" -p 8888:8888 -v $(pwd):/wd --name ${USER}_${CURDIRNAME} ${USER}_${CURDIRNAME} \ No newline at end of file diff --git a/interactively.sh b/interactively.sh deleted file mode 100755 index 8f5e83e..0000000 --- a/interactively.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -CURDIRNAME=${PWD##*/} - -docker run -it --rm --gpus "device=0" -p 8888:8888 -v $(pwd):/wd --name ${USER}_${CURDIRNAME} ${USER}_${CURDIRNAME} \ No newline at end of file diff --git a/readme.md b/readme.md index aecffe7..9bee5c4 100644 --- a/readme.md +++ b/readme.md @@ -1,14 +1,10 @@ - -``` -git clone https://git.ai.ssau.ru/liav/docker_template myproject -cd myproject -``` -Модифицируйте `Dockerfile` для выбора базового образа из https://hub.docker.com/ и установки зависимостей. Отредактируйте .dockerfile, если хотите скопировать файлы в образ командой COPY (по-умолчанию файлы не отправляются в контекст для ускорения сборки). +Для запуска vscode на сервере скопируйте в терминал и запустите: ``` -./build.sh -./start_daemon.sh или ./start_interactively.sh +git clone https://git.ai.ssau.ru/liav/docker_template --branch vscode my_project_name; ./build.sh; ./vscode.sh ``` ------------------------------------ + При использовании этой схемы будет получен контейнер с пользователем, идентичным пользователю в `host` системе. Новые файлы (логи/модели etm.) и процессы в диспетчере процессов (top/htop) хоста будут принадлежать вашему пользователю. Параметр `-v $(pwd):/wd ` в `start` скриптах означает, что директория `/wd` в контейнере будет связана с текущей папкой на хосте. + +Для остановки vscode используйте `./stop.sh`. diff --git a/stop.sh b/stop.sh new file mode 100755 index 0000000..c81688e --- /dev/null +++ b/stop.sh @@ -0,0 +1,4 @@ +#!/bin/bash +CURDIRNAME=${PWD##*/} + +docker stop ${USER}_${CURDIRNAME}_vscode diff --git a/vscode.sh b/vscode.sh new file mode 100755 index 0000000..fad597a --- /dev/null +++ b/vscode.sh @@ -0,0 +1,21 @@ +#!/bin/bash +CURDIRNAME=${PWD##*/} + +PORT=8400 +PASSWORD=$(openssl rand -base64 45) +docker run \ + -d \ + --rm \ + --gpus "device=0" \ + -p $PORT:8443 \ + -v $(pwd):/wd \ + --shm-size=10gb \ + --name ${USER}_${CURDIRNAME}_vscode \ + -e PASSWORD="${PASSWORD}" \ + ${USER}_${CURDIRNAME} \ + code-server +sleep 1 +docker logs ${USER}_${CURDIRNAME}_vscode +echo "" +echo "Address: https://$(hostname -i | awk '{ print $1; }'):${PORT}" +echo "Password: $PASSWORD" From 26e96b0189689756dfc737ad145c6b99c8ec9b97 Mon Sep 17 00:00:00 2001 From: Vladimir Protsenko Date: Thu, 3 Aug 2023 18:36:45 +0400 Subject: [PATCH 02/24] Vscode template --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 9bee5c4..f68b66d 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,6 @@ Для запуска vscode на сервере скопируйте в терминал и запустите: ``` -git clone https://git.ai.ssau.ru/liav/docker_template --branch vscode my_project_name; ./build.sh; ./vscode.sh +PROJECT=myprojectname; git clone https://git.ai.ssau.ru/liav/docker_template --branch vscode $PROJECT; cd $PROJECT; ./build.sh; ./vscode.sh ``` При использовании этой схемы будет получен контейнер с пользователем, идентичным пользователю в `host` системе. Новые файлы (логи/модели etm.) и процессы в диспетчере процессов (top/htop) хоста будут принадлежать вашему пользователю. From bed15d8e6b0aaa5399be53ba8c81816702d45189 Mon Sep 17 00:00:00 2001 From: Vladimir Protsenko Date: Thu, 3 Aug 2023 19:02:10 +0400 Subject: [PATCH 03/24] Vscode template --- readme.md | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.md b/readme.md index f68b66d..5eccd81 100644 --- a/readme.md +++ b/readme.md @@ -2,6 +2,7 @@ ``` PROJECT=myprojectname; git clone https://git.ai.ssau.ru/liav/docker_template --branch vscode $PROJECT; cd $PROJECT; ./build.sh; ./vscode.sh ``` +Если порт занят, поменяйте его в скрипте `vscode.sh` и запустите `./vscode.sh` заново. При использовании этой схемы будет получен контейнер с пользователем, идентичным пользователю в `host` системе. Новые файлы (логи/модели etm.) и процессы в диспетчере процессов (top/htop) хоста будут принадлежать вашему пользователю. From ac8f3b2e5a256df63a7a79441a8d38c35f80f3c9 Mon Sep 17 00:00:00 2001 From: Vladimir Protsenko Date: Thu, 3 Aug 2023 19:51:15 +0400 Subject: [PATCH 04/24] Vscode template --- readme.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/readme.md b/readme.md index 5eccd81..a52d1b5 100644 --- a/readme.md +++ b/readme.md @@ -9,3 +9,26 @@ PROJECT=myprojectname; git clone https://git.ai.ssau.ru/liav/docker_template --b Параметр `-v $(pwd):/wd ` в `start` скриптах означает, что директория `/wd` в контейнере будет связана с текущей папкой на хосте. Для остановки vscode используйте `./stop.sh`. + + + +Настроить рабочее окружение в контейнере можно либо классическим способом внутри контейнера, либо в более воспроизводимом ключе по шагам: + +1. Скачивание шаблона в новую папку с названием `myprojectname`, переход в неё по завершению +``` +PROJECT=myprojectname; git clone https://git.ai.ssau.ru/liav/docker_template --branch vscode $PROJECT; cd $PROJECT +``` + +2. Редактирование Dockerfile для смены базового образа, установки ПО и настройки среды образа. + +3. Выполнение построения образа/отладка процесса +``` +./build.sh +``` + +4. Редактирование аргументов запуска контейнера на основе образа: + - изменение номера/добавление доступных ГПУ в запускаемом контейнере ('--gpus' аргумент), + - изменение порта для vscode ('-p' аргумент), + - добавление папок хост системы, доступных из контейнера ('-v' аргумент). + +5. Запуск контейнера `./vscode.sh`. From 8838f0eae9ea898fe060de2c8dd59f4434beb396 Mon Sep 17 00:00:00 2001 From: Vladimir Protsenko Date: Thu, 3 Aug 2023 19:52:48 +0400 Subject: [PATCH 05/24] Vscode template --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index a52d1b5..8c122ea 100644 --- a/readme.md +++ b/readme.md @@ -12,7 +12,7 @@ PROJECT=myprojectname; git clone https://git.ai.ssau.ru/liav/docker_template --b -Настроить рабочее окружение в контейнере можно либо классическим способом внутри контейнера, либо в более воспроизводимом ключе по шагам: +Настроить рабочее окружение в контейнере можно либо классическим способом внутри контейнера, с возможностью эскалации прав до root командой `sudo`. Либо в более воспроизводимом ключе по шагам: 1. Скачивание шаблона в новую папку с названием `myprojectname`, переход в неё по завершению ``` From 002c231acc9623c95c31f6e802243a7cbf2375ba Mon Sep 17 00:00:00 2001 From: Vladimir Protsenko Date: Thu, 3 Aug 2023 19:53:34 +0400 Subject: [PATCH 06/24] Vscode template --- readme.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 8c122ea..4246772 100644 --- a/readme.md +++ b/readme.md @@ -31,4 +31,7 @@ PROJECT=myprojectname; git clone https://git.ai.ssau.ru/liav/docker_template --b - изменение порта для vscode ('-p' аргумент), - добавление папок хост системы, доступных из контейнера ('-v' аргумент). -5. Запуск контейнера `./vscode.sh`. +5. Запуск контейнера +``` +./vscode.sh +``` From 493febf4b5174b2d4beac92c0e9712ab7319b6d4 Mon Sep 17 00:00:00 2001 From: Vladimir Protsenko Date: Thu, 3 Aug 2023 19:57:21 +0400 Subject: [PATCH 07/24] Vscode template --- readme.md | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/readme.md b/readme.md index 4246772..31cb835 100644 --- a/readme.md +++ b/readme.md @@ -4,12 +4,7 @@ PROJECT=myprojectname; git clone https://git.ai.ssau.ru/liav/docker_template --b ``` Если порт занят, поменяйте его в скрипте `vscode.sh` и запустите `./vscode.sh` заново. -При использовании этой схемы будет получен контейнер с пользователем, идентичным пользователю в `host` системе. Новые файлы (логи/модели etm.) и процессы в диспетчере процессов (top/htop) хоста будут принадлежать вашему пользователю. - -Параметр `-v $(pwd):/wd ` в `start` скриптах означает, что директория `/wd` в контейнере будет связана с текущей папкой на хосте. - -Для остановки vscode используйте `./stop.sh`. - +При использовании этой схемы будет получен контейнер с пользователем, идентичным пользователю в `host` системе. Новые файлы (логи/модели etm.) и процессы в диспетчере процессов (top/htop) хоста будут принадлежать вашему пользователю. Параметр `-v $(pwd):/wd ` в `start` скриптах означает, что директория `/wd` в контейнере будет связана с текущей папкой на хосте. Настроить рабочее окружение в контейнере можно либо классическим способом внутри контейнера, с возможностью эскалации прав до root командой `sudo`. Либо в более воспроизводимом ключе по шагам: @@ -35,3 +30,5 @@ PROJECT=myprojectname; git clone https://git.ai.ssau.ru/liav/docker_template --b ``` ./vscode.sh ``` + +Для остановки vscode используйте `./stop.sh`. From bd0fd0b4100d2c1c8c7d983add132a6ff65216f6 Mon Sep 17 00:00:00 2001 From: Vladimir Protsenko Date: Thu, 3 Aug 2023 19:59:53 +0400 Subject: [PATCH 08/24] Vscode template --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 31cb835..3b2c158 100644 --- a/readme.md +++ b/readme.md @@ -16,7 +16,7 @@ PROJECT=myprojectname; git clone https://git.ai.ssau.ru/liav/docker_template --b 2. Редактирование Dockerfile для смены базового образа, установки ПО и настройки среды образа. -3. Выполнение построения образа/отладка процесса +3. Выполнение построения образа/отладка процесса построения ``` ./build.sh ``` From f71f16dc01fbd88eed830702798500979bd7f8ec Mon Sep 17 00:00:00 2001 From: Vladimir Protsenko Date: Thu, 3 Aug 2023 20:01:23 +0400 Subject: [PATCH 09/24] Vscode template --- readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 3b2c158..c006a09 100644 --- a/readme.md +++ b/readme.md @@ -21,12 +21,12 @@ PROJECT=myprojectname; git clone https://git.ai.ssau.ru/liav/docker_template --b ./build.sh ``` -4. Редактирование аргументов запуска контейнера на основе образа: +4. Редактирование аргументов запуска контейнера: - изменение номера/добавление доступных ГПУ в запускаемом контейнере ('--gpus' аргумент), - изменение порта для vscode ('-p' аргумент), - добавление папок хост системы, доступных из контейнера ('-v' аргумент). -5. Запуск контейнера +5. Запуск контейнера на основе построенного образа ``` ./vscode.sh ``` From b2593abf48ccdbc455df519956fb05877037a258 Mon Sep 17 00:00:00 2001 From: Vladimir Protsenko Date: Thu, 3 Aug 2023 20:02:29 +0400 Subject: [PATCH 10/24] Vscode template --- readme.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/readme.md b/readme.md index c006a09..cba5166 100644 --- a/readme.md +++ b/readme.md @@ -22,9 +22,9 @@ PROJECT=myprojectname; git clone https://git.ai.ssau.ru/liav/docker_template --b ``` 4. Редактирование аргументов запуска контейнера: - - изменение номера/добавление доступных ГПУ в запускаемом контейнере ('--gpus' аргумент), - - изменение порта для vscode ('-p' аргумент), - - добавление папок хост системы, доступных из контейнера ('-v' аргумент). + - изменение номера/добавление доступных ГПУ в запускаемом контейнере (`--gpus` аргумент), + - изменение порта для vscode (`-p` аргумент), + - добавление папок хост системы, доступных из контейнера (`-v` аргумент). 5. Запуск контейнера на основе построенного образа ``` From 0c520df93f51f8f6a502c82d621704e2104b51d2 Mon Sep 17 00:00:00 2001 From: Vladimir Protsenko Date: Thu, 17 Aug 2023 22:47:11 +0400 Subject: [PATCH 11/24] Install python extension for user, not for root. --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 834d3aa..d9b3f7d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,13 +19,13 @@ RUN chown ${USER}:${GROUP} /wd # SYSTEM CONFIGURATION RUN apt install vim htop mc curl wget git tree -y RUN curl -fsSL https://code-server.dev/install.sh | sh -RUN code-server --install-extension ms-python.python USER ${USER} # USER CONFIGURATION # RUN ... +RUN code-server --install-extension ms-python.python RUN openssl req -x509 -newkey rsa:4096 -keyout /home/${USER}/key.pem -out /home/${USER}/cert.pem -sha256 -nodes -days 365 -subj "/C=RU/ST=SamaraRegion/L=Samara/O=SSAU/OU=LIAV/CN=vscode.ssau.ru/" RUN mkdir -p /home/${USER}/.config/code-server From 867ddf9a6ec17b1bc015be35cba4beb06b1fcbfc Mon Sep 17 00:00:00 2001 From: Vladimir Protsenko Date: Thu, 17 Aug 2023 22:56:31 +0400 Subject: [PATCH 12/24] Install ipykernel for conda base environment. --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index d9b3f7d..8a76e8b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,7 +19,7 @@ RUN chown ${USER}:${GROUP} /wd # SYSTEM CONFIGURATION RUN apt install vim htop mc curl wget git tree -y RUN curl -fsSL https://code-server.dev/install.sh | sh - +RUN /opt/conda/bin/conda install -n base ipykernel --update-deps --force-reinstall -y USER ${USER} From a360d0c3df46c0c5ec68b84366318b972a9fa4de Mon Sep 17 00:00:00 2001 From: Vladimir Protsenko Date: Fri, 18 Aug 2023 13:10:38 +0400 Subject: [PATCH 13/24] Fix bug with dup config strings. --- Dockerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8a76e8b..640026c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,7 +25,6 @@ USER ${USER} # USER CONFIGURATION # RUN ... -RUN code-server --install-extension ms-python.python RUN openssl req -x509 -newkey rsa:4096 -keyout /home/${USER}/key.pem -out /home/${USER}/cert.pem -sha256 -nodes -days 365 -subj "/C=RU/ST=SamaraRegion/L=Samara/O=SSAU/OU=LIAV/CN=vscode.ssau.ru/" RUN mkdir -p /home/${USER}/.config/code-server @@ -33,6 +32,8 @@ RUN echo 'bind-addr: 0.0.0.0:8443' >> /home/${USER}/.config/code-server/config.y RUN echo "cert: /home/${USER}/cert.pem" >> /home/${USER}/.config/code-server/config.yaml RUN echo "cert-key: /home/${USER}/key.pem" >> /home/${USER}/.config/code-server/config.yaml +RUN code-server --install-extension ms-python.python + ENV SHELL=/bin/bash SHELL ["/bin/bash", "--login", "-i", "-c"] -WORKDIR /wd +WORKDIR /wd \ No newline at end of file From c1262a932bccd63f6b7a8fa8561cae650cfd7c73 Mon Sep 17 00:00:00 2001 From: Vladimir Protsenko Date: Fri, 18 Aug 2023 13:11:26 +0400 Subject: [PATCH 14/24] Fix image name --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index e276c02..7796d61 100755 --- a/build.sh +++ b/build.sh @@ -1,7 +1,7 @@ #!/bin/bash CURDIRNAME=${PWD##*/} -docker build . -t ${USER}_${CURDIRNAME} \ +docker build . -t ${USER}_${CURDIRNAME}_vscode \ --build-arg USER=${USER} \ --build-arg GROUP=${USER} \ --build-arg UID=$(id -u ${USER}) \ From d0b2d5d8337678be5e7c042f54e53d0d7917449e Mon Sep 17 00:00:00 2001 From: Vladimir Protsenko Date: Fri, 18 Aug 2023 13:12:01 +0400 Subject: [PATCH 15/24] Fix image name --- vscode.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vscode.sh b/vscode.sh index fad597a..1b4f8ea 100755 --- a/vscode.sh +++ b/vscode.sh @@ -12,7 +12,7 @@ docker run \ --shm-size=10gb \ --name ${USER}_${CURDIRNAME}_vscode \ -e PASSWORD="${PASSWORD}" \ - ${USER}_${CURDIRNAME} \ + ${USER}_${CURDIRNAME}_vscode \ code-server sleep 1 docker logs ${USER}_${CURDIRNAME}_vscode From b7ef654c515cf9b1bcc4b0f7e0e3cfd02adbd42c Mon Sep 17 00:00:00 2001 From: Vladimir Protsenko Date: Sun, 27 Aug 2023 12:11:34 +0400 Subject: [PATCH 16/24] cheburnet version of vscode install script --- code_server_install.sh | 618 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 618 insertions(+) create mode 100644 code_server_install.sh diff --git a/code_server_install.sh b/code_server_install.sh new file mode 100644 index 0000000..7984460 --- /dev/null +++ b/code_server_install.sh @@ -0,0 +1,618 @@ +#!/bin/sh +set -eu + +# code-server's automatic install script. +# See https://coder.com/docs/code-server/latest/install + +usage() { + arg0="$0" + if [ "$0" = sh ]; then + arg0="curl -fsSL https://code-server.dev/install.sh | sh -s --" + else + not_curl_usage="The latest script is available at https://code-server.dev/install.sh +" + fi + + cath << EOF +Installs code-server. +It tries to use the system package manager if possible. +After successful installation it explains how to start using code-server. + +Pass in user@host to install code-server on user@host over ssh. +The remote host must have internet access. +${not_curl_usage-} +Usage: + + $arg0 [--dry-run] [--version X.X.X] [--edge] [--method detect] \ + [--prefix ~/.local] [--rsh ssh] [user@host] + + --dry-run + Echo the commands for the install process without running them. + + --version X.X.X + Install a specific version instead of the latest. + + --edge + Install the latest edge version instead of the latest stable version. + + --method [detect | standalone] + Choose the installation method. Defaults to detect. + - detect detects the system package manager and tries to use it. + Full reference on the process is further below. + - standalone installs a standalone release archive into ~/.local + Add ~/.local/bin to your \$PATH to use it. + + --prefix + Sets the prefix used by standalone release archives. Defaults to ~/.local + The release is unarchived into ~/.local/lib/code-server-X.X.X + and the binary symlinked into ~/.local/bin/code-server + To install system wide pass --prefix=/usr/local + + --rsh + Specifies the remote shell for remote installation. Defaults to ssh. + +The detection method works as follows: + - Debian, Ubuntu, Raspbian: install the deb package from GitHub. + - Fedora, CentOS, RHEL, openSUSE: install the rpm package from GitHub. + - Arch Linux: install from the AUR (which pulls releases from GitHub). + - FreeBSD, Alpine: install from npm. + - macOS: install using Homebrew if installed otherwise install from GitHub. + - All others: install the release from GitHub. + +We only build releases on GitHub for amd64 and arm64 on Linux and amd64 for +macOS. When the detection method tries to pull a release from GitHub it will +fall back to installing from npm when there is no matching release for the +system's operating system and architecture. + +The standalone method will force installion using GitHub releases. It will not +fall back to npm so on architectures without pre-built releases this will error. + +The installer will cache all downloaded assets into ~/.cache/code-server + +More installation docs are at https://coder.com/docs/code-server/latest/install +EOF +} + +echo_latest_version() { + if [ "${EDGE-}" ]; then + version="$(curl -fsSL https://api.github.com/repos/coder/code-server/releases | awk 'match($0,/.*"html_url": "(.*\/releases\/tag\/.*)".*/)' | head -n 1 | awk -F '"' '{print $4}')" + else + # https://gist.github.com/lukechilds/a83e1d7127b78fef38c2914c4ececc3c#gistcomment-2758860 + version="$(curl -fsSLI -o /dev/null -w "%{url_effective}" https://github.com/coder/code-server/releases/latest)" + fi + version="${version#https://github.com/coder/code-server/releases/tag/}" + version="${version#v}" + echo "$version" +} + +echo_npm_postinstall() { + echoh + cath << EOF +npm package has been installed. + +Extend your path to use code-server: + PATH="$NPM_BIN_DIR:\$PATH" +Then run with: + code-server +EOF +} + +echo_standalone_postinstall() { + echoh + cath << EOF +Standalone release has been installed into $STANDALONE_INSTALL_PREFIX/lib/code-server-$VERSION + +Extend your path to use code-server: + PATH="$STANDALONE_INSTALL_PREFIX/bin:\$PATH" +Then run with: + code-server +EOF +} + +echo_brew_postinstall() { + echoh + cath << EOF +Brew release has been installed. + +Run with: + code-server +EOF +} + +echo_systemd_postinstall() { + echoh + cath << EOF +$1 package has been installed. + +To have systemd start code-server now and restart on boot: + sudo systemctl enable --now code-server@\$USER +Or, if you don't want/need a background service you can run: + code-server +EOF +} + +echo_coder_postinstall() { + echoh + echoh "Deploy code-server for your team with Coder: https://github.com/coder/coder" +} + +main() { + if [ "${TRACE-}" ]; then + set -x + fi + + unset \ + DRY_RUN \ + METHOD \ + OPTIONAL \ + ALL_FLAGS \ + RSH_ARGS \ + EDGE \ + RSH + + ALL_FLAGS="" + while [ "$#" -gt 0 ]; do + case "$1" in + -*) + ALL_FLAGS="${ALL_FLAGS} $1" + ;; + esac + + case "$1" in + --dry-run) + DRY_RUN=1 + ;; + --method) + METHOD="$(parse_arg "$@")" + shift + ;; + --method=*) + METHOD="$(parse_arg "$@")" + ;; + --prefix) + STANDALONE_INSTALL_PREFIX="$(parse_arg "$@")" + shift + ;; + --prefix=*) + STANDALONE_INSTALL_PREFIX="$(parse_arg "$@")" + ;; + --version) + VERSION="$(parse_arg "$@")" + shift + ;; + --version=*) + VERSION="$(parse_arg "$@")" + ;; + --edge) + EDGE=1 + ;; + --rsh) + RSH="$(parse_arg "$@")" + shift + ;; + --rsh=*) + RSH="$(parse_arg "$@")" + ;; + -h | --h | -help | --help) + usage + exit 0 + ;; + --) + shift + # We remove the -- added above. + ALL_FLAGS="${ALL_FLAGS% --}" + RSH_ARGS="$*" + break + ;; + -*) + echoerr "Unknown flag $1" + echoerr "Run with --help to see usage." + exit 1 + ;; + *) + RSH_ARGS="$*" + break + ;; + esac + + shift + done + + if [ "${RSH_ARGS-}" ]; then + RSH="${RSH-ssh}" + echoh "Installing remotely with $RSH $RSH_ARGS" + curl -fsSL https://code-server.dev/install.sh | prefix "$RSH_ARGS" "$RSH" "$RSH_ARGS" sh -s -- "$ALL_FLAGS" + return + fi + + METHOD="${METHOD-detect}" + if [ "$METHOD" != detect ] && [ "$METHOD" != standalone ]; then + echoerr "Unknown install method \"$METHOD\"" + echoerr "Run with --help to see usage." + exit 1 + fi + + # These are used by the various install_* functions that make use of GitHub + # releases in order to download and unpack the right release. + CACHE_DIR=$(echo_cache_dir) + STANDALONE_INSTALL_PREFIX=${STANDALONE_INSTALL_PREFIX:-$HOME/.local} + VERSION=${VERSION:-$(echo_latest_version)} + # These can be overridden for testing but shouldn't normally be used as it can + # result in a broken code-server. + OS=${OS:-$(os)} + ARCH=${ARCH:-$(arch)} + + distro_name + + # Standalone installs by pulling pre-built releases from GitHub. + if [ "$METHOD" = standalone ]; then + if has_standalone; then + install_standalone + echo_coder_postinstall + exit 0 + else + echoerr "There are no standalone releases for $ARCH" + echoerr "Please try again without '--method standalone'" + exit 1 + fi + fi + + # DISTRO can be overridden for testing but shouldn't normally be used as it + # can result in a broken code-server. + DISTRO=${DISTRO:-$(distro)} + + case $DISTRO in + # macOS uses brew when available and falls back to standalone. We only have + # amd64 for macOS so for anything else use npm. + macos) + BREW_PATH="${BREW_PATH-brew}" + if command_exists "$BREW_PATH"; then + install_brew + else + echoh "Homebrew not installed." + echoh "Falling back to standalone installation." + npm_fallback install_standalone + fi + ;; + # The .deb and .rpm files are pulled from GitHub and we only have amd64 and + # arm64 there and need to fall back to npm otherwise. + debian) npm_fallback install_deb ;; + fedora | opensuse) npm_fallback install_rpm ;; + # Arch uses the AUR package which only supports amd64 and arm64 since it + # pulls releases from GitHub so we need to fall back to npm. + arch) npm_fallback install_aur ;; + # We don't have GitHub releases that work on Alpine or FreeBSD so we have no + # choice but to use npm here. + alpine | freebsd) install_npm ;; + # For anything else we'll try to install standalone but fall back to npm if + # we don't have releases for the architecture. + *) + echoh "Unsupported package manager." + echoh "Falling back to standalone installation." + npm_fallback install_standalone + ;; + esac + + echo_coder_postinstall +} + +parse_arg() { + case "$1" in + *=*) + # Remove everything after first equal sign. + opt="${1%%=*}" + # Remove everything before first equal sign. + optarg="${1#*=}" + if [ ! "$optarg" ] && [ ! "${OPTIONAL-}" ]; then + echoerr "$opt requires an argument" + echoerr "Run with --help to see usage." + exit 1 + fi + echo "$optarg" + return + ;; + esac + + case "${2-}" in + "" | -*) + if [ ! "${OPTIONAL-}" ]; then + echoerr "$1 requires an argument" + echoerr "Run with --help to see usage." + exit 1 + fi + ;; + *) + echo "$2" + return + ;; + esac +} + +fetch() { + URL="$1" + FILE="$2" + + if [ -e "$FILE" ]; then + echoh "+ Reusing $FILE" + return + fi + + sh_c mkdir -p "$CACHE_DIR" + sh_c curl \ + -#fL \ + -o "$FILE.incomplete" \ + -C - \ + "$URL" + sh_c mv "$FILE.incomplete" "$FILE" +} + +install_brew() { + echoh "Installing latest from Homebrew." + echoh + + sh_c "$BREW_PATH" install code-server + + echo_brew_postinstall +} + +install_deb() { + echoh "Installing v$VERSION of the $ARCH deb package from GitHub." + echoh + + fetch "https://github.com/coder/code-server/releases/download/v$VERSION/code-server_${VERSION}_$ARCH.deb" \ + "$CACHE_DIR/code-server_${VERSION}_$ARCH.deb" + sudo_sh_c dpkg -i "$CACHE_DIR/code-server_${VERSION}_$ARCH.deb" + + echo_systemd_postinstall deb +} + +install_rpm() { + echoh "Installing v$VERSION of the $ARCH rpm package from GitHub." + echoh + + fetch "https://github.com/coder/code-server/releases/download/v$VERSION/code-server-$VERSION-$ARCH.rpm" \ + "$CACHE_DIR/code-server-$VERSION-$ARCH.rpm" + sudo_sh_c rpm -U "$CACHE_DIR/code-server-$VERSION-$ARCH.rpm" + + echo_systemd_postinstall rpm +} + +install_aur() { + echoh "Installing latest from the AUR." + echoh + + sh_c mkdir -p "$CACHE_DIR/code-server-aur" + sh_c "curl -#fsSL https://aur.archlinux.org/cgit/aur.git/snapshot/code-server.tar.gz | tar -xzC $CACHE_DIR/code-server-aur --strip-components 1" + echo "+ cd $CACHE_DIR/code-server-aur" + if [ ! "${DRY_RUN-}" ]; then + cd "$CACHE_DIR/code-server-aur" + fi + sh_c makepkg -si --noconfirm + + echo_systemd_postinstall AUR +} + +install_standalone() { + echoh "Installing v$VERSION of the $ARCH release from GitHub." + echoh + + fetch "https://github.com/coder/code-server/releases/download/v$VERSION/code-server-$VERSION-$OS-$ARCH.tar.gz" \ + "$CACHE_DIR/code-server-$VERSION-$OS-$ARCH.tar.gz" + + # -w only works if the directory exists so try creating it first. If this + # fails we can ignore the error as the -w check will then swap us to sudo. + sh_c mkdir -p "$STANDALONE_INSTALL_PREFIX" 2> /dev/null || true + + sh_c="sh_c" + if [ ! -w "$STANDALONE_INSTALL_PREFIX" ]; then + sh_c="sudo_sh_c" + fi + + if [ -e "$STANDALONE_INSTALL_PREFIX/lib/code-server-$VERSION" ]; then + echoh + echoh "code-server-$VERSION is already installed at $STANDALONE_INSTALL_PREFIX/lib/code-server-$VERSION" + echoh "Remove it to reinstall." + exit 0 + fi + + "$sh_c" mkdir -p "$STANDALONE_INSTALL_PREFIX/lib" "$STANDALONE_INSTALL_PREFIX/bin" + "$sh_c" tar -C "$STANDALONE_INSTALL_PREFIX/lib" -xzf "$CACHE_DIR/code-server-$VERSION-$OS-$ARCH.tar.gz" + "$sh_c" mv -f "$STANDALONE_INSTALL_PREFIX/lib/code-server-$VERSION-$OS-$ARCH" "$STANDALONE_INSTALL_PREFIX/lib/code-server-$VERSION" + "$sh_c" ln -fs "$STANDALONE_INSTALL_PREFIX/lib/code-server-$VERSION/bin/code-server" "$STANDALONE_INSTALL_PREFIX/bin/code-server" + + echo_standalone_postinstall +} + +install_npm() { + echoh "Installing latest from npm." + echoh + + NPM_PATH="${YARN_PATH-npm}" + + if command_exists "$NPM_PATH"; then + sh_c="sh_c" + if [ ! "${DRY_RUN-}" ] && [ ! -w "$(NPM_PATH config get prefix)" ]; then + sh_c="sudo_sh_c" + fi + echoh "Installing with npm." + echoh + "$sh_c" "$NPM_PATH" install -g code-server --unsafe-perm + NPM_BIN_DIR="\$($NPM_PATH bin -g)" echo_npm_postinstall + return + fi + echoerr "Please install npm to install code-server!" + echoerr "You will need at least node v12 and a few C dependencies." + echoerr "See the docs https://coder.com/docs/code-server/latest/install#npm" + + exit 1 +} + +# Run $1 if we have a standalone otherwise run install_npm. +npm_fallback() { + if has_standalone; then + $1 + else + echoh "No standalone releases for $ARCH." + echoh "Falling back to installation from npm." + install_npm + fi +} + +# Determine if we have standalone releases on GitHub for the system's arch. +has_standalone() { + case $ARCH in + amd64) return 0 ;; + # We only have amd64 for macOS. + arm64) + [ "$(distro)" != macos ] + return + ;; + *) return 1 ;; + esac +} + +os() { + uname="$(uname)" + case $uname in + Linux) echo linux ;; + Darwin) echo macos ;; + FreeBSD) echo freebsd ;; + *) echo "$uname" ;; + esac +} + +# Print the detected Linux distro, otherwise print the OS name. +# +# Example outputs: +# - macos -> macos +# - freebsd -> freebsd +# - ubuntu, raspbian, debian ... -> debian +# - amzn, centos, rhel, fedora, ... -> fedora +# - opensuse-{leap,tumbleweed} -> opensuse +# - alpine -> alpine +# - arch, manjaro, endeavouros, ... -> arch +# +# Inspired by https://github.com/docker/docker-install/blob/26ff363bcf3b3f5a00498ac43694bf1c7d9ce16c/install.sh#L111-L120. +distro() { + if [ "$OS" = "macos" ] || [ "$OS" = "freebsd" ]; then + echo "$OS" + return + fi + + if [ -f /etc/os-release ]; then + ( + . /etc/os-release + if [ "${ID_LIKE-}" ]; then + for id_like in $ID_LIKE; do + case "$id_like" in debian | fedora | opensuse | arch) + echo "$id_like" + return + ;; + esac + done + fi + + echo "$ID" + ) + return + fi +} + +# Print a human-readable name for the OS/distro. +distro_name() { + if [ "$(uname)" = "Darwin" ]; then + echo "macOS v$(sw_vers -productVersion)" + return + fi + + if [ -f /etc/os-release ]; then + ( + . /etc/os-release + echo "$PRETTY_NAME" + ) + return + fi + + # Prints something like: Linux 4.19.0-9-amd64 + uname -sr +} + +arch() { + uname_m=$(uname -m) + case $uname_m in + aarch64) echo arm64 ;; + x86_64) echo amd64 ;; + *) echo "$uname_m" ;; + esac +} + +command_exists() { + if [ ! "$1" ]; then return 1; fi + command -v "$@" > /dev/null +} + +sh_c() { + echoh "+ $*" + if [ ! "${DRY_RUN-}" ]; then + sh -c "$*" + fi +} + +sudo_sh_c() { + if [ "$(id -u)" = 0 ]; then + sh_c "$@" + elif command_exists doas; then + sh_c "doas $*" + elif command_exists sudo; then + sh_c "sudo $*" + elif command_exists su; then + sh_c "su root -c '$*'" + else + echoh + echoerr "This script needs to run the following command as root." + echoerr " $*" + echoerr "Please install doas, sudo, or su." + exit 1 + fi +} + +echo_cache_dir() { + if [ "${XDG_CACHE_HOME-}" ]; then + echo "$XDG_CACHE_HOME/code-server" + elif [ "${HOME-}" ]; then + echo "$HOME/.cache/code-server" + else + echo "/tmp/code-server-cache" + fi +} + +echoh() { + echo "$@" | humanpath +} + +cath() { + humanpath +} + +echoerr() { + echoh "$@" >&2 +} + +# humanpath replaces all occurrences of " $HOME" with " ~" +# and all occurrences of '"$HOME' with the literal '"$HOME'. +humanpath() { + sed "s# $HOME# ~#g; s#\"$HOME#\"\$HOME#g" +} + +# We need to make sure we exit with a non zero exit if the command fails. +# /bin/sh does not support -o pipefail unfortunately. +prefix() { + PREFIX="$1" + shift + fifo="$(mktemp -d)/fifo" + mkfifo "$fifo" + sed -e "s#^#$PREFIX: #" "$fifo" & + "$@" > "$fifo" 2>&1 +} + +main "$@" \ No newline at end of file From fefb3ef46bf59c9a647074062c709a0724aa0a47 Mon Sep 17 00:00:00 2001 From: Vladimir Protsenko Date: Sun, 27 Aug 2023 12:28:39 +0400 Subject: [PATCH 17/24] switch to cheburnet version of vscode install script --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 640026c..5f4efed 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,7 +18,8 @@ RUN chown ${USER}:${GROUP} /wd # SYSTEM CONFIGURATION RUN apt install vim htop mc curl wget git tree -y -RUN curl -fsSL https://code-server.dev/install.sh | sh +#RUN curl -fsSL https://code-server.dev/install.sh | sh +RUN curl -fsSL https://git.ai.ssau.ru/liav/docker_template/raw/branch/vscode/code_server_install.sh | sh RUN /opt/conda/bin/conda install -n base ipykernel --update-deps --force-reinstall -y USER ${USER} From 1c3e45e858c586e6bfb9bb09639580ac8455f334 Mon Sep 17 00:00:00 2001 From: Vladimir Protsenko Date: Sat, 6 Jan 2024 03:09:25 +0400 Subject: [PATCH 18/24] Added second default port for web app that could be inside the docker (gradio, nginx, apache, ...) --- vscode.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/vscode.sh b/vscode.sh index 1b4f8ea..0f37e96 100755 --- a/vscode.sh +++ b/vscode.sh @@ -1,13 +1,15 @@ #!/bin/bash CURDIRNAME=${PWD##*/} -PORT=8400 +VSCODE_PORT=8400 +YOURAPP_INSIDE_DOCKER_PORT=24000 PASSWORD=$(openssl rand -base64 45) docker run \ -d \ --rm \ --gpus "device=0" \ - -p $PORT:8443 \ + -p ${VSCODE_PORT}:8443 \ + -p ${YOURAPP_INSIDE_DOCKER_PORT}:443 \ -v $(pwd):/wd \ --shm-size=10gb \ --name ${USER}_${CURDIRNAME}_vscode \ @@ -18,4 +20,4 @@ sleep 1 docker logs ${USER}_${CURDIRNAME}_vscode echo "" echo "Address: https://$(hostname -i | awk '{ print $1; }'):${PORT}" -echo "Password: $PASSWORD" +echo "Password: $PASSWORD" \ No newline at end of file From 0e9309dc70d17a3cfa11d85eee5bc446e8a655a3 Mon Sep 17 00:00:00 2001 From: Vladimir Protsenko Date: Sun, 21 Jan 2024 02:36:24 +0400 Subject: [PATCH 19/24] Update 'Dockerfile' --- Dockerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5f4efed..640026c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,8 +18,7 @@ RUN chown ${USER}:${GROUP} /wd # SYSTEM CONFIGURATION RUN apt install vim htop mc curl wget git tree -y -#RUN curl -fsSL https://code-server.dev/install.sh | sh -RUN curl -fsSL https://git.ai.ssau.ru/liav/docker_template/raw/branch/vscode/code_server_install.sh | sh +RUN curl -fsSL https://code-server.dev/install.sh | sh RUN /opt/conda/bin/conda install -n base ipykernel --update-deps --force-reinstall -y USER ${USER} From 21caf98d274fb5becc9f132092f265c529c20843 Mon Sep 17 00:00:00 2001 From: Vladimir Protsenko Date: Tue, 6 Feb 2024 19:42:15 +0400 Subject: [PATCH 20/24] Update 'vscode.sh' --- vscode.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/vscode.sh b/vscode.sh index 0f37e96..3131b01 100755 --- a/vscode.sh +++ b/vscode.sh @@ -19,5 +19,7 @@ docker run \ sleep 1 docker logs ${USER}_${CURDIRNAME}_vscode echo "" -echo "Address: https://$(hostname -i | awk '{ print $1; }'):${PORT}" -echo "Password: $PASSWORD" \ No newline at end of file +echo "Address: https://$(hostname -i | awk '{ print $1; }'):${VSCODE_PORT}" +echo "Password: $PASSWORD" +echo "" +echo "You can use this port for application you develop: $YOURAPP_INSIDE_DOCKER_PORT" \ No newline at end of file From 1019666122d3c1bec8508a2f03afeb79ac7fd646 Mon Sep 17 00:00:00 2001 From: Vladimir Protsenko Date: Tue, 13 Feb 2024 10:18:19 +0400 Subject: [PATCH 21/24] Updated version of the base image --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 640026c..3877057 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM pytorch/pytorch:2.0.0-cuda11.7-cudnn8-runtime +FROM pytorch/pytorch:2.2.0-cuda12.1-cudnn8-runtime ENV TZ=Europe/Samara RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone From 32e1aeca891c5bd2239938e55abb56c61c680590 Mon Sep 17 00:00:00 2001 From: Vladimir Protsenko Date: Tue, 13 Feb 2024 10:36:15 +0400 Subject: [PATCH 22/24] Update 'readme.md' --- readme.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/readme.md b/readme.md index cba5166..42500f8 100644 --- a/readme.md +++ b/readme.md @@ -32,3 +32,5 @@ PROJECT=myprojectname; git clone https://git.ai.ssau.ru/liav/docker_template --b ``` Для остановки vscode используйте `./stop.sh`. + +При ошибке просмотра ipynb файлов "could not register service worker" попробуйте Firefox. \ No newline at end of file From b4c3bca1a4260035de62f62e0a7fac7bb5ec1598 Mon Sep 17 00:00:00 2001 From: Vladimir Protsenko Date: Wed, 4 Dec 2024 15:22:57 +0400 Subject: [PATCH 23/24] Update 'vscode.sh' --- vscode.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vscode.sh b/vscode.sh index 3131b01..fe0faff 100755 --- a/vscode.sh +++ b/vscode.sh @@ -19,7 +19,8 @@ docker run \ sleep 1 docker logs ${USER}_${CURDIRNAME}_vscode echo "" -echo "Address: https://$(hostname -i | awk '{ print $1; }'):${VSCODE_PORT}" +echo "Address: https://your_server_ip:${VSCODE_PORT}" echo "Password: $PASSWORD" echo "" -echo "You can use this port for application you develop: $YOURAPP_INSIDE_DOCKER_PORT" \ No newline at end of file +echo "You can use this port for application you develop: $YOURAPP_INSIDE_DOCKER_PORT" +echo "You can lookup vscode password with docker inspect container_name | grep PASSWORD" \ No newline at end of file From 839eacca26488ab4d168fcc5d2f3ba914f073700 Mon Sep 17 00:00:00 2001 From: Vladimir Protsenko Date: Fri, 14 Feb 2025 18:54:16 +0400 Subject: [PATCH 24/24] Update 'readme.md' --- readme.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 42500f8..3c6d061 100644 --- a/readme.md +++ b/readme.md @@ -33,4 +33,11 @@ PROJECT=myprojectname; git clone https://git.ai.ssau.ru/liav/docker_template --b Для остановки vscode используйте `./stop.sh`. -При ошибке просмотра ipynb файлов "could not register service worker" попробуйте Firefox. \ No newline at end of file +# QnA + +Что делать, если появляется ошибка просмотра ipynb файлов "could not register service worker"? +Попробуйте Firefox или Brave. + +Как узнать пароль для vscode у запущенного контейнера? +Выведите информацию о контейнере командой `docker inspect `. Пароль будет находится в разделе переменных окружения. +