From 80050d0d9d8fd11061e9694cc8474fe36b214df6 Mon Sep 17 00:00:00 2001 From: Asher Date: Wed, 21 Aug 2019 11:29:28 -0500 Subject: [PATCH] Detect target automatically This removes the potential for a bad build because the native Node modules currently can only be built on the target system, so specifying a target for something other than the system your are building on will not work. --- scripts/ci.bash | 2 +- scripts/tasks.bash | 23 +++++++++++++++-------- src/update.ts | 10 +++++----- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/scripts/ci.bash b/scripts/ci.bash index 885a8b5e..e553854a 100755 --- a/scripts/ci.bash +++ b/scripts/ci.bash @@ -26,7 +26,7 @@ function docker-build() { function docker-exec() { local command="${1}" ; shift - local args="'${vscodeVersion}' '${codeServerVersion}' '${target}'" + local args="'${vscodeVersion}' '${codeServerVersion}'" docker exec "${containerId}" \ bash -c "cd /src && CI=true GITHUB_TOKEN=${token} MINIFY=${minify} yarn ${command} ${args}" } diff --git a/scripts/tasks.bash b/scripts/tasks.bash index c4d2144d..5e7cae31 100755 --- a/scripts/tasks.bash +++ b/scripts/tasks.bash @@ -212,7 +212,7 @@ function in-vscode () { if [[ ! -f "${maybeVsCode}/package.json" ]] ; then return 1 fi - if ! grep '"name": "code-oss-dev"' "${maybeVsCode}/package.json" --quiet ; then + if ! grep '"name": "code-oss-dev"' "${maybeVsCode}/package.json" -q ; then return 1 fi return 0 @@ -264,17 +264,24 @@ function main() { local codeServerVersion="${1}" ; shift local ci="${CI:-}" local minify="${MINIFY:-}" + local arch arch=$(uname -m) - local target="${1:-}" - if [[ -z "${target}" ]] ; then - local ostype="${OSTYPE:-}" - if [[ "${ostype}" == "darwin"* ]] ; then - target="darwin" - else - target="linux" + + local target="linux" + local ostype="${OSTYPE:-}" + if [[ "${ostype}" == "darwin"* ]] ; then + target="darwin" + else + # On Alpine there seems no way to get the version except to use an invalid + # command which will output the version to stderr and exit with 1. + local output + output=$(ldd --version 2>&1 || :) + if [[ "${output}" == "musl"* ]] ; then + target="alpine" fi fi + local binaryName="code-server${codeServerVersion}-vsc${vscodeVersion}-${target}-${arch}" local buildPath="${stagingPath}/${binaryName}-built" diff --git a/src/update.ts b/src/update.ts index cc2dcbed..30428edf 100644 --- a/src/update.ts +++ b/src/update.ts @@ -124,11 +124,11 @@ export class UpdateService extends AbstractUpdateService { private async buildReleaseName(release: string): Promise { let target: string = os.platform(); if (target === "linux") { - const result = await util.promisify(cp.exec)("ldd --version"); - if (result.stderr) { - throw new Error(result.stderr); - } - if (result.stdout.indexOf("musl") !== -1) { + const result = await util.promisify(cp.exec)("ldd --version").catch((error) => ({ + stderr: error.message, + stdout: "", + })); + if (result.stderr.indexOf("musl") !== -1 || result.stdout.indexOf("musl") !== -1) { target = "alpine"; } }