Skip to content

Commit

Permalink
Merge pull request #380 from CodinGame/use-official-ext-host-server
Browse files Browse the repository at this point in the history
Use official ext host server
  • Loading branch information
CGNonofr authored Mar 29, 2024
2 parents a998c4c + 4fef72c commit 7b84fb7
Show file tree
Hide file tree
Showing 19 changed files with 124 additions and 579 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"globals": {
"Thenable": "readonly",
"VSCODE_VERSION": "readonly",
"VSCODE_REF": "readonly"
"VSCODE_REF": "readonly",
"VSCODE_COMMIT": "readonly"
},
"extends": [
"@codingame"
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ vscode/
vscode-loc/
monaco-editor/
vscode-default-extensions/
vscode-default-extensions-node/
dist/
10 changes: 1 addition & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -456,15 +456,7 @@ npm run start:debugServer

#### Remote agent

To connect to a remote agent, run:

```bash
npm run start:extHostServer
```

Then go to <http://localhost:5173/?remoteAuthority=localhost:8000>

You can also go to <http://localhost:5173/?remoteAuthority=localhost:8000&remotePath=/any/path/on/your/machine> to open a directory on your machine as the current workspace
[See vscode_server.md](./docs/vscode_server.md)

### History

Expand Down
49 changes: 8 additions & 41 deletions demo/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
"check-build": "npm run lint && npm run typecheck",
"build": "npm run check-build && vite --config vite.config.ts build",
"build:netlify": "npm run check-build && vite --config vite.netlify.config.ts build",
"start:debugServer": "node --loader ts-node/esm src/debugServer.ts",
"start:extHostServer": "WEB_ENDPOINT_URL_TEMPLATE=http://localhost:5173/ vscode-ext-host-server --without-connection-token"
"start:debugServer": "node --loader ts-node/esm src/debugServer.ts"
},
"devDependencies": {
"@codingame/esbuild-import-meta-url-plugin": "^1.0.2",
Expand All @@ -25,7 +24,7 @@
"@types/ws": "^8.5.10",
"ts-node": "^10.9.2",
"typescript": "~5.4.3",
"vite": "~5.2.2"
"vite": "~5.2.6"
},
"dependencies": {
"@codingame/monaco-vscode-accessibility-service-override": "file:../dist/service-override-accessibility",
Expand Down Expand Up @@ -139,7 +138,6 @@
"@codingame/monaco-vscode-scss-default-extension": "file:../dist/default-extension-scss",
"@codingame/monaco-vscode-search-result-default-extension": "file:../dist/default-extension-search-result",
"@codingame/monaco-vscode-search-service-override": "file:../dist/service-override-search",
"@codingame/monaco-vscode-server": "file:../dist/server",
"@codingame/monaco-vscode-shaderlab-default-extension": "file:../dist/default-extension-shaderlab",
"@codingame/monaco-vscode-share-service-override": "file:../dist/service-override-share",
"@codingame/monaco-vscode-shellscript-default-extension": "file:../dist/default-extension-shellscript",
Expand Down Expand Up @@ -184,7 +182,7 @@
"@codingame/monaco-vscode-yaml-default-extension": "file:../dist/default-extension-yaml",
"ansi-colors": "^4.1.3",
"dockerode": "^4.0.2",
"express": "^4.19.1",
"express": "^4.19.2",
"monaco-editor": "file:../dist/editor-api",
"vscode": "file:../dist/main",
"ws": "^8.16.0"
Expand Down
86 changes: 86 additions & 0 deletions docs/vscode_server.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# How to install and use VSCode server with monaco-vscode-api

## Install VSCode server

Get the commit_sha of the proper VSCode version by running:
```bash
curl https://raw.githubusercontent.com/CodinGame/monaco-vscode-api/v<monaco_vscode_api_version>/package.json | jq -r '.["config"]["vscode"]["commit"]'
```
(replace `<monaco_vscode_api_version>` by the version of monaco-vscode-api, starting from `3.2.3`)

Then download the server:

### For VScode server

Download `https://update.code.visualstudio.com/commit:${commit_sha}/server-<platform>-<arch>/stable`

Replace:
- `<platform>` by either `win32`, `linux` or `darwin`
- `<arch>` by either `arm64`, `x64` or `armhf`

For instance: <https://update.code.visualstudio.com/commit:863d2581ecda6849923a2118d93a088b0745d9d6/server-linux-x64/stable>

### For VSCodium server

Get `reh` release from <https://github.com/VSCodium/vscodium/releases>

For instance: `vscodium-reh-linux-x64-1.87.2.24072.tar.gz`

## Installation
Untar the archive in the install directory:

```bash
mkdir -p <install_directory> && tar --no-same-owner -xzv --strip-components=1 -C <install_directory> -f <archive>
```

It's also possible to extract the archive on the fly while downloading it:
```bash
curl -L --max-redirs 5 https://update.code.visualstudio.com/commit:863d2581ecda6849923a2118d93a088b0745d9d6/server-linux-x64/stable | tar -xz -C . --strip-components=1
```

## Configuration

In the install directory, edit the file `product.json` and make sure:
- The `commit` field correspond to the `commit_sha` found earlier (especially for VSCodium)
- The `webEndpointUrlTemplate` contains the url of the app that will be using monaco-vscode-api (example: `https://my.domain.com/`) (create the field if it doesn't exists)

Example:
```bash
cat <<< "$(jq ".webEndpointUrlTemplate = \"https://my.domain.com/\"" product.json)" > product.json
cat <<< "$(jq ".commit = \"863d2581ecda6849923a2118d93a088b0745d9d6\"" product.json)" > product.json
```

### advanced

The `commit` should correspond to what is configured in the client, which is by default the VSCode commit used to build the lib, but it can be overriden by providing `configuration.productConfiguration.commit` to the service initialization function.

## Running the server

From the install directory, run:

```bash
./bin/code-server --port 8080 --without-connection-token --accept-server-license-terms --host 0.0.0.0
```

(or `./bin/codium-server`) for VSCodium

Note: it starts the service on every interfaces and without a security token just to simplify the usage, but do not use it as is in production


## Using the server

- Add the `remoteAgent` service override (`@codingame/monaco-vscode-remote-agent-service-override`)
- Configure the url of the remote server by providing a `remoteAuthority` to the service initialization function configuration. It should only contain the authority (domain/ip and port, example: `localhost:8080`). You can also provide a `connectionToken` if the server is configured to expect it.
- You can now use a remote directory as workspace by using the `vscode-remote` scheme. for instance : `vscode-remote://localhost:8080/my/project/directory`

## Testing it in the demo

Run the demo, then go to <http://localhost:5173/?remoteAuthority=localhost:8080>

You can also go to <http://localhost:5173/?remoteAuthority=localhost:8000&remotePath=/any/path/on/your/machine> to open a directory on your machine as the current workspace

## Production concerns

The commit and product quality should be the same on the client and on the server to be able to connect them. It can be an issue if you have the server deployed on a cluster, and the client is upgraded progressively: it is required for the server to expose both old and new version.

It can be achieved because all calls to the server are prefixed by `<quality>-<commit>`. So both servers can be started on a different port, and a reverse proxy in front of them can redirect the calls based on the path prefix.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
},
"type": "module",
"scripts": {
"build": "npm run clean && npm run lint && npm run compile && npm run compile-rollup-plugins && npm run generate-types && npm run compile-server && npm run compile-default-extensions && npm run compile-language-packs && npm run compile-monaco-languages",
"compile": "NODE_OPTIONS=--max_old_space_size=16384 rollup --config rollup/rollup.config.ts --configPlugin 'typescript={tsconfig: `tsconfig.rollup-config.json`}' --vscode-version ${npm_package_config_vscode_version} --vscode-ref ${npm_package_config_vscode_ref}",
"build": "npm run clean && npm run lint && npm run compile && npm run compile-rollup-plugins && npm run generate-types && npm run compile-default-extensions && npm run compile-language-packs && npm run compile-monaco-languages",
"compile": "NODE_OPTIONS=--max_old_space_size=16384 rollup --config rollup/rollup.config.ts --configPlugin 'typescript={tsconfig: `tsconfig.rollup-config.json`}' --vscode-version ${npm_package_config_vscode_version} --vscode-ref ${npm_package_config_vscode_ref} --vscode-commit ${npm_package_config_vscode_commit}",
"compile-default-extensions": "NODE_OPTIONS=--max_old_space_size=16384 rollup --config rollup/rollup.default-extensions.ts --configPlugin 'typescript={tsconfig: `tsconfig.rollup-config-default-extensions.json`}'",
"compile-language-packs": "NODE_OPTIONS=--max_old_space_size=16384 rollup --config rollup/rollup.language-packs.ts --configPlugin 'typescript={tsconfig: `tsconfig.rollup-config-language-packs.json`}'",
"compile-monaco-languages": "NODE_OPTIONS=--max_old_space_size=16384 rollup --config rollup/rollup.monaco.ts --configPlugin 'typescript={tsconfig: `tsconfig.rollup-config-monaco.json`}'",
"clean": "rm -rf dist/",
"compile-server": "rollup --config rollup/rollup.server.config.ts --configPlugin 'typescript={tsconfig: `tsconfig.rollup-config-server.json`, include: [`./rollup/rollup.server.config.ts`, `./rollup/rollup-metadata-plugin.ts`, `./rollup/rollup-asset-glob-meta-url-plugin.ts`]}' --vscode-version ${npm_package_config_vscode_version} --vscode-ref ${npm_package_config_vscode_ref}",
"compile-rollup-plugins": "rollup --config rollup/rollup.rollup-plugins.config.ts --configPlugin 'typescript={tsconfig: `tsconfig.rollup-config-plugins.json`, include: [`./rollup/rollup.rollup-plugins.config.ts`, `./rollup/rollup-metadata-plugin.ts`]}'",
"preprepare": "patch-package && ./scripts/install-vscode",
"lint": "eslint '{src/**/*.ts,rollup/*.ts,*.ts}'",
Expand All @@ -33,7 +32,8 @@
"config": {
"vscode": {
"version": "1.87.2",
"ref": "1.87.2"
"ref": "1.87.2",
"commit": "863d2581ecda6849923a2118d93a088b0745d9d6"
},
"monaco": {
"ref": "v0.47.0",
Expand Down
2 changes: 2 additions & 0 deletions rollup/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ const external: rollup.ExternalOption = (source) => {

export default (args: Record<string, string>): rollup.RollupOptions[] => {
const vscodeVersion = args['vscode-version']
const vscodeCommit = args['vscode-commit']
delete args['vscode-version']
const vscodeRef = args['vscode-ref']
delete args['vscode-ref']
Expand Down Expand Up @@ -550,6 +551,7 @@ export default (args: Record<string, string>): rollup.RollupOptions[] => {
}), replace({
VSCODE_VERSION: JSON.stringify(vscodeVersion),
VSCODE_REF: JSON.stringify(vscodeRef),
VSCODE_COMMIT: JSON.stringify(vscodeCommit),
preventAssignment: true
}),
(() => {
Expand Down
Loading

1 comment on commit 7b84fb7

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.