跑在浏览器的 vscode | gitpod

源代码地址:https://github.com/gitpod-io/openvscode-server

源码安装

1. 下载

下载最新的版本
https://github.com/gitpod-io/openvscode-server/releases

备用下载地址:
https://cdn.jansora.com/files/openvscode-server/openvscode-server-v1.75.1-linux-x64.tar.gz

解压安装

tar zxvf openvscode-server-v1.75.1-linux-x64.tar.gz

mkdir -p /data/app
mv openvscode-server-v1.75.1-linux-x64 /data/app/openvscode-server

检查可配置项

root@l1:~/openvscode-server-v1.75.1-linux-x64# ./bin/openvscode-server --help
OpenVSCode Server 1.75.1

Usage: openvscode-server [options]

Options
  --host <ip-address>            The host name or IP address the server should listen to. If not set,
                                 defaults to 'localhost'.
  --port <port | port range>     The port the server should listen to. If 0 is passed a random free port
                                 is picked. If a range in the format num-num is passed, a free port from
                                 the range (end inclusive) is selected.
  --socket-path <path>           The path to a socket file for the server to listen to.
  --connection-token <token>     A secret that must be included with all requests.
  --connection-token-file <path> Path to a file that contains the connection token.
  --without-connection-token     Run without a connection token. Only use this if the connection is
                                 secured by other means.
  --accept-server-license-terms  If set, the user accepts the server license terms and the server will be
                                 started without a user prompt.
  --server-data-dir              Specifies the directory that server data is kept in.
  --telemetry-level <level>      Sets the initial telemetry level. Valid levels are: 'off', 'crash',
                                 'error' and 'all'. If not specified, the server will send telemetry
                                 until a client connects, it will then use the clients telemetry setting.
                                 Setting this to 'off' is equivalent to --disable-telemetry
  --user-data-dir <dir>          Specifies the directory that user data is kept in. Can be used to open
                                 multiple distinct instances of Code.
  -h --help                      Print usage.

Troubleshooting
  --log <level> Log level to use. Default is 'info'. Allowed values are 'critical', 'error', 'warn',
                'info', 'debug', 'trace', 'off'. You can also configure the log level of an extension by
                passing extension id and log level in the following format:
                '${publisher}.${name}:${logLevel}'. For example: 'vscode.csharp:trace'. Can receive one
                or more such entries.
  -v --version  Print version.

Extensions Management
  --extensions-dir <dir>              Set the root path for extensions.
  --install-extension <ext-id | path> Installs or updates an extension. The argument is either an
                                      extension id or a path to a VSIX. The identifier of an extension is
                                      '${publisher}.${name}'. Use '--force' argument to update to latest
                                      version. To install a specific version provide '@${version}'. For
                                      example: 'vscode.csharp@1.2.3'.
  --uninstall-extension <ext-id>      Uninstalls an extension.
  --list-extensions                   List the installed extensions.
  --show-versions                     Show versions of installed extensions, when using
                                      --list-extensions.
  --category <category>               Filters installed extensions by provided category, when using
                                      --list-extensions.
  --pre-release                       Installs the pre-release version of the extension, when using
                                      --install-extension
  --start-server                      Start the server when installing or uninstalling extensions. To be
                                      used in combination with 'install-extension',
                                      'install-builtin-extension' and 'uninstall-extension'.


配置 systemd

编辑 /etc/systemd/system/openvscode-server.service

禁用安全 token. 由外部nginx管理
注意端口冲突

[Unit]
Description=openvscode-server
Documentation=openvscode-server
After=network-online.target
Wants=network-online.target

[Service]
Environment="OCTANT_LISTENER_ADDR=0.0.0.0:7777"
EnvironmentFile=-/etc/default/%p
ExecStart=/data/app/openvscode-server/bin/openvscode-server --port 3000 --host=0.0.0.0 --without-connection-token
ExecStop=/bin/kill -HUP $MAINPID

KillSignal=SIGINT

[Install]
WantedBy=multi-user.target

重新加载 systemd

systemctl daemon-reload 

启动

systemctl start openvscode-server.service 
systemctl status openvscode-server.service

检测运行状态

systemctl start openvscode-server.service 
systemctl status openvscode-server.service

root@l1:/etc/systemd/system# systemctl start openvscode-server.service 
root@l1:/etc/systemd/system# systemctl status openvscode-server.service 
● openvscode-server.service - openvscode-server
     Loaded: loaded (/etc/systemd/system/openvscode-server.service; disabled; vendor preset: enabled)
     Active: active (running) since Tue 2023-02-14 16:42:07 CST; 7s ago
   Main PID: 4082036 (sh)
      Tasks: 23 (limit: 3987)
     Memory: 40.4M
     CGroup: /system.slice/openvscode-server.service
             ├─4082036 sh /data/app/openvscode-server/bin/openvscode-server --port 3000 --host=0.0.0.0 --without-connection-token
             ├─4082054 /data/app/openvscode-server/node /data/app/openvscode-server/out/server-main.js --port 3000 --host=0.0.0.0 --without-connection-token
             └─4082065 /data/app/openvscode-server/node /data/app/openvscode-server/out/bootstrap-fork --type=ptyHost --logsPath /root/.openvscode-server/data/logs/20230214T164207

Feb 14 16:42:07 l1 systemd[1]: Started openvscode-server.
Feb 14 16:42:07 l1 openvscode-server[4082054]: Server bound to 0.0.0.0:3000 (IPv4)
Feb 14 16:42:07 l1 openvscode-server[4082054]: Extension host agent listening on 3000

配置开机启动

systemctl enable openvscode-server.service 

集成到 nginx 并启用 https

请自行修改 端口号, https 证书, 自定义域名

vs.conf

upstream vs {
    server 127.0.0.1:3000;
}


server {
    listen 443 ssl;
    server_name sub.example.com;
    ssl_ciphers    ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_protocols    TLSv1 TLSv1.1 TLSv1.2;
    ssl_certificate     /etc/nginx/certs/lets-encrypt/sub.example.com.cer;
    ssl_certificate_key /etc/nginx/certs/lets-encrypt/sub.example.com.key;

    location / {
      proxy_pass http://vs;
      proxy_set_header Host $host;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection upgrade;
      proxy_set_header Accept-Encoding gzip;
    }
}

server {
    listen 80;
    server_name sub.example.com;
    return https://sub.example.com$request_uri ;
}

评论栏