gitpod 基于vscode server 开源

天问 1fb5716eb9 Update 'README.md' 1 year ago
README.md 1fb5716eb9 Update 'README.md' 1 year ago

README.md

openvscode-server

gitpod 基于vscode server 开源,应用在gitpod上可以通过浏览器,gitpod插件连接远程服务器实现远程开发,coding也是用的这个技术。

Usage

启动openvscode-server:

docker run -it --init -p 3000:3000 -v "$(pwd):/home/workspace:cached" gitpod/openvscode-server

指定端口3000,--connection-token YOUR_TOKEN 指定token权限

Develop

基于vscode开发,类似构建源码,项目结构类似


coding 启动远程开发过程:

1、点击远程开发按钮,会检测当前页面项目分支,检测是否有配置文件 .coding-ci.yml,有就覆盖配置文件构建开发容器

2、

# 设置token
set env for key: CODING_PROJECT_TOKEN
set env for key: CODING_PROJECT_TOKEN_USER_NAME

分配cpu等硬件资源

这一阶段如果自定义镜像,会构建很慢

3、

docker network create --driver bridge coding-ci-7d3-1hf9l6thi-001-network

docker run --rm -d --name coding-ci-7d3-1hf9l6thi-001-network-bus orangeci/network-bus:latest sleep 79200

docker run --rm -d --name coding-ci-7d3-1hf9l6thi-001-git-clone-yyds orangeci/git-clone-yyds:latest sleep 79200

docker exec -e PLUGIN_IS_RETRY coding-ci-7d3-1hf9l6thi-001-git-clone-yyds /bin/entrypoint.sh


# Initialized empty Git repository in /data/orange-ci/git/e.coding.net/sift~XunfeiTTS~XunfeiTTS/cache/.git/

git remote add origin "https://e.coding.net/sift/XunfeiTTS/XunfeiTTS.git"

git fetch --quiet --progress --force --prune --tags --prune-tags --no-recurse-submodules --refmap=+refs/heads/*:refs/remotes/origin/* origin "refs/heads/master"

docker run --rm -d --name coding-ci-7d3-1hf9l6thi-001-dind docker:24.0.5-dind dockerd --rootless

# docker in docker
docker cp coding-ci-7d3-1hf9l6thi-001-dind:/usr/local/bin/docker /data/orange-ci/tmp/coding-ci-7d3-1hf9l6thi-001/docker/cli/docker


# 应用 
docker run --rm -e PLUGIN_FILES -e PLUGIN_ALGORITHM -v /data/orange-ci/runner/sift~XunfeiTTS~XunfeiTTS/coding-ci-7d3-1hf9l6thi-001/workspace/:/data -w /data orangeci/hasha:latest

docker run -d --rm -e TZ='Asia/Shanghai' -p 10.234.14.2::80 -e ip -e port --name coding-ci-7d3-1hf9l6thi-001-endpoint-36000 --network coding-ci-7d3-1hf9l6thi-001-network orangeci/endpoints:2.0.1

docker run -d --rm -e TZ='Asia/Shanghai' -u root $ORANGE_ENVS --network container:coding-ci-7d3-1hf9l6thi-001-network-bus --ulimit nofile=65535:65535 --sysctl net.ipv4.ping_group_range="0 2147483647"  --cap-drop CAP_NET_RAW --cgroup-parent=/coding-ci-7d3-1hf9l6thi-001/ --cpus 1 --storage-opt size=10G --shm-size 2g --name coding-ci-7d3-1hf9l6thi-001 -v /etc/localtime:/etc/localtime -v /data/orange-ci/runner/sift~XunfeiTTS~XunfeiTTS/coding-ci-7d3-1hf9l6thi-001/workspace/:/workspace/ -w /workspace/ -v /data/orange-ci/runner/sift~XunfeiTTS~XunfeiTTS/coding-ci-7d3-1hf9l6thi-001/userdata/.git/:/run/.git/ -v /data/orange-ci/runner/sift~XunfeiTTS~XunfeiTTS/coding-ci-7d3-1hf9l6thi-001/userdata/.userdata/:/run/.userdata/ -v /data/orange-ci/tmp/coding-ci-7d3-1hf9l6thi-001/docker/host/docker.sock:/var/run/docker.sock -v /data/orange-ci/tmp/coding-ci-7d3-1hf9l6thi-001/docker/cli/docker:/usr/local/bin/docker -v /usr/libexec/docker/cli-plugins:/usr/libexec/docker/cli-plugins:ro -v /var/lib/lxcfs/proc/cpuinfo:/proc/cpuinfo -v /var/lib/lxcfs/proc/diskstats:/proc/diskstats -v /var/lib/lxcfs/proc/loadavg:/proc/loadavg -v /var/lib/lxcfs/proc/meminfo:/proc/meminfo -v /var/lib/lxcfs/proc/slabinfo:/proc/slabinfo -v /var/lib/lxcfs/proc/stat:/proc/stat -v /var/lib/lxcfs/proc/swaps:/proc/swaps -v /var/lib/lxcfs/proc/uptime:/proc/uptime -v /var/lib/lxcfs/sys/devices/system/cpu:/sys/devices/system/cpu --entrypoint= --init codingci/default-env:latest sleep 72000


mkdir -p /run/sshd; ssh-keygen -A; /usr/sbin/sshd -e -p 36000 -o UsePAM=no -o PermitRootL

ln -s /root/.local/share/code-server/extensions /root/.vscode-server/extensions

rsync -acvm --timeout=300 --safe-links --delete  --include="*/" --include=".bash_history" --include=".bashrc" --include=".gitconfig" --include=".local/share/code-server/User/settings.json" --include=".node_repl_history" --include=".profile" --include=".python_history" --include=".ssh/authorized_keys" --include=".local/share/code-server/User/settings.json" --exclude="*" ./ "rsync://10.234.14.2:8088/data/orange-ci/runner/sift~XunfeiTTS~XunfeiTTS/coding-ci-7d3-1hf9l6thi-001/userdata/.userdata/"

docker exec coding-ci-7d3-1hf9l6thi-001 sh -c "$ORANGE_TMP_SHELL"

docker run --rm -u root --privileged --pid=container:coding-ci-7d3-1hf9l6thi-001 orangeci/read-env:latest | docker exec -i coding-ci-7d3-1hf9l6thi-001 sh -c "cat >> /etc/profile"

# 检测是否连接,10分钟终止
docker run -e PORT=36000 --network container:coding-ci-7d3-1hf9l6thi-001-network-bus orangeci/check-is-remote-connections:latest

最后

#浏览器生成如下连接,启动vscode:

vscode://vscode-remote/ssh-remote+coding-ci-pb2-1hf6o1jl8-001%2318a22d64-51ba-4629-8755-cd021b24f028-gig@ci.coding.net:2201/workspace/


"D:\Program Files\Git\usr\bin\ssh.exe" -T -D 15319 -F "C:\Users\liuyuqi\.ssh\config" -p 2201 "coding-ci-pb2-1hf6o1jl8-001#18a22d64-51ba-4629-8755-cd021b24f028-gig@ci.coding.net" bash

vscode://file/path/to/filevscode://vscode-remote/ssh-remote+[USER@]HOST[:PORT]/path/to/file

"C:\WINDOWS\System32\OpenSSH\ssh.exe" -T -D 25398 "52ddb1a8b045e2e32b1c5ef69bce26a4093a91cf-qgtmyt@qgtmyt.ssh.cloudstudio.net" bash