2021-09-11

安裝code-server

 code-server,也就是讓你可以自架雲端版的VS Code(或開源的VSCodium),可以像GitPod(基於Eclipse Theia)一樣用瀏覽器操作遠端vs code介面。

安裝可分三種方式(Linux based):

一、直接下載script安裝(自動安裝deb或rpm):curl -fsSL https://code-server.dev/install.sh | sh

二、手動下載deb或rpm安裝

三、安裝到雲端供應商

安裝上非常簡單,安裝完後,先執行code-server跑跑看,會出現連線網址及port(預設8080),按ctrl+c停止。

打code-server --help會顯示一些可用參數,若不想用參數可修改設定檔,設定檔用的參數名稱與執行命令的參數名稱都是一樣的,設定檔位置在 ~/.config/code-server/config.yaml,以下是範例(埠號10000,使用密碼及憑證):

bind-addr: 0.0.0.0:10000
auth: password
password: mypassword
cert: /path/to/your/fullchain.pem
cert-key: /path/to/your/privkey.pem

若設為 cert: false 會使用自簽憑證,若有正式憑證請把cert及cert-key檔案路徑打上去,
建議憑證一定要設,不然複製貼上等一些功能可能會有問題,免費憑證可以使用letsencrypt,參照cerbot官網並選擇平台照建議安裝即可。

還有一個問題就是預設的plugin maketplace並不是微軟的marketplace,而是open vsx,這是因為使用條款限制的關係而不能直接使用,若想切換成微軟的marketplace,可以新增環境變數,範例script如下(.sh):

#!/bin/bash
SERVICE_URL=https://marketplace.visualstudio.com/_apis/public/gallery ITEM_URL=https://marketplace.visualstudio.com/items CACHE_URL=https://vscode.blob.core.windows.net/gallery/index code-server > /dev/null 2>&1 &  echo "$!"

用以上script執行後會顯示執行的pid並背景執行,想要關閉程式的話,可直接kill -9 <pid>,若沒記下pid而清掉螢幕,就改用 ps -u username Sf | grep code-server 找出/usr/lib/code-server/lib/node /usr/lib/code-server...執行樹最上層的process pid,並用kill -15 <pid>停止程序。

若想用systemd的方式開機自動以某user身份執行的話,可用
sudo systemctl enable --now code-server@username

記得要更換extension marketplace的話,把以下變數設定加到
/lib/systemd/system/code-server@.service
的 [Service] 裡:
Environment=SERVICE_URL=https://marketplace.visualstudio.com/_apis/public/gallery Environment=ITEM_URL=https://marketplace.visualstudio.com/items Environment=CACHE_URL=https://vscode.blob.core.windows.net/gallery/index 

執行code-server加執行參數時,可寫在
~/.local/share/code-server/argv.json 或 ~/.config/code-server/config.yaml
但像要加上 enable-proposed-api 時,寫在config.yam只能指定單個extension,用list形式指定的話無法生效(bug?),只好改寫在 argv.json,譬如:
{"enable-proposed-api": ["genuitecllc.codetogether", "ms-toolsai.jupyter"]}

ref:
https://coder.com/docs/code-server/v3.12.0/collaboration#installing-the-codetogether-extension
https://code.visualstudio.com/api/advanced-topics/using-proposed-api#sharing-extensions-using-the-proposed-api
https://coder.com/docs/code-server/v3.12.0/FAQ#how-can-i-reuse-my-vs-code-configuration


沒有留言:

張貼留言