Skip to content

Commit 2b2aa9a

Browse files
committed
Add https server
1 parent 81862d4 commit 2b2aa9a

20 files changed

Lines changed: 405 additions & 186 deletions

.travis.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,14 @@ matrix:
88
- os: linux
99
dist: trusty
1010
env:
11-
- VSCODE_VERSION="1.36.1" MAJOR_VERSION="2" VERSION="$MAJOR_VERSION.$TRAVIS_BUILD_NUMBER" TARGET="centos"
11+
- VSCODE_VERSION="1.36.1" MAJOR_VERSION="2" VERSION="$MAJOR_VERSION.$TRAVIS_BUILD_NUMBER" TARGET="linux"
1212
- os: linux
1313
dist: trusty
1414
env:
1515
- VSCODE_VERSION="1.36.1" MAJOR_VERSION="2" VERSION="$MAJOR_VERSION.$TRAVIS_BUILD_NUMBER" TARGET="alpine"
1616
- os: osx
1717
env:
1818
- VSCODE_VERSION="1.36.1" MAJOR_VERSION="2" VERSION="$MAJOR_VERSION.$TRAVIS_BUILD_NUMBER"
19-
before_install:
20-
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install -y libxkbfile-dev libsecret-1-dev; fi
21-
- npm install -g yarn@1.12.3
22-
- npm install -g @coder/nbin
2319
script:
2420
- scripts/ci.bash
2521
before_deploy:

main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
require("../../bootstrap-amd").load("vs/server/cli");
1+
require("../../bootstrap-amd").load("vs/server/src/cli");

package.json

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
11
{
22
"license": "MIT",
33
"scripts": {
4-
"preinstall": "cd ../../../ && yarn",
5-
"postinstall": "rm -rf node_modules/@types/node # I keep getting type conflicts",
6-
"start": "nodemon ../../../out/vs/server/main.js --watch ../../../out --verbose",
7-
"watch": "cd ../../../ && yarn watch",
4+
"ensure-in-vscode": "bash ./scripts/tasks.bash ensure-in-vscode",
5+
"preinstall": "yarn ensure-in-vscode && cd ../../../ && yarn || true",
6+
"postinstall": "rm -rf node_modules/@types/node",
7+
"start": "yarn ensure-in-vscode && nodemon ../../../out/vs/server/main.js --watch ../../../out --verbose",
8+
"watch": "yarn ensure-in-vscode && cd ../../../ && yarn watch",
89
"build": "bash ./scripts/tasks.bash build",
910
"package": "bash ./scripts/tasks.bash package",
1011
"vstar": "bash ./scripts/tasks.bash vstar",
1112
"binary": "bash ./scripts/tasks.bash binary",
12-
"patch:generate": "cd ../../../ && git diff --staged > ./src/vs/server/scripts/vscode.patch",
13-
"patch:apply": "cd ../../../ && git apply ./src/vs/server/scripts/vscode.patch"
13+
"patch:generate": "yarn ensure-in-vscode && cd ../../../ && git diff --staged > ./src/vs/server/scripts/vscode.patch",
14+
"patch:apply": "yarn ensure-in-vscode && cd ../../../ && git apply ./src/vs/server/scripts/vscode.patch"
1415
},
1516
"devDependencies": {
17+
"@types/pem": "^1.9.5",
18+
"@types/safe-compare": "^1.1.0",
1619
"@types/tar-stream": "^1.6.1",
1720
"nodemon": "^1.19.1"
1821
},
19-
"dependencies": {
20-
"tar-stream": "^2.1.0"
21-
},
2222
"resolutions": {
2323
"@types/node": "^10.12.12"
24+
},
25+
"dependencies": {
26+
"httpolyglot": "^0.1.2",
27+
"pem": "^1.14.2",
28+
"safe-compare": "^1.1.4"
2429
}
2530
}

scripts/ci.bash

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,21 @@ set -euo pipefail
33

