Add https server
This commit is contained in:
@ -3,11 +3,21 @@ set -euo pipefail
|
||||
|
||||
# Build using a Docker container.
|
||||
function docker-build() {
|
||||
local image="codercom/nbin-${target}"
|
||||
if [[ "${target}" == "linux" ]] ; then
|
||||
image="codercom/nbin-centos"
|
||||
fi
|
||||
|
||||
local containerId
|
||||
containerId=$(docker create --network=host --rm -it -v "$(pwd)"/.cache:/src/.cache "${image}")
|
||||
docker start "${containerId}"
|
||||
docker exec "${containerId}" mkdir -p /src
|
||||
|
||||
# TODO: temporary as long as we are rebuilding modules.
|
||||
if [[ "${image}" == "codercom/nbin-alpine" ]] ; then
|
||||
docker exec "${containerId}" apk add libxkbfile-dev libsecret-dev
|
||||
fi
|
||||
|
||||
function docker-exec() {
|
||||
local command="${1}" ; shift
|
||||
local args="'${codeServerVersion}' '${vscodeVersion}' '${target}' '${arch}'"
|
||||
@ -57,14 +67,6 @@ function main() {
|
||||
target=darwin
|
||||
local-build
|
||||
else
|
||||
local image
|
||||
if [[ "${target}" == alpine ]]; then
|
||||
image=codercom/nbin-alpine
|
||||
target=musl
|
||||
else
|
||||
image=codercom/nbin-centos
|
||||
target=linux
|
||||
fi
|
||||
docker-build
|
||||
fi
|
||||
}
|
||||
|
@ -20,39 +20,55 @@ function exit-if-ci() {
|
||||
|
||||
# Copy code-server into VS Code along with its dependencies.
|
||||
function copy-server() {
|
||||
log "Applying patch"
|
||||
cd "${vscodeSourcePath}"
|
||||
git reset --hard
|
||||
git clean -fd
|
||||
git apply "${rootPath}/scripts/vscode.patch"
|
||||
|
||||
local serverPath="${vscodeSourcePath}/src/vs/server"
|
||||
rm -rf "${serverPath}"
|
||||
mkdir -p "${serverPath}"
|
||||
|
||||
log "Copying server code"
|
||||
log "Copying code-server code"
|
||||
|
||||
cp "${rootPath}"/*.{ts,js} "${serverPath}"
|
||||
cp -r "${rootPath}/src" "${serverPath}"
|
||||
cp -r "${rootPath}/typings" "${serverPath}"
|
||||
cp "${rootPath}/main.js" "${serverPath}"
|
||||
cp "${rootPath}/package.json" "${serverPath}"
|
||||
cp "${rootPath}/yarn.lock" "${serverPath}"
|
||||
|
||||
if [[ -d "${rootPath}/node_modules" ]] ; then
|
||||
log "Copying dependencies"
|
||||
log "Copying code-server build dependencies"
|
||||
cp -r "${rootPath}/node_modules" "${serverPath}"
|
||||
else
|
||||
log "Installing dependencies"
|
||||
log "Installing code-server build dependencies"
|
||||
cd "${serverPath}"
|
||||
# Ignore scripts to avoid also installing VS Code dependencies which has
|
||||
# already been done.
|
||||
yarn --ignore-scripts
|
||||
rm -r node_modules/@types/node # I keep getting type conflicts
|
||||
fi
|
||||
|
||||
# TODO: Duplicate identifier issue. There must be a better way to fix this.
|
||||
if [[ "${target}" == "darwin" ]] ; then
|
||||
rm "${serverPath}/node_modules/fsevents/node_modules/safe-buffer/index.d.ts"
|
||||
fi
|
||||
}
|
||||
|
||||
# Prepend the nbin loading code which allows the code to find files within
|
||||
# the binary.
|
||||
# Prepend the nbin shim which enables finding files within the binary.
|
||||
function prepend-loader() {
|
||||
local filePath="${codeServerBuildPath}/${1}" ; shift
|
||||
cat "${rootPath}/scripts/nbin-loader.js" "${filePath}" > "${filePath}.temp"
|
||||
cat "${rootPath}/scripts/nbin-shim.js" "${filePath}" > "${filePath}.temp"
|
||||
mv "${filePath}.temp" "${filePath}"
|
||||
# Using : as the delimiter so the escaping here is easier to read.
|
||||
# ${parameter/pattern/string}, so the pattern is /: (if the pattern starts
|
||||
# with / it matches all instances) and the string is \\: (results in \:).
|
||||
sed -i "s:{{ROOT_PATH}}:${codeServerBuildPath//:/\\:}:g" "${filePath}"
|
||||
if [[ "${target}" == "darwin" ]] ; then
|
||||
sed -i "" -e "s:{{ROOT_PATH}}:${codeServerBuildPath//:/\\:}:g" "${filePath}"
|
||||
else
|
||||
sed -i "s:{{ROOT_PATH}}:${codeServerBuildPath//:/\\:}:g" "${filePath}"
|
||||
fi
|
||||
}
|
||||
|
||||
# Copy code-server into VS Code then build it.
|
||||
@ -63,10 +79,7 @@ function build-code-server() {
|
||||
# (basically just want to skip extensions, target our server code, and get
|
||||
# the same type of build you get with the vscode-linux-x64-min task).
|
||||
# Something like: yarn gulp "vscode-server-${target}-${arch}-min"
|
||||
cd "${vscodeSourcePath}"
|
||||
git reset --hard
|
||||
git clean -fd
|
||||
git apply "${rootPath}/scripts/vscode.patch"
|
||||
log "Building code-server"
|
||||
yarn gulp compile-client
|
||||
|
||||
rm -rf "${codeServerBuildPath}"
|
||||
@ -78,9 +91,22 @@ function build-code-server() {
|
||||
node "${rootPath}/scripts/merge.js" "${vscodeBuildPath}/resources/app/package.json" "${rootPath}/scripts/package.json" "${codeServerBuildPath}/package.json" "${json}"
|
||||
node "${rootPath}/scripts/merge.js" "${vscodeBuildPath}/resources/app/product.json" "${rootPath}/scripts/product.json" "${codeServerBuildPath}/product.json"
|
||||
cp -r "${vscodeSourcePath}/out" "${codeServerBuildPath}"
|
||||
rm -rf "${codeServerBuildPath}/out/vs/server/node_modules"
|
||||
rm -rf "${codeServerBuildPath}/out/vs/server/typings"
|
||||
|
||||
# Rebuild to make sure the native modules work since at the moment all the
|
||||
# pre-built packages are from one Linux system. This means you must build on
|
||||
# the target system.
|
||||
log "Installing remote dependencies"
|
||||
cd "${vscodeSourcePath}/remote"
|
||||
if [[ "${target}" != "linux" ]] ; then
|
||||
yarn --production --force
|
||||
fi
|
||||
cp -r "${vscodeSourcePath}/remote/node_modules" "${codeServerBuildPath}"
|
||||
|
||||
# Only keep the production dependencies.
|
||||
cd "${codeServerBuildPath}/out/vs/server"
|
||||
yarn --production --ignore-scripts
|
||||
|
||||
prepend-loader "out/vs/server/main.js"
|
||||
prepend-loader "out/bootstrap-fork.js"
|
||||
|
||||
@ -105,11 +131,9 @@ function build-vscode() {
|
||||
if [[ ! -d "${vscodeSourcePath}/node_modules" ]] ; then
|
||||
exit-if-ci
|
||||
log "Installing VS Code dependencies"
|
||||
yarn
|
||||
# Not entirely sure why but there seem to be problems with native modules.
|
||||
# Also vscode-ripgrep keeps complaining after the rebuild that the
|
||||
# node_modules directory doesn't exist, so we're ignoring that for now.
|
||||
npm rebuild || true
|
||||
# Not entirely sure why but there seem to be problems with native modules
|
||||
# so rebuild them.
|
||||
yarn --force
|
||||
|
||||
# Keep just what we need to keep the pre-built archive smaller.
|
||||
rm -rf "${vscodeSourcePath}/test"
|
||||
@ -138,7 +162,7 @@ function download-vscode() {
|
||||
cd "${buildPath}"
|
||||
if command -v wget &> /dev/null ; then
|
||||
log "Attempting to download ${tarName} with wget"
|
||||
wget "${vsSourceUrl}" --quiet
|
||||
wget "${vsSourceUrl}" --quiet --output-document "${tarName}"
|
||||
else
|
||||
log "Attempting to download ${tarName} with curl"
|
||||
curl "${vsSourceUrl}" --silent --fail --output "${tarName}"
|
||||
@ -152,13 +176,20 @@ function download-vscode() {
|
||||
function prepare-vscode() {
|
||||
if [[ ! -d "${vscodeBuildPath}" || ! -d "${vscodeSourcePath}" ]] ; then
|
||||
mkdir -p "${buildPath}"
|
||||
# TODO: for now everything uses the Linux build and we rebuild the modules.
|
||||
# This means you must build on the target system.
|
||||
local tarName="vstar-${vscodeVersion}-${target}-${arch}.tar.gz"
|
||||
local vsSourceUrl="https://codesrv-ci.cdr.sh/${tarName}"
|
||||
local linuxTarName="vstar-${vscodeVersion}-linux-${arch}.tar.gz"
|
||||
local linuxVscodeBuildName="vscode-${vscodeVersion}-linux-${arch}-built"
|
||||
local vsSourceUrl="https://codesrv-ci.cdr.sh/${linuxTarName}"
|
||||
if download-vscode ; then
|
||||
cd "${buildPath}"
|
||||
rm -rf "${vscodeBuildPath}"
|
||||
tar -xzf "${tarName}"
|
||||
rm "${tarName}"
|
||||
if [[ "${target}" != "linux" ]] ; then
|
||||
mv "${linuxVscodeBuildName}" "${vscodeBuildName}"
|
||||
fi
|
||||
elif [[ -n "${ci}" ]] ; then
|
||||
log "Pre-built VS Code ${vscodeVersion}-${target}-${arch} does not exist" "error"
|
||||
exit 1
|
||||
@ -199,12 +230,12 @@ function package-task() {
|
||||
cp "${vscodeSourcePath}/ThirdPartyNotices.txt" "${archivePath}"
|
||||
|
||||
cd "${releasePath}"
|
||||
if [[ "${target}" == "linux" ]] ; then
|
||||
tar -czf "${binaryName}.tar.gz" "${binaryName}"
|
||||
log "Archive: ${archivePath}.tar.gz"
|
||||
else
|
||||
if [[ "${target}" == "darwin" ]] ; then
|
||||
zip -r "${binaryName}.zip" "${binaryName}"
|
||||
log "Archive: ${archivePath}.zip"
|
||||
else
|
||||
tar -czf "${binaryName}.tar.gz" "${binaryName}"
|
||||
log "Archive: ${archivePath}.tar.gz"
|
||||
fi
|
||||
}
|
||||
|
||||
@ -221,19 +252,54 @@ function binary-task() {
|
||||
log "Binary: ${buildPath}/${binaryName}"
|
||||
}
|
||||
|
||||
# Check if it looks like we are inside VS Code.
|
||||
function in-vscode () {
|
||||
log "Checking if we are inside VS Code"
|
||||
local dir="${1}" ; shift
|
||||
|
||||
local maybeVscode
|
||||
local dirName
|
||||
maybeVscode="$(realpath "${dir}/../../..")"
|
||||
dirName="$(basename "${maybeVscode}")"
|
||||
|
||||
if [[ "${dirName}" != "vscode" ]] ; then
|
||||
return 1
|
||||
fi
|
||||
if [[ ! -f "${maybeVscode}/package.json" ]] ; then
|
||||
return 1
|
||||
fi
|
||||
if ! grep '"name": "code-oss-dev"' "${maybeVscode}/package.json" --quiet ; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
function ensure-in-vscode-task() {
|
||||
if ! in-vscode "${rootPath}"; then
|
||||
log "Not in vscode" "error"
|
||||
exit 1
|
||||
fi
|
||||
exit 0
|
||||
}
|
||||
|
||||
function main() {
|
||||
local relativeRootPath
|
||||
local rootPath
|
||||
relativeRootPath="$(dirname "${0}")/.."
|
||||
rootPath="$(realpath "${relativeRootPath}")"
|
||||
|
||||
local task="${1}" ; shift
|
||||
if [[ "${task}" == "ensure-in-vscode" ]] ; then
|
||||
ensure-in-vscode-task
|
||||
fi
|
||||
|
||||
local codeServerVersion="${1}" ; shift
|
||||
local vscodeVersion="${1}" ; shift
|
||||
local target="${1}" ; shift
|
||||
local arch="${1}" ; shift
|
||||
local ci="${CI:-}"
|
||||
|
||||
local relativeRootPath
|
||||
local rootPath
|
||||
relativeRootPath="$(dirname "${0}")/.."
|
||||
rootPath="$(realpath "${relativeRootPath}")"
|
||||
|
||||
# This lets you build in a separate directory since building within this
|
||||
# directory while developing makes it hard to keep developing since compiling
|
||||
# will compile everything in the build directory as well.
|
||||
@ -241,15 +307,9 @@ function main() {
|
||||
|
||||
# If we're inside a vscode directory, assume we want to develop. In that case
|
||||
# we should set an OUT directory and not build in this directory.
|
||||
if [[ "${outPath}" == "${rootPath}" ]] ; then
|
||||
local maybeVscode
|
||||
local dirName
|
||||
maybeVscode="$(realpath "${outPath}/../../..")"
|
||||
dirName="$(basename "${maybeVscode}")"
|
||||
if [[ "${dirName}" == "vscode" ]] ; then
|
||||
log "Set the OUT environment variable to something outside ${maybeVscode}" "error"
|
||||
exit 1
|
||||
fi
|
||||
if in-vscode "${outPath}" ; then
|
||||
log "Set the OUT environment variable to something outside of VS Code" "error"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local releasePath="${outPath}/release"
|
||||
|
Reference in New Issue
Block a user