From 41d625abb6cd77e7e8b6cb955c328ffa310ca586 Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Tue, 12 May 2020 01:46:38 -0400 Subject: [PATCH 01/27] Revamp README.md with new installation options --- README.md | 99 ++++++++++++++++++++++++++++---------- ci/build/build-packages.sh | 3 +- 2 files changed, 75 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 667426ec4..7cd169465 100644 --- a/README.md +++ b/README.md @@ -1,47 +1,94 @@ # code-server -`code-server` is [VS Code](https://github.com/Microsoft/vscode) running on a -remote server, accessible through the browser. - -Try it out: - -```bash -docker run -it -p 127.0.0.1:8080:8080 -v "$PWD:/home/coder/project" -u "$(id -u):$(id -g)" codercom/code-server:latest -``` +Run [VS Code](https://github.com/Microsoft/vscode) on any machine anywhere and access it through the browser. - **Code anywhere:** Code on your Chromebook, tablet, and laptop with a consistent dev environment. Develop on a Linux machine and pick up from any device with a web browser. -- **Server-powered:** Take advantage of large cloud servers to speed up tests, - compilations, downloads, and more. Preserve battery life when you're on the go - since all intensive computation runs on your server. +- **Server-powered:** Take advantage of large cloud servers to speed up tests, compilations, downloads, and more. + Preserve battery life when you're on the go since all intensive tasks runs on your server. + Make use of a spare computer you have lying around and turn it into a full development environment. -![Example gif](/doc/assets/code-server.gif) +![Example gif](./doc/assets/code-server.gif) -## Getting Started +## Getting started -### Requirements +For a proper setup and walkthrough, please see [./doc/guide.md](./doc/guide.md). -- 64-bit host. -- At least 1GB of RAM. -- 2 cores or more are recommended (1 core works but not optimally). -- Secure connection over HTTPS or localhost (required for service workers and - clipboard support). -- For Linux: GLIBC 2.17 or later and GLIBCXX 3.4.15 or later. +### Debian, Ubuntu -### Run over SSH +```bash +curl -sSOL https://github.com/cdr/code-server/releases/download/3.3.0/code-server_3.3.0_amd64.deb +sudo dpkg -i code-server_3.3.0_amd64.deb +sudo systemctl enable --now code-server +# Now visit http://127.0.0.1:8080. Your password is in ~/.config/code-server/config.yaml +``` -Use [sshcode](https://github.com/codercom/sshcode) for a simple setup. +### Fedora, Red Hat, SUSE + +```bash +curl -sSOL https://github.com/cdr/code-server/releases/download/3.3.0/code-server-3.3.0-amd64.rpm +sudo dnf install code-server-3.3.0-amd64.rpm +sudo systemctl enable --now code-server +# Now visit http://127.0.0.1:8080. Your password is in ~/.config/code-server/config.yaml +``` + +### npm + +```bash +npm install -g code-server +code-server +``` + +### macOS + +```bash +brew install code-server +brew service start code-server +# Now visit http://127.0.0.1:8080. Your password is in ~/.config/code-server/config.yaml +``` + +### SSH + +You can use [sshcode](https://github.com/codercom/sshcode) to start and use code-server on any Linux machine over SSH. + +```bash +sshcode user@dev.coder.com +# Downloads and installs code-server on dev.coder.com and opens it in a new browser window. +``` ### Digital Ocean [![Create a Droplet](./doc/assets/droplet.svg)](https://marketplace.digitalocean.com/apps/code-server) -### Releases +### Docker -1. [Download a release](https://github.com/cdr/code-server/releases). (Linux and macOS supported. Windows support planned.) -2. Unpack the downloaded release then run the included `code-server` script. -3. In your browser navigate to `localhost:8080`. +```bash +docker run -it -p 127.0.0.1:8080:8080 -v "$PWD:/home/coder/project" -u "$(id -u):$(id -g)" codercom/code-server:latest +``` + +This will start a code-server container and expose it at http://127.0.0.1:8080. It will also mount +your current directory into the container as `/home/coder/project` and forward your UID/GID so that +all file system operations occur as your user outside the container. + +### Self contained releases + +We publish self contained archives for every release on [github](https://github.com/cdr/code-server/releases). +They bundle the node binary and node_modules. + +1. Download the latest release archive for your system from [github](https://github.com/cdr/code-server/releases) +2. Unpack the release +3. You can run code-server by executing `bin/code-server` + +Add the code-server `bin` directory to your `$PATH` to easily execute it without the full path every time. + +Here is an example script for installing and using a self-contained code-server release on Linux: + +```bash +curl -sSL https://github.com/cdr/code-server/releases/download/3.3.0/code-server-3.3.0-linux-amd64.tar.gz | sudo tar -C /opt -xz +PATH="$PATH:/opt/code-server-3.3.0-linux-amd64/bin" +code-server +``` ## FAQ diff --git a/ci/build/build-packages.sh b/ci/build/build-packages.sh index 7dc65df0d..6eb93c544 100755 --- a/ci/build/build-packages.sh +++ b/ci/build/build-packages.sh @@ -52,7 +52,8 @@ release_nfpm() { local nfpm_config nfpm_config=$(envsubst < ./ci/build/nfpm.yaml) - nfpm pkg -f <(echo "$nfpm_config") --target release-packages/code-server-"$VERSION-$ARCH.deb" + # The underscores are convention for .deb. + nfpm pkg -f <(echo "$nfpm_config") --target release-packages/code-server_"$VERSION_$ARCH.deb" nfpm pkg -f <(echo "$nfpm_config") --target release-packages/code-server-"$VERSION-$ARCH.rpm" } From 4aae5eaeca524cb952f1a63980e48af5e4846f0a Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Tue, 12 May 2020 19:33:34 -0400 Subject: [PATCH 02/27] CI fixes - Splits up test into fmt, lint and test - Fixes bug in build-packages.sh - Minor README.md fixes --- .github/workflows/ci.yaml | 18 ++++++++++++++++++ README.md | 14 +------------- ci/README.md | 8 ++++++-- ci/build/build-packages.sh | 4 ++-- ci/steps/fmt.sh | 17 +++++++++++++++++ ci/steps/lint.sh | 17 +++++++++++++++++ ci/steps/test.sh | 2 +- 7 files changed, 62 insertions(+), 18 deletions(-) create mode 100755 ci/steps/fmt.sh create mode 100755 ci/steps/lint.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f20b60f37..c2a97ddd8 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -3,6 +3,24 @@ name: ci on: [push, pull_request] jobs: + fmt: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Run ./ci/steps/fmt.sh + uses: ./ci/container + with: + args: ./ci/steps/fmt.sh + + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Run ./ci/steps/lint.sh + uses: ./ci/container + with: + args: ./ci/steps/lint.sh + test: runs-on: ubuntu-latest steps: diff --git a/README.md b/README.md index 7cd169465..a0f5e6b12 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ sudo systemctl enable --now code-server ```bash npm install -g code-server code-server +# Now visit http://127.0.0.1:8080. Your password is in ~/.config/code-server/config.yaml ``` ### macOS @@ -48,19 +49,6 @@ brew service start code-server # Now visit http://127.0.0.1:8080. Your password is in ~/.config/code-server/config.yaml ``` -### SSH - -You can use [sshcode](https://github.com/codercom/sshcode) to start and use code-server on any Linux machine over SSH. - -```bash -sshcode user@dev.coder.com -# Downloads and installs code-server on dev.coder.com and opens it in a new browser window. -``` - -### Digital Ocean - -[![Create a Droplet](./doc/assets/droplet.svg)](https://marketplace.digitalocean.com/apps/code-server) - ### Docker ```bash diff --git a/ci/README.md b/ci/README.md index b09545246..b2539f8f7 100644 --- a/ci/README.md +++ b/ci/README.md @@ -31,7 +31,7 @@ This directory contains scripts used for the development of code-server. - [./dev/container](./dev/container) - See [CONTRIBUTING.md](../doc/CONTRIBUTING.md) for docs on the development container - [./dev/ci.sh](./dev/ci.sh) (`yarn ci`) - - Runs formatters, linters and tests + - Runs `yarn fmt`, `yarn lint` and `yarn test` - [./dev/fmt.sh](./dev/fmt.sh) (`yarn fmt`) - Runs formatters - [./dev/lint.sh](./dev/lint.sh) (`yarn lint`) @@ -106,8 +106,12 @@ This directory contains the container for CI. This directory contains a few scripts used in CI. Just helps avoid clobbering the CI configuration. +- [./steps/fmt.sh](./steps/fmt.sh) + - Runs `yarn fmt` after ensuring VS Code is patched +- [./steps/lint.sh](./steps/lint.sh) + - Runs `yarn lint` after ensuring VS Code is patched - [./steps/test.sh](./steps/test.sh) - - Runs `yarn ci` after ensuring VS Code is patched + - Runs `yarn test` after ensuring VS Code is patched - [./steps/release.sh](./steps/release.sh) - Runs the full release process - Generates the npm package at `./release` diff --git a/ci/build/build-packages.sh b/ci/build/build-packages.sh index 6eb93c544..dc7f61680 100755 --- a/ci/build/build-packages.sh +++ b/ci/build/build-packages.sh @@ -53,8 +53,8 @@ release_nfpm() { nfpm_config=$(envsubst < ./ci/build/nfpm.yaml) # The underscores are convention for .deb. - nfpm pkg -f <(echo "$nfpm_config") --target release-packages/code-server_"$VERSION_$ARCH.deb" - nfpm pkg -f <(echo "$nfpm_config") --target release-packages/code-server-"$VERSION-$ARCH.rpm" + nfpm pkg -f <(echo "$nfpm_config") --target "release-packages/code-server_${VERSION}_${ARCH}.deb" + nfpm pkg -f <(echo "$nfpm_config") --target "release-packages/code-server-$VERSION-$ARCH.rpm" } main "$@" diff --git a/ci/steps/fmt.sh b/ci/steps/fmt.sh new file mode 100755 index 000000000..f7b1bbb88 --- /dev/null +++ b/ci/steps/fmt.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +set -euo pipefail + +main() { + cd "$(dirname "$0")/../.." + + yarn + + git submodule update --init + # We do not `yarn vscode` to make test.sh faster. + # If the patch fails to apply, then it's likely already applied + yarn vscode:patch &> /dev/null || true + + yarn fmt +} + +main "$@" diff --git a/ci/steps/lint.sh b/ci/steps/lint.sh new file mode 100755 index 000000000..c58473fbf --- /dev/null +++ b/ci/steps/lint.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +set -euo pipefail + +main() { + cd "$(dirname "$0")/../.." + + yarn + + git submodule update --init + # We do not `yarn vscode` to make test.sh faster. + # If the patch fails to apply, then it's likely already applied + yarn vscode:patch &> /dev/null || true + + yarn lint +} + +main "$@" diff --git a/ci/steps/test.sh b/ci/steps/test.sh index 9430d1078..73c3520dc 100755 --- a/ci/steps/test.sh +++ b/ci/steps/test.sh @@ -11,7 +11,7 @@ main() { # If the patch fails to apply, then it's likely already applied yarn vscode:patch &> /dev/null || true - yarn ci + yarn test } main "$@" From 502c262c82bf802ffe5eef0eabc9d1c8d90d38d7 Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Tue, 12 May 2020 19:44:54 -0400 Subject: [PATCH 03/27] Mention update of versions in README install examples --- ci/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/README.md b/ci/README.md index b2539f8f7..be08b7bf6 100644 --- a/ci/README.md +++ b/ci/README.md @@ -10,7 +10,7 @@ Any file and directory added into this tree should be documented here. Make sure you have `$GITHUB_TOKEN` set and [hub](https://github.com/github/hub) installed. -1. Update the version of code-server in `package.json` and push a commit +1. Update the version of code-server in `package.json` and README.md install examples and push a commit 1. GitHub actions will generate the `npm-package` and `release-packages` artifacts 1. Run `yarn release:github-draft` to create a GitHub draft release from the template with the updated version. From a346c6d565e77a83b6a874802b0163ee57e1e4dd Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Tue, 12 May 2020 23:11:31 -0400 Subject: [PATCH 04/27] Document npm module install dependencies --- README.md | 5 ++++- doc/CONTRIBUTING.md | 24 ++++++++++++++++++++---- doc/npm.md | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 doc/npm.md diff --git a/README.md b/README.md index a0f5e6b12..d99076a74 100644 --- a/README.md +++ b/README.md @@ -28,13 +28,16 @@ sudo systemctl enable --now code-server ```bash curl -sSOL https://github.com/cdr/code-server/releases/download/3.3.0/code-server-3.3.0-amd64.rpm -sudo dnf install code-server-3.3.0-amd64.rpm +sudo yum install -y code-server-3.3.0-amd64.rpm sudo systemctl enable --now code-server # Now visit http://127.0.0.1:8080. Your password is in ~/.config/code-server/config.yaml ``` ### npm +**note:** Installing via `npm` requires building native module dependencies. See [./doc/npm.md](./doc/npm.md) +for the dependency install process depending on your OS. + ```bash npm install -g code-server code-server diff --git a/doc/CONTRIBUTING.md b/doc/CONTRIBUTING.md index 37be0f7dd..def3df0fc 100644 --- a/doc/CONTRIBUTING.md +++ b/doc/CONTRIBUTING.md @@ -3,9 +3,16 @@ - [Detailed CI and build process docs](../ci) - [Our VS Code Web docs](../src/node/app) -## Development Workflow +## Requirements -- [VS Code prerequisites](https://github.com/Microsoft/vscode/wiki/How-to-Contribute#prerequisites) +Please refer to [VS Code's prerequisites](https://github.com/Microsoft/vscode/wiki/How-to-Contribute#prerequisites). + +Differences: + +- We are not constrained by node version +- We use [fnpm](https://github.com/goreleaser/nfpm) to build .deb and .rpm packages + +## Development Workflow ```shell yarn @@ -33,8 +40,6 @@ works internally. ## Build -- [VS Code prerequisites](https://github.com/Microsoft/vscode/wiki/How-to-Contribute#prerequisites) - ```shell yarn yarn vscode @@ -45,3 +50,14 @@ cd release yarn --production node . # Run the built JavaScript with Node. ``` + +Now you can make it static and build packages with: + +``` +yarn release:static +yarn test:static-release +yarn package +``` + +The static release will be in `./release-static` and the release packages +(.deb, .rpm, self contained release) in `./release-packages`. diff --git a/doc/npm.md b/doc/npm.md new file mode 100644 index 000000000..84712f61b --- /dev/null +++ b/doc/npm.md @@ -0,0 +1,32 @@ +# npm Install Requirements + +If you're installing the npm module you'll need certain dependencies to build +the native modules used by VS Code. + +## Ubuntu, Debian + +```bash +sudo apt-get install -y \ + build-essential \ + pkg-config \ + libx11-dev \ + libxkbfile-dev \ + libsecret-1-dev +``` + +## Fedora, Red Hat, SUSE + +```bash +sudo yum groupinstall -y 'Development Tools' +sudo yum config-manager --set-enabled PowerTools +sudo yum install -y python2 libsecret-devel libX11-devel libxkbfile-devel +npm config set python python2 +``` + +## macOS + +Install [Xcode](https://developer.apple.com/xcode/downloads/) and run: + +```bash +xcode-select --install +``` From 1739b21600dd826ad88840f7aa3ed9a6cc625de8 Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Wed, 13 May 2020 02:35:11 -0400 Subject: [PATCH 05/27] Bundle VS Code node_modules to avoid yarn dependency Many random bizarre issues otherwise. Also includes misc improvements to docs and scripts. --- README.md | 2 +- ci/README.md | 12 ++++++++---- ci/build/build-release.sh | 28 +++++++++++++++------------- ci/build/clean.sh | 18 +++++++++++++++--- ci/dev/diff-vscode.sh | 11 +++++++++++ ci/dev/patch-vscode.sh | 11 +++++++++++ doc/CONTRIBUTING.md | 3 +-- package.json | 4 ++-- 8 files changed, 64 insertions(+), 25 deletions(-) create mode 100755 ci/dev/diff-vscode.sh create mode 100755 ci/dev/patch-vscode.sh diff --git a/README.md b/README.md index d99076a74..d0a95abcc 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ all file system operations occur as your user outside the container. ### Self contained releases We publish self contained archives for every release on [github](https://github.com/cdr/code-server/releases). -They bundle the node binary and node_modules. +They bundle the node binary and compiled native modules. 1. Download the latest release archive for your system from [github](https://github.com/cdr/code-server/releases) 2. Unpack the release diff --git a/ci/README.md b/ci/README.md index be08b7bf6..dc3e0da50 100644 --- a/ci/README.md +++ b/ci/README.md @@ -39,7 +39,11 @@ This directory contains scripts used for the development of code-server. - [./dev/test.sh](./dev/test.sh) (`yarn test`) - Runs tests - [./dev/vscode.sh](./dev/vscode.sh) (`yarn vscode`) - - Ensures `lib/vscode` is cloned, patched and dependencies are installed + - Ensures [../lib/vscode](../lib/vscode) is cloned, patched and dependencies are installed +- [./dev/patch-vscode.sh](./dev/patch-vscode.sh) (`yarn vscode:patch`) + - Applies [./dev/vscode.patch](./dev/vscode.patch) to [../lib/vscode](../lib/vscode) +- [./dev/diff-vscode.sh](./dev/diff-vscode.sh) (`yarn vscode:diff`) + - Diffs [../lib/vscode](../lib/vscode) into [./dev/vscode.patch](./dev/vscode.patch) - [./dev/vscode.patch](./dev/vscode.patch) - Our patch of VS Code to enable remote browser access - Generate it with `yarn vscode:diff` and apply with `yarn vscode:patch` @@ -62,11 +66,11 @@ You can disable minification by setting `MINIFY=`. - Bundles the output of the above two scripts into a single node module at `./release`. - [./build/build-static-release.sh](./build/build-static-release.sh) (`yarn release:static`) - Requires a release already built in `./release`. - - Will build a static release with node and node_modules into `./release-static` + - Will build a static release with node bundled into `./release-static` - [./build/clean.sh](./build/clean.sh) (`yarn clean`) - - Removes all git ignored files like build artifacts. + - Removes all build artifacts - Will also `git reset --hard lib/vscode` - - Useful to do a clean build. + - Useful to do a clean build - [./build/code-server.sh](./build/code-server.sh) - Copied into static releases to run code-server with the bundled node binary. - [./build/test-static-release.sh](./build/test-static-release.sh) (`yarn test:static-release`) diff --git a/ci/build/build-release.sh b/ci/build/build-release.sh index d96a466d3..0c1117e41 100755 --- a/ci/build/build-release.sh +++ b/ci/build/build-release.sh @@ -40,7 +40,7 @@ bundle_code_server() { { "commit": "$(git rev-parse HEAD)", "scripts": { - "postinstall": "cd lib/vscode && yarn --production && cd extensions && yarn --production" + "postinstall": "cd lib/vscode && npm rebuild # Builds native modules" } } EOF @@ -49,18 +49,15 @@ EOF bundle_vscode() { mkdir -p "$VSCODE_OUT_PATH" + rsync "$VSCODE_SRC_PATH/package.json" "$VSCODE_OUT_PATH" + rsync "$VSCODE_SRC_PATH/yarn.lock" "$VSCODE_OUT_PATH" + rsync "$VSCODE_SRC_PATH/node_modules" "$VSCODE_OUT_PATH" rsync "$VSCODE_SRC_PATH/out-vscode${MINIFY+-min}/" "$VSCODE_OUT_PATH/out" rsync "$VSCODE_SRC_PATH/.build/extensions/" "$VSCODE_OUT_PATH/extensions" - rm -Rf "$VSCODE_OUT_PATH/extensions/node_modules" - rsync "$VSCODE_SRC_PATH/extensions/package.json" "$VSCODE_OUT_PATH/extensions" - rsync "$VSCODE_SRC_PATH/extensions/yarn.lock" "$VSCODE_OUT_PATH/extensions" - rsync "$VSCODE_SRC_PATH/extensions/postinstall.js" "$VSCODE_OUT_PATH/extensions" mkdir -p "$VSCODE_OUT_PATH/resources/linux" rsync "$VSCODE_SRC_PATH/resources/linux/code.png" "$VSCODE_OUT_PATH/resources/linux/code.png" - rsync "$VSCODE_SRC_PATH/yarn.lock" "$VSCODE_OUT_PATH" - # Adds the commit and date to product.json jq --slurp '.[0] * .[1]' "$VSCODE_SRC_PATH/product.json" <( cat << EOF @@ -71,12 +68,17 @@ bundle_vscode() { EOF ) > "$VSCODE_OUT_PATH/product.json" - # We remove the scripts field so that later on we can run - # yarn to fetch node_modules if necessary without build scripts - # being ran. - # We cannot use --no-scripts because we still want dependant package scripts to run - # for native modules to be rebuilt. - jq 'del(.scripts)' < "$VSCODE_SRC_PATH/package.json" > "$VSCODE_OUT_PATH/package.json" + pushd "$VSCODE_OUT_PATH" + yarn --production --ignore-scripts + popd + + # Now we clear any native module builds. + local nativeModules + mapfile -t nativeModules < <(find "$VSCODE_OUT_PATH/node_modules" -name "binding.gyp" -exec dirname {} \;) + local nm + for nm in "${nativeModules[@]}"; do + rm -R "$nm/build" + done } main "$@" diff --git a/ci/build/clean.sh b/ci/build/clean.sh index df8da6de0..c57e0b435 100755 --- a/ci/build/clean.sh +++ b/ci/build/clean.sh @@ -3,10 +3,22 @@ set -euo pipefail main() { cd "$(dirname "${0}")/../.." + source ./ci/lib.sh - git clean -Xffd - git submodule foreach --recursive git clean -xffd - git submodule foreach --recursive git reset --hard + rm -Rf \ + out \ + release \ + release-static \ + release-packages \ + release-gcp \ + dist \ + .tsbuildinfo \ + .cache/out.tsbuildinfo + + pushd lib/vscode + git clean -xffd + git reset --hard + popd } main "$@" diff --git a/ci/dev/diff-vscode.sh b/ci/dev/diff-vscode.sh new file mode 100755 index 000000000..a1c1f0273 --- /dev/null +++ b/ci/dev/diff-vscode.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +set -euo pipefail + +main() { + cd "$(dirname "$0")/../.." + + cd ./lib/vscode + git diff HEAD > ../../ci/dev/vscode.patch +} + +main "$@" diff --git a/ci/dev/patch-vscode.sh b/ci/dev/patch-vscode.sh new file mode 100755 index 000000000..cdc2691ad --- /dev/null +++ b/ci/dev/patch-vscode.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +set -euo pipefail + +main() { + cd "$(dirname "$0")/../.." + + cd ./lib/vscode + git apply ../../ci/dev/vscode.patch +} + +main "$@" diff --git a/doc/CONTRIBUTING.md b/doc/CONTRIBUTING.md index def3df0fc..2eeefc47a 100644 --- a/doc/CONTRIBUTING.md +++ b/doc/CONTRIBUTING.md @@ -59,5 +59,4 @@ yarn test:static-release yarn package ``` -The static release will be in `./release-static` and the release packages -(.deb, .rpm, self contained release) in `./release-packages`. +The static release will be in `./release-static` and .deb, .rpm and self-contained release in `./release-packages`. diff --git a/package.json b/package.json index 87696289b..246db4c78 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,8 @@ "scripts": { "clean": "./ci/build/clean.sh", "vscode": "./ci/dev/vscode.sh", - "vscode:patch": "cd ./lib/vscode && git apply ../../ci/dev/vscode.patch", - "vscode:diff": "cd ./lib/vscode && git diff HEAD > ../../ci/dev/vscode.patch", + "vscode:patch": "./ci/dev/patch-vscode.sh", + "vscode:diff": "./ci/dev/diff-vscode.sh", "build": "./ci/build/build-code-server.sh", "build:vscode": "./ci/build/build-vscode.sh", "release": "./ci/build/build-release.sh", From d30f3dbdf7c2b0f0501a85b466eda8ac588483a7 Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Wed, 13 May 2020 02:37:25 -0400 Subject: [PATCH 06/27] Update to rc.10 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 246db4c78..a9312f03c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "code-server", "license": "MIT", - "version": "3.3.0-rc.7", + "version": "3.3.0-rc.10", "description": "Run VS Code on a remote server.", "homepage": "https://github.com/cdr/code-server", "bugs": { From b3ae4d67d3bd3ed7b22b102b16ecd440391ddcb5 Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Wed, 13 May 2020 04:17:34 -0400 Subject: [PATCH 07/27] Hide bundled node_modules to prevent them from being ignored --- README.md | 4 ++-- ci/README.md | 3 +++ ci/build/build-release.sh | 24 +++++++++++++++++------- ci/build/npm-postinstall.sh | 21 +++++++++++++++++++++ package.json | 2 +- 5 files changed, 44 insertions(+), 10 deletions(-) create mode 100755 ci/build/npm-postinstall.sh diff --git a/README.md b/README.md index d0a95abcc..093026946 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ For a proper setup and walkthrough, please see [./doc/guide.md](./doc/guide.md). ```bash curl -sSOL https://github.com/cdr/code-server/releases/download/3.3.0/code-server_3.3.0_amd64.deb sudo dpkg -i code-server_3.3.0_amd64.deb -sudo systemctl enable --now code-server +systemctl --user enable --now code-server # Now visit http://127.0.0.1:8080. Your password is in ~/.config/code-server/config.yaml ``` @@ -29,7 +29,7 @@ sudo systemctl enable --now code-server ```bash curl -sSOL https://github.com/cdr/code-server/releases/download/3.3.0/code-server-3.3.0-amd64.rpm sudo yum install -y code-server-3.3.0-amd64.rpm -sudo systemctl enable --now code-server +systemctl --user enable --now code-server # Now visit http://127.0.0.1:8080. Your password is in ~/.config/code-server/config.yaml ``` diff --git a/ci/README.md b/ci/README.md index dc3e0da50..892a2bf1d 100644 --- a/ci/README.md +++ b/ci/README.md @@ -90,6 +90,9 @@ You can disable minification by setting `MINIFY=`. - Downloads the release-package artifacts for the current commit from CI - Uses [hub](https://github.com/github/hub) to upload the artifacts to the release specified in `package.json` +- [./build/npm-postinstall.sh](./build/npm-postinstall.sh) + - Post install script for the npm package + - Bundled by`yarn release` ## release-container diff --git a/ci/build/build-release.sh b/ci/build/build-release.sh index 0c1117e41..583fc50de 100755 --- a/ci/build/build-release.sh +++ b/ci/build/build-release.sh @@ -32,19 +32,20 @@ bundle_code_server() { mkdir -p "$RELEASE_PATH/src/browser/pages" rsync src/browser/pages/*.html "$RELEASE_PATH/src/browser/pages" - rsync yarn.lock "$RELEASE_PATH" - # Adds the commit to package.json jq --slurp '.[0] * .[1]' package.json <( cat << EOF { "commit": "$(git rev-parse HEAD)", "scripts": { - "postinstall": "cd lib/vscode && npm rebuild # Builds native modules" + "postinstall": "./postinstall.sh" } } EOF ) > "$RELEASE_PATH/package.json" + rsync yarn.lock "$RELEASE_PATH" + rsync ci/build/npm-postinstall.sh "$RELEASE_PATH/postinstall.sh" + } bundle_vscode() { @@ -72,13 +73,22 @@ EOF yarn --production --ignore-scripts popd - # Now we clear any native module builds. - local nativeModules - mapfile -t nativeModules < <(find "$VSCODE_OUT_PATH/node_modules" -name "binding.gyp" -exec dirname {} \;) + # We clear any native module builds. + local native_modules + mapfile -t native_modules < <(find "$VSCODE_OUT_PATH/node_modules" -name "binding.gyp" -exec dirname {} \;) local nm - for nm in "${nativeModules[@]}"; do + for nm in "${native_modules[@]}"; do rm -R "$nm/build" done + + # We have to rename node_modules to node_modules.bundled to avoid them being ignored by yarn. + local node_modules + mapfile -t node_modules < <(find "$VSCODE_OUT_PATH" -depth -name "node_modules") + local nm + for nm in "${node_modules[@]}"; do + rm -Rf "$nm.bundled" + mv "$nm" "$nm.bundled" + done } main "$@" diff --git a/ci/build/npm-postinstall.sh b/ci/build/npm-postinstall.sh new file mode 100755 index 000000000..2b37bd1de --- /dev/null +++ b/ci/build/npm-postinstall.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env sh +set -eu + +main() { + cd lib/vscode + + # We have to rename node_modules.bundled to node_modules. + # The bundled modules were renamed originally to avoid being ignored by yarn. + local node_modules + node_modules="$(find . -depth -name "node_modules.bundled")" + local nm + for nm in $node_modules; do + rm -Rf "${nm%.bundled}" + mv "$nm" "${nm%.bundled}" + done + + # Rebuilds native modules. + npm rebuild +} + +main "$@" diff --git a/package.json b/package.json index a9312f03c..8e0d820bc 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "code-server", "license": "MIT", - "version": "3.3.0-rc.10", + "version": "3.3.0-rc.21", "description": "Run VS Code on a remote server.", "homepage": "https://github.com/cdr/code-server", "bugs": { From f4a78587b066d82b99491b6d7800fee5904e0fef Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Wed, 13 May 2020 05:06:11 -0400 Subject: [PATCH 08/27] Make npm-postinstall.sh more robust --- README.md | 4 ++-- ci/build/npm-postinstall.sh | 22 +++++++++++++++++++--- ci/steps/release-static.sh | 3 +++ package.json | 2 +- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 093026946..d1e670a18 100644 --- a/README.md +++ b/README.md @@ -35,8 +35,8 @@ systemctl --user enable --now code-server ### npm -**note:** Installing via `npm` requires building native module dependencies. See [./doc/npm.md](./doc/npm.md) -for the dependency install process depending on your OS. +**note:** Installing via `npm` requires certain dependencies for the native module builds. +See [./doc/npm.md](./doc/npm.md) for installing these dependencies. ```bash npm install -g code-server diff --git a/ci/build/npm-postinstall.sh b/ci/build/npm-postinstall.sh index 2b37bd1de..6f0df6a8f 100755 --- a/ci/build/npm-postinstall.sh +++ b/ci/build/npm-postinstall.sh @@ -4,18 +4,34 @@ set -eu main() { cd lib/vscode + case "${npm_config_user_agent-}" in npm*) + # We are running under npm. + if [ "${npm_config_unsafe_perm-}" != "true" ]; then + echo "Please pass --unsafe-perm to npm to install code-server" + echo "Otherwise the postinstall script does not have permissions to run" + echo "See https://docs.npmjs.com/misc/config#unsafe-perm" + echo "See https://stackoverflow.com/questions/49084929/npm-sudo-global-installation-unsafe-perm" + exit 1 + fi + ;; + esac + # We have to rename node_modules.bundled to node_modules. # The bundled modules were renamed originally to avoid being ignored by yarn. - local node_modules node_modules="$(find . -depth -name "node_modules.bundled")" - local nm for nm in $node_modules; do rm -Rf "${nm%.bundled}" mv "$nm" "${nm%.bundled}" done + # $npm_config_global makes npm rebuild return without rebuilding. + unset npm_config_global # Rebuilds native modules. - npm rebuild + if ! npm rebuild; then + echo "You may not have the required dependencies to build the native modules." + echo "Please see https://github.com/cdr/code-server/blob/master/doc/npm.md" + exit 1 + fi } main "$@" diff --git a/ci/steps/release-static.sh b/ci/steps/release-static.sh index 63c1b7788..cd2514e77 100755 --- a/ci/steps/release-static.sh +++ b/ci/steps/release-static.sh @@ -4,6 +4,9 @@ set -euo pipefail main() { cd "$(dirname "$0")/../.." + # https://github.com/actions/upload-artifact/issues/38 + chmod +x $(grep -rl '^#!/.\+' release) + yarn release:static yarn test:static-release yarn package diff --git a/package.json b/package.json index 8e0d820bc..aed1e9d6b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "code-server", "license": "MIT", - "version": "3.3.0-rc.21", + "version": "3.3.0-rc.24", "description": "Run VS Code on a remote server.", "homepage": "https://github.com/cdr/code-server", "bugs": { From a0a77e379ecd7b929850d28ec445cd5778f8d228 Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Thu, 14 May 2020 03:17:17 -0400 Subject: [PATCH 09/27] Add doc/guide.md --- README.md | 3 + ci/README.md | 18 +-- ci/dev/fmt.sh | 3 + doc/FAQ.md | 116 ++++++++++------- doc/guide.md | 236 ++++++++++++++++++++++++++++++++++ package.json | 3 +- src/browser/pages/vscode.html | 2 +- src/browser/register.ts | 2 +- src/node/util.ts | 11 +- src/node/wrapper.ts | 2 +- yarn.lock | 215 +++++++++++++++++++++++++++++-- 11 files changed, 537 insertions(+), 74 deletions(-) create mode 100644 doc/guide.md diff --git a/README.md b/README.md index d1e670a18..02866778b 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,9 @@ systemctl --user enable --now code-server ### npm +We recommend installing from `npm` if we don't have a precompiled release for your machine's +platform or architecture. + **note:** Installing via `npm` requires certain dependencies for the native module builds. See [./doc/npm.md](./doc/npm.md) for installing these dependencies. diff --git a/ci/README.md b/ci/README.md index 892a2bf1d..c21adceb2 100644 --- a/ci/README.md +++ b/ci/README.md @@ -10,19 +10,19 @@ Any file and directory added into this tree should be documented here. Make sure you have `$GITHUB_TOKEN` set and [hub](https://github.com/github/hub) installed. -1. Update the version of code-server in `package.json` and README.md install examples and push a commit -1. GitHub actions will generate the `npm-package` and `release-packages` artifacts -1. Run `yarn release:github-draft` to create a GitHub draft release from the template with +1. Update the version of code-server in `package.json` and README.md/guide.md install examples and push a commit +2. GitHub actions will generate the `npm-package` and `release-packages` artifacts +3. Run `yarn release:github-draft` to create a GitHub draft release from the template with the updated version. 1. Summarize the major changes in the release notes and link to the relevant issues. -1. Wait for the artifacts in step 2 to build -1. Run `yarn release:github-assets` to download the artifacts and then upload them to the draft release -1. Run some basic sanity tests on one of the released packages -1. Publish the release +4. Wait for the artifacts in step 2 to build +5. Run `yarn release:github-assets` to download the artifacts and then upload them to the draft release +6. Run some basic sanity tests on one of the released packages +7. Publish the release 1. CI will automatically grab the artifacts and then 1. Publish the NPM package - 1. Publish the AMD64 docker image - 1. Publish the ARM64 docker image + 2. Publish the AMD64 docker image + 3. Publish the ARM64 docker image ## dev diff --git a/ci/dev/fmt.sh b/ci/dev/fmt.sh index f7c48c41c..8e2488236 100755 --- a/ci/dev/fmt.sh +++ b/ci/dev/fmt.sh @@ -21,6 +21,9 @@ main() { ) prettier --write --loglevel=warn $(git ls-files "${prettierExts[@]}") + doctoc --title '# FAQ' doc/FAQ.md > /dev/null + doctoc --title '# Setup Guide' doc/guide.md > /dev/null + if [[ ${CI-} && $(git ls-files --other --modified --exclude-standard) ]]; then echo "Files need generation or are formatted incorrectly:" git -c color.ui=always status | grep --color=no '\[31m' diff --git a/doc/FAQ.md b/doc/FAQ.md index a43575608..087c7141d 100644 --- a/doc/FAQ.md +++ b/doc/FAQ.md @@ -1,9 +1,31 @@ + + # FAQ +- [Questions?](#questions) +- [What's the deal with extensions?](#whats-the-deal-with-extensions) +- [Where are extensions stored?](#where-are-extensions-stored) +- [How is this different from VS Code Codespaces?](#how-is-this-different-from-vs-code-codespaces) +- [How should I expose code-server to the internet?](#how-should-i-expose-code-server-to-the-internet) +- [How do I securely access web services?](#how-do-i-securely-access-web-services) + - [Sub-domains](#sub-domains) + - [Sub-paths](#sub-paths) +- [Multi Tenancy](#multi-tenancy) +- [Docker in code-server docker container?](#docker-in-code-server-docker-container) +- [Collaboration](#collaboration) +- [How can I disable telemetry?](#how-can-i-disable-telemetry) +- [How does code-server decide what workspace or folder to open?](#how-does-code-server-decide-what-workspace-or-folder-to-open) +- [How do I debug issues with code-server?](#how-do-i-debug-issues-with-code-server) +- [Heartbeat file](#heartbeat-file) +- [Enterprise](#enterprise) + + + ## Questions? -Please file all questions and support requests at https://www.reddit.com/r/codeserver/ -The issue tracker is only for bugs. +Please file all questions and support requests at https://www.reddit.com/r/codeserver/. + +The issue tracker is **only** for bugs. ## What's the deal with extensions? @@ -23,42 +45,53 @@ Issue [#1299](https://github.com/cdr/code-server/issues/1299) is a big one in ma better by allowing the community to submit extensions and repos to avoid waiting until the scraper finds an extension. -If an extension does not work, try to grab its VSIX from its Github releases or build it yourself and -copy it to the extensions folder. +If an extension is not available or does not work, you can grab its VSIX from its Github releases or +build it yourself and [Install from VSIX](https://code.visualstudio.com/docs/editor/extension-gallery#_install-from-a-vsix). -## How is this different from VS Code Online? +Feel free to file an issue to add a missing extension to the marketplace. -VS Code Online is a closed source managed service by Microsoft and only runs on Azure. +## Where are extensions stored? -code-server is open source and can be freely run on any machine. +Defaults to `~/.local/share/code-server/extensions`. + +If the `XDG_DATA_HOME` environment variable is set the data directory will be +`$XDG_DATA_HOME/code-server/extensions`. + +You can install an extension on the CLI with: + +```bash +# From the Coder extension marketplace +code-server --install-extension ms-python.python + +# From a downloaded VSIX on the file system +code-server --install-extension downloaded-ms-python.python.vsix +``` + +## How is this different from VS Code Codespaces? + +VS Code Codespaces is a closed source and paid service by Microsoft. It also allows you to access +VS Code via the browser. + +However, code-server is free, open source and can be ran on any machine without any limitations. + +While you can self host environments with VS Code Codespaces, you still need to an Azure billing +account and you access VS Code via the Codespaces web dashboard instead of directly connecting to +your instance. ## How should I expose code-server to the internet? -By far the most secure method of using code-server is via -[sshcode](https://github.com/codercom/sshcode) as it runs code-server and then forwards -its port over SSH and requires no setup on your part other than having a working SSH server. +Please follow [./guide.md]](./guide.md) for our recommendations on setting up and using code-server. -You can also forward your SSH key and GPG agent to the remote machine to securely access GitHub -and securely sign commits without duplicating your keys onto the the remote machine. - -1. https://developer.github.com/v3/guides/using-ssh-agent-forwarding/ -1. https://wiki.gnupg.org/AgentForwarding - -If you cannot use sshcode, then you will need to ensure there is some sort of authorization in -front of code-server and that you are using HTTPS to secure all connections. - -By default when listening externally, code-server enables password authentication using a -randomly generated password so you can use that. You can set the `PASSWORD` environment variable -to use your own instead. If you want to handle authentication yourself, use `--auth none` -to disable password authentication. +code-server only supports password authentication natively. **note**: code-server will rate limit password authentication attempts at 2 a minute and 12 an hour. -If you want to use external authentication you should handle this with a reverse -proxy using something like [oauth2_proxy](https://github.com/pusher/oauth2_proxy). +If you want to use external authentication (i.e sign in with Google) you should handle this +with a reverse proxy using something like [oauth2_proxy](https://github.com/pusher/oauth2_proxy). -For HTTPS, you can use a self signed certificate by passing in just `--cert` or pass in an existing -certificate by providing the path to `--cert` and the path to its key with `--cert-key`. +For HTTPS, you can use a self signed certificate by passing in just `--cert` or +pass in an existing certificate by providing the path to `--cert` and the path to +its key with `--cert-key`. If `code-server` has been passed a certificate it will also respond to HTTPS requests and will redirect all HTTP requests to HTTPS. Otherwise it will respond @@ -67,6 +100,8 @@ only to HTTP requests. You can use [Let's Encrypt](https://letsencrypt.org/) to get an SSL certificate for free. +Again, Please follow [./guide.md]](./guide.md) for our recommendations on setting up and using code-server. + ## How do I securely access web services? code-server is capable of proxying to any port using either a subdomain or a @@ -96,15 +131,6 @@ ensure your reverse proxy forwards that information if you are using one. Just browse to `/proxy//`. -## x86 releases? - -node has dropped support for x86 and so we decided to as well. See -[nodejs/build/issues/885](https://github.com/nodejs/build/issues/885). - -## Alpine builds? - -Just install `libc-dev` and code-server should work. - ## Multi Tenancy If you want to run multiple code-server's on shared infrastructure, we recommend using virtual @@ -127,8 +153,9 @@ to make volume mounts in any other directory work. ## Collaboration -At the moment we have no plans for multi user collaboration on code-server but we understand there is strong -demand and will work on it when the time is right. +We understand the high demand but the team is swamped right now. + +You can follow progress at [#33](https://github.com/cdr/code-server/issues/33). ## How can I disable telemetry? @@ -165,13 +192,16 @@ information from the following places: Additionally, collecting core dumps (you may need to enable them first) if code-server crashes can be helpful. -### Where is the data directory? +## Heartbeat file -If the `XDG_DATA_HOME` environment variable is set the data directory will be -`$XDG_DATA_HOME/code-server`. Otherwise: +`code-server` touches `~/.local/share/code-server/heartbeat` once a minute as long +as there is an active browser connection. -1. Unix: `~/.local/share/code-server` -1. Windows: `%APPDATA%\Local\code-server\Data` +If you want to shutdown `code-server` if there hasn't been an active connection in X minutes +you can do so by continously checking the last modified time on the heartbeat file and if it is +older than X minutes, you should kill `code-server`. + +[#1636](https://github.com/cdr/code-server/issues/1636) will make the experience here better. ## Enterprise diff --git a/doc/guide.md b/doc/guide.md new file mode 100644 index 000000000..2cc036305 --- /dev/null +++ b/doc/guide.md @@ -0,0 +1,236 @@ + + +# Setup Guide + +- [1. Acquire a remote machine](#1-acquire-a-remote-machine) + - [Requirements](#requirements) + - [Google Cloud Platform](#google-cloud-platform) +- [2. Install code-server](#2-install-code-server) +- [3. Expose code-server](#3-expose-code-server) + - [SSH forwarding](#ssh-forwarding) + - [Let's Encrypt](#lets-encrypt) + - [Self Signed Certificate](#self-signed-certificate) + - [Change the password?](#change-the-password) + - [How do I securely access development web services?](#how-do-i-securely-access-development-web-services) + + + +This guide demonstrates how to setup and use code-server. +To reiterate, code-server lets you run VS Code on a remote server and then access it via a browser. + +See the [README](../README.md) for a general overview and the [FAQ](./FAQ.md) for further user docs. + +We'll walk you through acquiring a remote machine to run code-server on and then exposing `code-server` so you can +easily access it. + +## 1. Acquire a remote machine + +First, you need a machine to run code-server on. You can use a physical +machine you have lying around or use a VM on GCP/AWS. + +### Requirements + +For a good experience, we recommend at least: + +- 1 GB of RAM +- 2 cores + +You can use whatever linux distribution floats your boat but in this guide we assume Debian. + +### Google Cloud Platform + +For demonstration purposes, this guide assumes you're using a VM on GCP but you should be +able to easily use any machine or VM provider. + +You can sign up at https://console.cloud.google.com/getting-started. You'll get a 12 month \$300 +free trial. + +Once you've signed up and created a GCP project, create a new Compute Engine VM Instance. + +1. Navigate to `Compute Engine -> VM Instances` on the sidebar +2. Now click `Create Instance` to create a new instance +3. Choose the region closest to you based on [gcping.com](http://www.gcping.com) +4. Name it whatever you want +5. Any zone is fine +6. We'd recommend a `e2-standard-2` instance from the E2 series and General-purpose family + - Add more vCPUs and memory as you prefer, you can edit after creating the instance as well + - https://cloud.google.com/compute/docs/machine-types#general_purpose +7. We highly recommend switching the persistent disk to a SSD of at least 32 GB +8. Navigate to `Networking -> Network interfaces` and edit the existing interface + to use a static external IP + - Click done to save network interface changes +9. If you do not have a [project wide SSH key](https://cloud.google.com/compute/docs/instances/adding-removing-ssh-keys#project-wide), navigate to `Security - > SSH Keys` and add your public key there +10. Click create! + +Remember, you can shutdown your server when not in use to lower costs. +We highly recommend learning to use the [`gcloud`](https://cloud.google.com/sdk/gcloud) cli +to avoid the slow dashboard. + +## 2. Install code-server + +SSH into your instance and run the appropriate commands documented in [README.md](../README.md). + +Assuming Debian: + +```bash +curl -sSOL https://github.com/cdr/code-server/releases/download/3.3.0/code-server_3.3.0_amd64.deb +sudo dpkg -i code-server_3.3.0_amd64.deb +systemctl --user enable --now code-server +# Now code-server is running at http://127.0.0.1:8080 +# Your password is in ~/.config/code-server/config.yaml +``` + +## 3. Expose code-server + +There are several approaches to operating and exposing code-server. + +Since you can gain access to a terminal from within code-server, **never**, **ever** +expose it directly to the internet without some form of authentication and encryption! + +By default, code-server will enable password authentication which will +require you to copy the password from the code-server config file to login. You +can also set a custom password with `$PASSWORD`. + +**tip**: You can list the full set of code-server options with `code-server --help` + +### SSH forwarding + +We highly recommend this approach for not requiring any additional setup, you just need an +SSH server on your remote machine. The downside is you won't be able to access `code-server` +without an SSH client like an iPad. If that's important to you, skip to [Let's Encrypt](#lets-encrypt). + +Recommended reading: https://help.ubuntu.com/community/SSH/OpenSSH/PortForwarding + +```bash +# -N disables executing a remote shell +ssh -N -L 8080:127.0.0.1:8080 +``` + +As long as this command hasn't exited, that means any request on local port 8080 goes to your +instance at `127.0.0.1:8080` which is where code-server is running. + +Next ssh into your instance and edit your code-server config file to disable password authentication. + +```bash +# Replaces "auth: password" with "auth: none" in the code-server config. +sed -i.bak 's/auth: password/auth: none/' ~/.config/code-server/config.yaml +``` + +Restart code-server with (assuming you followed the guide): + +```bash +systemctl --user restart code-server +``` + +Now if you access http://127.0.0.1:8080 locally, you should see code-server! + +If you want to make the SSH port forwarding persistent we recommend using +[mutagen](https://mutagen.io/documentation/introduction/installation). + +``` +# Same as the above SSH command but runs in the background continously. +# Add `mutagen daemon start` to your ~/.bashrc to start the mutagen daemon when you open a shell. +mutagen forward create --help -n=code-server tcp:127.0.0.1:8080 :tcp:127.0.0.1:8080 +``` + +We also recommend adding the following lines to your `~/.ssh/config` to quickly detect bricked SSH connections: + +```bash +Host * +ServerAliveInterval 5 +ExitOnForwardFailure yes +``` + +You can also forward your SSH key and GPG agent to the instance to securely access GitHub +and sign commits without copying your keys onto the instance. + +1. https://developer.github.com/v3/guides/using-ssh-agent-forwarding/ +2. https://wiki.gnupg.org/AgentForwarding + +### Let's Encrypt + +Let's Encrypt is a great option if you want to access code-server on an iPad or just want password +based authentication. This does require that the remote machine is exposed to the internet. + +Assuming you have been following the guide, edit your instance and checkmark the allow HTTP/HTTPS traffic options. + +1. You'll need to buy a domain name. We recommend [Google Domains](https://domains.google.com) +2. Add an A record to your domain with your instance's IP +3. Install caddy https://caddyserver.com/docs/download#debian-ubuntu-raspbian + +```bash +echo "deb [trusted=yes] https://apt.fury.io/caddy/ /" \ + | sudo tee -a /etc/apt/sources.list.d/caddy-fury.list +sudo apt update +sudo apt install caddy +``` + +4. Replace `/etc/caddy/Caddyfile` with sudo to look like this: + +``` +mydomain.com + +reverse_proxy 127.0.0.1:8080 +``` + +5. Reload caddy with: + +```bash +sudo systemctl reload caddy +``` + +Visit `https://` to access code-server. Congratulations! + +In a future release we plan to integrate Let's Encrypt directly with code-server to avoid +the dependency on caddy. + +### Self Signed Certificate + +**note:** Self signed certificates do not work with iPad and will cause a blank page. You'll +have to use [Let's Encrypt](#lets-encrypt) instead. + +Recommended reading: https://security.stackexchange.com/a/8112 + +We recommend this as a last resort as self signed certificates do not work with iPads and can +cause other bizarre issues. Not to mention all the warnings when you access code-server. +Only use this if you do not want to buy a domain or cannot expose the remote machine to the internet. + +ssh into your instance and edit your code-server config file to use a randomly generated self signed certificate: + +```bash +# Replaces "cert: false" with "cert: true" in the code-server config. +sed -i.bak 's/cert: false/cert: true/' ~/.config/code-server/config.yaml +# Replaces "bind-addr: 127.0.0.1:8080" with "bind-addr: 0.0.0.0:443" in the code-server config. +sed -i.bak 's/bind-addr: 127.0.0.1:8080/bind-addr: 0.0.0.0:443/' ~/.config/code-server/config.yaml +# Allows code-server to listen on port 443. +sudo setcap cap_net_bind_service=+ep /usr/lib/code-server/lib/node +``` + +Assuming you have been following the guide, restart code-server with: + +```bash +systemctl --user restart code-server +``` + +Edit your instance and checkmark the allow HTTPS traffic option. + +Visit `https://` to access code-server. +You'll get a warning when accessing but if you click through you should be good. + +You can also use [mkcert](https://mkcert.dev) to create a self signed certificate trusted by your +OS to avoid the warnings. + +### Change the password? + +Edit the code-server config file at `~/.config/code-server/config.yaml` and then restart +code-server with: + +```bash +systemctl --user restart code-server +``` + +### How do I securely access development web services? + +If you're working on a web service and want to access it locally, code-server can proxy it for you. + +See the [FAQ](https://github.com/cdr/code-server/blob/master/doc/FAQ.md#how-do-i-securely-access-web-services). diff --git a/package.json b/package.json index aed1e9d6b..713f6be8d 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ "@types/ws": "^6.0.4", "@typescript-eslint/eslint-plugin": "^2.0.0", "@typescript-eslint/parser": "^2.0.0", + "doctoc": "^1.4.0", "eslint": "^6.2.0", "eslint-config-prettier": "^6.0.0", "eslint-plugin-import": "^2.18.2", @@ -52,7 +53,7 @@ "leaked-handles": "^5.2.0", "mocha": "^6.2.0", "parcel-bundler": "^1.12.4", - "prettier": "^1.18.2", + "prettier": "^2.0.5", "stylelint": "^13.0.0", "stylelint-config-recommended": "^3.0.0", "ts-node": "^8.4.1", diff --git a/src/browser/pages/vscode.html b/src/browser/pages/vscode.html index abfb102c2..72c39824f 100644 --- a/src/browser/pages/vscode.html +++ b/src/browser/pages/vscode.html @@ -98,7 +98,7 @@ END_PROD_ONLY -->