44
# Build using a Docker container.
55
function docker-build() {
6+
local image="codercom/nbin-${target}"
7+
if [[ "${target}" == "linux" ]] ; then
8+
image="codercom/nbin-centos"
9+
fi
10+
611
local containerId
712
containerId=$(docker create --network=host --rm -it -v "$(pwd)"/.cache:/src/.cache "${image}")
813
docker start "${containerId}"
914
docker exec "${containerId}" mkdir -p /src
1015

16+
# TODO: temporary as long as we are rebuilding modules.
17+
if [[ "${image}" == "codercom/nbin-alpine" ]] ; then
18+
docker exec "${containerId}" apk add libxkbfile-dev libsecret-dev
19+
fi
20+
1121
function docker-exec() {
1222
local command="${1}" ; shift
1323
local args="'${codeServerVersion}' '${vscodeVersion}' '${target}' '${arch}'"
@@ -57,14 +67,6 @@ function main() {
5767
target=darwin
5868
local-build
5969
else
60-
local image
61-
if [[ "${target}" == alpine ]]; then
62-
image=codercom/nbin-alpine
63-
target=musl
64-
else
65-
image=codercom/nbin-centos
66-
target=linux
67-
fi
6870
docker-build
6971
fi
7072
}

scripts/tasks.bash

Lines changed: 98 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,39 +20,55 @@ function exit-if-ci() {
2020

2121
# Copy code-server into VS Code along with its dependencies.
2222
function copy-server() {
23+
log "Applying patch"
24+
cd "${vscodeSourcePath}"
25+
git reset --hard
26+
git clean -fd
27+
git apply "${rootPath}/scripts/vscode.patch"
28+
2329
local serverPath="${vscodeSourcePath}/src/vs/server"
2430
rm -rf "${serverPath}"
2531
mkdir -p "${serverPath}"
2632

27-
log "Copying server code"
33+
log "Copying code-server code"
2834

29-
cp "${rootPath}"/*.{ts,js} "${serverPath}"
35+
cp -r "${rootPath}/src" "${serverPath}"
36+
cp -r "${rootPath}/typings" "${serverPath}"
37+
cp "${rootPath}/main.js" "${serverPath}"
3038
cp "${rootPath}/package.json" "${serverPath}"
3139
cp "${rootPath}/yarn.lock" "${serverPath}"
3240

3341
if [[ -d "${rootPath}/node_modules" ]] ; then
34-
log "Copying dependencies"
42+
log "Copying code-server build dependencies"
3543
cp -r "${rootPath}/node_modules" "${serverPath}"
3644
else
37-
log "Installing dependencies"
45+
log "Installing code-server build dependencies"
3846
cd "${serverPath}"
3947
# Ignore scripts to avoid also installing VS Code dependencies which has
4048
# already been done.
4149
yarn --ignore-scripts
4250
rm -r node_modules/@types/node # I keep getting type conflicts
4351
fi
52+
53+
# TODO: Duplicate identifier issue. There must be a better way to fix this.
54+
if [[ "${target}" == "darwin" ]] ; then
55+
rm "${serverPath}/node_modules/fsevents/node_modules/safe-buffer/index.d.ts"
56+
fi
4457
}
4558

46-
# Prepend the nbin loading code which allows the code to find files within
47-
# the binary.
59+
# Prepend the nbin shim which enables finding files within the binary.
4860
function prepend-loader() {
4961
local filePath="${codeServerBuildPath}/${1}" ; shift
50-
cat "${rootPath}/scripts/nbin-loader.js" "${filePath}" > "${filePath}.temp"
62+
cat "${rootPath}/scripts/nbin-shim.js" "${filePath}" > "${filePath}.temp"
5163
mv "${filePath}.temp" "${filePath}"
5264
# Using : as the delimiter so the escaping here is easier to read.
5365
# ${parameter/pattern/string}, so the pattern is /: (if the pattern starts
5466
# with / it matches all instances) and the string is \\: (results in \:).
55-
sed -i "s:{{ROOT_PATH}}:${codeServerBuildPath//:/\\:}:g" "${filePath}"
67+
if [[ "${target}" == "darwin" ]] ; then
68+
sed -i "" -e "s:{{ROOT_PATH}}:${codeServerBuildPath//:/\\:}:g" "${filePath}"
69+
else
70+
sed -i "s:{{ROOT_PATH}}:${codeServerBuildPath//:/\\:}:g" "${filePath}"
71+
fi
5672
}
5773

5874
# Copy code-server into VS Code then build it.
@@ -63,10 +79,7 @@ function build-code-server() {
6379
# (basically just want to skip extensions, target our server code, and get
6480
# the same type of build you get with the vscode-linux-x64-min task).
6581
# Something like: yarn gulp "vscode-server-${target}-${arch}-min"
66-
cd "${vscodeSourcePath}"
67-
git reset --hard
68-
git clean -fd
69-
git apply "${rootPath}/scripts/vscode.patch"
82+
log "Building code-server"
7083
yarn gulp compile-client
7184

7285
rm -rf "${codeServerBuildPath}"
@@ -78,9 +91,22 @@ function build-code-server() {
7891
node "${rootPath}/scripts/merge.js" "${vscodeBuildPath}/resources/app/package.json" "${rootPath}/scripts/package.json" "${codeServerBuildPath}/package.json" "${json}"
7992
node "${rootPath}/scripts/merge.js" "${vscodeBuildPath}/resources/app/product.json" "${rootPath}/scripts/product.json" "${codeServerBuildPath}/product.json"
8093
cp -r "${vscodeSourcePath}/out" "${codeServerBuildPath}"
81-
rm -rf "${codeServerBuildPath}/out/vs/server/node_modules"
94+
rm -rf "${codeServerBuildPath}/out/vs/server/typings"
95+
96+
# Rebuild to make sure the native modules work since at the moment all the
97+
# pre-built packages are from one Linux system. This means you must build on
98+
# the target system.
99+
log "Installing remote dependencies"
100+
cd "${vscodeSourcePath}/remote"
101+
if [[ "${target}" != "linux" ]] ; then
102+
yarn --production --force
103+
fi
82104
cp -r "${vscodeSourcePath}/remote/node_modules" "${codeServerBuildPath}"
83105

106+
# Only keep the production dependencies.
107+
cd "${codeServerBuildPath}/out/vs/server"
108+
yarn --production --ignore-scripts
109+
84110
prepend-loader "out/vs/server/main.js"
85111
prepend-loader "out/bootstrap-fork.js"
86112

@@ -105,11 +131,9 @@ function build-vscode() {
105131
if [[ ! -d "${vscodeSourcePath}/node_modules" ]] ; then
106132
exit-if-ci
107133
log "Installing VS Code dependencies"
108-
yarn
109-
# Not entirely sure why but there seem to be problems with native modules.
110-
# Also vscode-ripgrep keeps complaining after the rebuild that the
111-
# node_modules directory doesn't exist, so we're ignoring that for now.
112-
npm rebuild || true
134+
# Not entirely sure why but there seem to be problems with native modules
135+
# so rebuild them.
136+
yarn --force
113137

114138
# Keep just what we need to keep the pre-built archive smaller.
115139
rm -rf "${vscodeSourcePath}/test"
@@ -138,7 +162,7 @@ function download-vscode() {
138162
cd "${buildPath}"
139163
if command -v wget &> /dev/null ; then
140164
log "Attempting to download ${tarName} with wget"
141-
wget "${vsSourceUrl}" --quiet
165+
wget "${vsSourceUrl}" --quiet --output-document "${tarName}"
142166
else
143167
log "Attempting to download ${tarName} with curl"
144168
curl "${vsSourceUrl}" --silent --fail --output "${tarName}"
@@ -152,13 +176,20 @@ function download-vscode() {
152176
function prepare-vscode() {
153177
if [[ ! -d "${vscodeBuildPath}" || ! -d "${vscodeSourcePath}" ]] ; then
154178
mkdir -p "${buildPath}"
179+
# TODO: for now everything uses the Linux build and we rebuild the modules.
180+
# This means you must build on the target system.
155181
local tarName="vstar-${vscodeVersion}-${target}-${arch}.tar.gz"
156-
local vsSourceUrl="https://codesrv-ci.cdr.sh/${tarName}"
182+
local linuxTarName="vstar-${vscodeVersion}-linux-${arch}.tar.gz"
183+
local linuxVscodeBuildName="vscode-${vscodeVersion}-linux-${arch}-built"
184+
local vsSourceUrl="https://codesrv-ci.cdr.sh/${linuxTarName}"
157185
if download-vscode ; then
158186
cd "${buildPath}"
159187
rm -rf "${vscodeBuildPath}"
160188
tar -xzf "${tarName}"
161189
rm "${tarName}"
190+
if [[ "${target}" != "linux" ]] ; then
191+
mv "${linuxVscodeBuildName}" "${vscodeBuildName}"
192+
fi
162193
elif [[ -n "${ci}" ]] ; then
163194
log "Pre-built VS Code ${vscodeVersion}-${target}-${arch} does not exist" "error"
164195
exit 1
@@ -199,12 +230,12 @@ function package-task() {
199230
cp "${vscodeSourcePath}/ThirdPartyNotices.txt" "${archivePath}"
200231

201232
cd "${releasePath}"
202-
if [[ "${target}" == "linux" ]] ; then
203-
tar -czf "${binaryName}.tar.gz" "${binaryName}"
204-
log "Archive: ${archivePath}.tar.gz"
205-
else
233+
if [[ "${target}" == "darwin" ]] ; then
206234
zip -r "${binaryName}.zip" "${binaryName}"
207235
log "Archive: ${archivePath}.zip"
236+
else
237+
tar -czf "${binaryName}.tar.gz" "${binaryName}"
238+
log "Archive: ${archivePath}.tar.gz"
208239
fi
209240
}
210241

@@ -221,35 +252,64 @@ function binary-task() {
221252
log "Binary: ${buildPath}/${binaryName}"
222253
}
223254

255+
# Check if it looks like we are inside VS Code.
256+
function in-vscode () {
257+
log "Checking if we are inside VS Code"
258+
local dir="${1}" ; shift
259+
260+
local maybeVscode
261+
local dirName
262+
maybeVscode="$(realpath "${dir}/../../..")"
263+
dirName="$(basename "${maybeVscode}")"
264+
265+
if [[ "${dirName}" != "vscode" ]] ; then
266+
return 1
267+
fi
268+
if [[ ! -f "${maybeVscode}/package.json" ]] ; then
269+
return 1
270+
fi
271+
if ! grep '"name": "code-oss-dev"' "${maybeVscode}/package.json" --quiet ; then
272+
return 1
273+
fi
274+
275+
return 0
276+
}
277+
278+
function ensure-in-vscode-task() {
279+
if ! in-vscode "${rootPath}"; then
280+
log "Not in vscode" "error"
281+
exit 1
282+
fi
283+
exit 0
284+
}
285+
224286
function main() {
287+
local relativeRootPath
288+
local rootPath
289+
relativeRootPath="$(dirname "${0}")/.."
290+
rootPath="$(realpath "${relativeRootPath}")"
291+
225292
local task="${1}" ; shift
293+
if [[ "${task}" == "ensure-in-vscode" ]] ; then
294+
ensure-in-vscode-task
295+
fi
296+
226297
local codeServerVersion="${1}" ; shift
227298
local vscodeVersion="${1}" ; shift
228299
local target="${1}" ; shift
229300
local arch="${1}" ; shift
230301
local ci="${CI:-}"
231302

232-
local relativeRootPath
233-
local rootPath
234-
relativeRootPath="$(dirname "${0}")/.."
235-
rootPath="$(realpath "${relativeRootPath}")"
236-
237303
# This lets you build in a separate directory since building within this
238304
# directory while developing makes it hard to keep developing since compiling
239305
# will compile everything in the build directory as well.
240306
local outPath="${OUT:-${rootPath}}"
241307

242308
# If we're inside a vscode directory, assume we want to develop. In that case
243309
# we should set an OUT directory and not build in this directory.
244-
if [[ "${outPath}" == "${rootPath}" ]] ; then
245-
local maybeVscode
246-
local dirName
247-
maybeVscode="$(realpath "${outPath}/../../..")"
248-
dirName="$(basename "${maybeVscode}")"
249-
if [[ "${dirName}" == "vscode" ]] ; then
250-
log "Set the OUT environment variable to something outside ${maybeVscode}" "error"
251-
exit 1
252-
fi
310+
if in-vscode "${outPath}" ; then
311+
log "Set the OUT environment variable to something outside of VS Code" "error"
312+
exit 1
253313
fi
254314

255315
local releasePath="${outPath}/release"

channel.ts renamed to src/channel.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Emitter, Event } from "vs/base/common/event";
66
import { IDisposable } from "vs/base/common/lifecycle";
77
import { OS } from "vs/base/common/platform";
88
import { URI, UriComponents } from "vs/base/common/uri";
9-
import { URITransformer, IRawURITransformer, transformOutgoingURIs } from "vs/base/common/uriIpc";
9+
import { transformOutgoingURIs } from "vs/base/common/uriIpc";
1010
import { IServerChannel } from "vs/base/parts/ipc/common/ipc";
1111
import { IDiagnosticInfo } from "vs/platform/diagnostics/common/diagnosticsService";
1212
import { IEnvironmentService } from "vs/platform/environment/common/environment";
@@ -19,6 +19,8 @@ import { IRemoteAgentEnvironment } from "vs/platform/remote/common/remoteAgentEn
1919
import { ExtensionScanner, ExtensionScannerInput } from "vs/workbench/services/extensions/node/extensionPoints";
2020
import { DiskFileSystemProvider } from "vs/workbench/services/files/node/diskFileSystemProvider";
2121

22+
import { getUriTransformer } from "vs/server/src/util";
23+
2224
/**
2325
* Extend the file provider to allow unwatching.
2426
*/
@@ -262,11 +264,3 @@ export class ExtensionEnvironmentChannel implements IServerChannel {
262264
throw new Error("not implemented");
263265
}
264266
}
265-
266-
export const uriTransformerPath = getPathFromAmdModule(require, "vs/server/uriTransformer");
267-
268-
export const getUriTransformer = (remoteAuthority: string): URITransformer => {
269-
const rawURITransformerFactory = <any>require.__$__nodeRequire(uriTransformerPath);
270-
const rawURITransformer = <IRawURITransformer>rawURITransformerFactory(remoteAuthority);
271-
return new URITransformer(rawURITransformer);
272-
};

0 commit comments

Comments
 (0)