diff --git a/README.md b/README.md index 38ef969a621b699898a234cbf39c7815efaecdb5..58921ebe081533e9d7f9a83018370cb063c9fa37 100644 --- a/README.md +++ b/README.md @@ -56,8 +56,11 @@ How to [secure your setup](/doc/security/ssl.md). directory which will cause issues because then `yarn watch` will try to compile the build directory as well. - For now `@coder/nbin` is a global dependency. -- Run `yarn build ${vscodeVersion} ${target} ${arch}`in this directory (for example: - `yarn build 1.35.0 linux x64`). +- Run `yarn build ${codeServerVersion} ${vscodeVersion} ${target} ${arch}` in + this directory (for example: `yarn build development 1.35.0 linux x64`). +- You can run the built code with `node path/to/build/out/vs/server/main.js` or run + `yarn binary` with the same arguments in the previous step to package the + code into a single binary. ## Development diff --git a/scripts/ci.bash b/scripts/ci.bash index 8d9300d0bf94f836402d09b728965c6cf53c4dfa..cacc30d27de0cbd7e06802dc9fa6d7dd97af35c7 100755 --- a/scripts/ci.bash +++ b/scripts/ci.bash @@ -1,41 +1,51 @@ #!/bin/bash set -euo pipefail -# Build using a Docker container using the specified image and version. +# Build using a Docker container. function docker-build() { - local image="${1}" ; shift - local version="${1}" ; shift - local vscodeVersion="${1}" ; shift - local target="${1}" ; shift - local arch="${1}" ; shift - local containerId containerId=$(docker create --network=host --rm -it -v "$(pwd)"/.cache:/src/.cache "${image}") docker start "${containerId}" docker exec "${containerId}" mkdir -p /src function docker-exec() { - docker exec "${containerId}" bash -c "$@" + local command="${1}" ; shift + local args="'${codeServerVersion}' '${vscodeVersion}' '${target}' '${arch}'" + docker exec "${containerId}" \ + bash -c "cd /src && CI=true yarn ${command} ${args}" } docker cp ./. "${containerId}":/src - docker-exec "cd /src && CI=true yarn build \"${vscodeVersion}\" \"${target}\" \"${arch}\"" - docker-exec "cd /src && CI=true yarn binary \"${vscodeVersion}\" \"${target}\" \"${arch}\"" - docker-exec "cd /src && CI=true yarn package \"${vscodeVersion}\" \"${target}\" \"${arch}\" \"${version}\"" + docker-exec build + docker-exec binary + docker-exec package docker cp "${containerId}":/src/release/. ./release/ docker stop "${containerId}" } +# Build locally. +function local-build() { + function local-exec() { + local command="${1}" ; shift + CI=true yarn "${command}" \ + "${codeServerVersion}" "${vscodeVersion}" "${target}" "${arch}" + } + + local-exec build + local-exec binary + local-exec package +} + # Build code-server in the CI. function main() { - local version="${VERSION:-}" + local codeServerVersion="${VERSION:-}" local vscodeVersion="${VSCODE_VERSION:-}" local ostype="${OSTYPE:-}" local target="${TARGET:-}" local arch=x64 - if [[ -z "${version}" ]] ; then + if [[ -z "${codeServerVersion}" ]] ; then >&2 echo "Must set VERSION environment variable"; exit 1 fi @@ -45,9 +55,7 @@ function main() { if [[ "${ostype}" == "darwin"* ]]; then target=darwin - CI=true yarn build "${vscodeVersion}" "${target}" "${arch}" - CI=true yarn binary "${vscodeVersion}" "${target}" "${arch}" - CI=true yarn package "${vscodeVersion}" "${target}" "${arch}" "${version}" + local-build else local image if [[ "${target}" == alpine ]]; then @@ -57,7 +65,7 @@ function main() { image=codercom/nbin-centos target=linux fi - docker-build "${image}" "${version}" "${vscodeVersion}" "${target}" "${arch}" + docker-build fi } diff --git a/scripts/merge.js b/scripts/merge.js index 61bfb7d4bf6f651bd6f1285b132a7e53b2a90536..fb7ba13e4ca6d6aa6e7cf195abd6dec8afd84783 100644 --- a/scripts/merge.js +++ b/scripts/merge.js @@ -3,6 +3,7 @@ const fs = require("fs"); const a = process.argv[2]; const b = process.argv[3]; const out = process.argv[4]; +const json = JSON.parse(process.argv[5] || "{}"); const aJson = JSON.parse(fs.readFileSync(a)); const bJson = JSON.parse(fs.readFileSync(b)); @@ -15,4 +16,5 @@ delete aJson.optionalDependencies; fs.writeFileSync(out, JSON.stringify({ ...aJson, ...bJson, + ...json, }, null, 2)); diff --git a/scripts/nbin-loader.js b/scripts/nbin-loader.js index 344e6b533b99a466e300f390e44f38b6644ab3f7..1fbd6e33ca686297fd7f3afd324bd74bad4bd16a 100644 --- a/scripts/nbin-loader.js +++ b/scripts/nbin-loader.js @@ -4,6 +4,6 @@ if (!global.NBIN_LOADED) { nbin.shimNativeFs("{{ROOT_PATH}}"); global.NBIN_LOADED = true; } catch (error) { - console.log("Not in the binary"); + // Not in the binary. } } diff --git a/scripts/tasks.bash b/scripts/tasks.bash index 4f2c426cf00b49644b6079aa2accb2c635d5593d..2d1106a56c5ca5dc065b418403ae912e7c763aae 100755 --- a/scripts/tasks.bash +++ b/scripts/tasks.bash @@ -72,8 +72,10 @@ function build-code-server() { rm -rf "${codeServerBuildPath}" mkdir -p "${codeServerBuildPath}" + local json="{\"codeServerVersion\": \"${codeServerVersion}\"}" + cp -r "${vscodeBuildPath}/resources/app/extensions" "${codeServerBuildPath}" - node "${rootPath}/scripts/merge.js" "${vscodeBuildPath}/resources/app/package.json" "${rootPath}/scripts/package.json" "${codeServerBuildPath}/package.json" + 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" @@ -187,12 +189,7 @@ function vstar-task() { } function package-task() { - local version="${1}" ; shift - - log " version: ${version}" - - local archiveName="code-server${version}-vsc${vscodeVersion}-${target}-${arch}" - local archivePath="${releasePath}/${archiveName}" + local archivePath="${releasePath}/${binaryName}" rm -rf "${archivePath}" mkdir -p "${archivePath}" @@ -203,10 +200,10 @@ function package-task() { cd "${releasePath}" if [[ "${target}" == "linux" ]] ; then - tar -czf "${archiveName}.tar.gz" "${archiveName}" + tar -czf "${binaryName}.tar.gz" "${binaryName}" log "Archive: ${archivePath}.tar.gz" else - zip -r "${archiveName}.zip" "${archiveName}" + zip -r "${binaryName}.zip" "${binaryName}" log "Archive: ${archivePath}.zip" fi } @@ -226,6 +223,7 @@ function binary-task() { function main() { local task="${1}" ; shift + local codeServerVersion="${1}" ; shift local vscodeVersion="${1}" ; shift local target="${1}" ; shift local arch="${1}" ; shift @@ -262,13 +260,14 @@ function main() { local vscodeSourcePath="${buildPath}/${vscodeSourceName}" local vscodeBuildPath="${buildPath}/${vscodeBuildName}" - local codeServerBuildName="code-server-${vscodeVersion}-${target}-${arch}-built" + local codeServerBuildName="code-server${codeServerVersion}-vsc${vscodeVersion}-${target}-${arch}-built" local codeServerBuildPath="${buildPath}/${codeServerBuildName}" - local binaryName="code-server-${vscodeVersion}-${target}-${arch}" + local binaryName="code-server${codeServerVersion}-vsc${vscodeVersion}-${target}-${arch}" log "Running ${task} task" log " rootPath: ${rootPath}" log " outPath: ${outPath}" + log " codeServerVersion: ${codeServerVersion}" log " vscodeVersion: ${vscodeVersion}" log " target: ${target}" log " arch: ${arch}"