Skip to content

Commit

Permalink
Symlink scripts on post-install and release
Browse files Browse the repository at this point in the history
  • Loading branch information
code-asher committed Aug 1, 2022
1 parent 9e70fe8 commit 5237b0a
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 58 deletions.
8 changes: 7 additions & 1 deletion ci/build/build-standalone-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@ main() {
ln -s "./bin/code-server" "$RELEASE_PATH/code-server"
ln -s "./lib/node" "$RELEASE_PATH/node"

cd "$RELEASE_PATH"
pushd "$RELEASE_PATH"
yarn --production --frozen-lockfile
popd

pushd "$RELEASE_PATH/lib/vscode"
symlink_bin_script remote-cli/code remote-cli/code-server
symlink_bin_script helpers/browser helpers/browser .sh
popd
}

main "$@"
76 changes: 50 additions & 26 deletions ci/build/npm-postinstall.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,57 @@
#!/usr/bin/env sh
set -eu

# Copied from arch() in ci/lib.sh.
detect_arch() {
case "$(uname -m)" in
aarch64)
echo arm64
;;
x86_64 | amd64)
echo amd64
;;
*)
# This will cause the download to fail, but is intentional
uname -m
;;
# Copied from ../lib.sh. Look there for details.
arch() {
cpu="$(uname -m)"
case "$cpu" in
aarch64) cpu=arm64 ;;
x86_64 | amd64) cpu=amd64 ;;
esac
echo "$cpu"
}

ARCH="${NPM_CONFIG_ARCH:-$(detect_arch)}"
# Copied from ../lib.sh except we do not rename Darwin since the cloud agent
# uses "darwin" in the release names and we do not need to detect Alpine.
os() {
osname=$(uname | tr '[:upper:]' '[:lower:]')
case $osname in
cygwin* | mingw*) osname="windows" ;;
esac
echo "$osname"
}

# Copied from ../lib.sh. Look there for details.
symlink() {
source="$1"
dest="$2"
rm -rf "$dest"
case $OS in
windows) mklink /J "$dest" "$source" ;;
*) ln -s "$source" "$dest" ;;
esac
}

# Copied from ../lib.sh. Look there for details.
symlink_asar() {
symlink node_modules node_modules.asar
}

# Copied from ../lib.sh. Look there for more details.
symlink_bin_script() {
source="$1"
dest="$2"
ext="${1-}"
case $OS in
windows) symlink "$source.cmd" "$dest.cmd" ;;
darwin | macos) symlink "$source-darwin.sh" "$dest$ext" ;;
*) symlink "$source-linux.sh" "$dest$ext" ;;
esac
}

ARCH="${NPM_CONFIG_ARCH:-$(_arch)}"
OS="$(os)"

# This is due to an upstream issue with RHEL7/CentOS 7 comptability with node-argon2
# See: https://github.com/cdr/code-server/pull/3422#pullrequestreview-677765057
export npm_config_build_from_source=true
Expand Down Expand Up @@ -56,8 +90,6 @@ main() {
;;
esac

OS="$(uname | tr '[:upper:]' '[:lower:]')"

mkdir -p ./lib

if curl -fsSL "https://github.com/coder/cloud-agent/releases/latest/download/cloud-agent-$OS-$ARCH" -o ./lib/coder-cloud-agent; then
Expand All @@ -79,22 +111,14 @@ main() {
fi
}

# This is a copy of symlink_asar in ../lib.sh. Look there for details.
symlink_asar() {
rm -rf node_modules.asar
if [ "${WINDIR-}" ]; then
mklink /J node_modules.asar node_modules
else
ln -s node_modules node_modules.asar
fi
}

vscode_yarn() {
echo 'Installing Code dependencies...'
cd lib/vscode
yarn --production --frozen-lockfile --no-default-rc

symlink_asar
symlink_bin_script remote-cli/code remote-cli/code-server
symlink_bin_script helpers/browser helpers/browser .sh

cd extensions
yarn --production --frozen-lockfile
Expand Down
76 changes: 45 additions & 31 deletions ci/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,30 @@ vscode_version() {
}

os() {
local os
os=$(uname | tr '[:upper:]' '[:lower:]')
if [[ $os == "linux" ]]; then
# Alpine's ldd doesn't have a version flag but if you use an invalid flag
# (like --version) it outputs the version to stderr and exits with 1.
local ldd_output
ldd_output=$(ldd --version 2>&1 || true)
if echo "$ldd_output" | grep -iq musl; then
os="alpine"
fi
elif [[ $os == "darwin" ]]; then
os="macos"
fi
echo "$os"
osname=$(uname | tr '[:upper:]' '[:lower:]')
case $osname in
linux)
# Alpine's ldd doesn't have a version flag but if you use an invalid flag
# (like --version) it outputs the version to stderr and exits with 1.
# TODO: Better to check /etc/os-release; see ../install.sh.
ldd_output=$(ldd --version 2>&1 || true)
if echo "$ldd_output" | grep -iq musl; then
osname="alpine"
fi
;;
darwin) osname="macos" ;;
cygwin* | mingw*) osname="windows" ;;
esac
echo "$osname"
}

arch() {
cpu="$(uname -m)"
case "$cpu" in
aarch64)
echo arm64
;;
x86_64 | amd64)
echo amd64
;;
*)
echo "$cpu"
;;
aarch64) cpu=arm64 ;;
x86_64 | amd64) cpu=amd64 ;;
esac
echo "$cpu"
}

# Grabs the most recent ci.yaml github workflow run that was triggered from the
Expand Down Expand Up @@ -105,6 +100,18 @@ export OS
# Defaults to release
RELEASE_PATH="${RELEASE_PATH-release}"

# Create a symlink at $2 pointing to $1 on any platform. Anything that
# currently exists at $2 will be deleted.
symlink() {
source="$1"
dest="$2"
rm -rf "$dest"
case $OS in
windows) mklink /J "$dest" "$source" ;;
*) ln -s "$source" "$dest" ;;
esac
}

# VS Code bundles some modules into an asar which is an archive format that
# works like tar. It then seems to get unpacked into node_modules.asar.
#
Expand All @@ -113,12 +120,19 @@ RELEASE_PATH="${RELEASE_PATH-release}"
# Code itself but also extensions will look specifically in this directory for
# files (like the ripgrep binary or the oniguruma wasm).
symlink_asar() {
rm -rf node_modules.asar
if [ "${WINDIR-}" ]; then
# mklink takes the link name first.
mklink /J node_modules.asar node_modules
else
# ln takes the link name second.
ln -s node_modules node_modules.asar
fi
symlink node_modules node_modules.asar
}

# Symlink the correct bin script from $source to $dest depending on the
# platform. The extension will be .cmd for Windows otherwise it will be
# whatever is in $3 if it exists.
symlink_bin_script() {
source="$1"
dest="$2"
ext="${1-}"
case $OS in
windows) symlink "$source.cmd" "$dest.cmd" ;;
darwin | macos) symlink "$source-darwin.sh" "$dest$ext" ;;
*) symlink "$source-linux.sh" "$dest$ext" ;;
esac
}

0 comments on commit 5237b0a

Please sign in to comment.