Archived
1
0

Add NPM package, debs, rpms and refactor CI/build process

Closes many issues that I'll prune after adding more docs
for users.
This commit is contained in:
Anmol Sethi
2020-04-30 07:52:54 -04:00
parent 4875f6aa87
commit be032cf735
42 changed files with 867 additions and 631 deletions

View File

@ -0,0 +1,41 @@
#!/usr/bin/env bash
set -euo pipefail
# Generates static code-server releases for CI.
# This script assumes that a static release is built already.
main() {
cd "$(dirname "${0}")/../.."
source ./ci/lib.sh
VERSION="$(pkg_json_version)"
local OS
OS="$(os)"
local ARCH
ARCH="$(arch)"
local archive_name="code-server-$VERSION-$OS-$ARCH"
mkdir -p release-github
local ext
if [[ $OS == "linux" ]]; then
ext=".tar.gz"
tar -czf "release-github/$archive_name$ext" --transform "s/^\.\/release-static/$archive_name/" ./release-static
else
mv ./release-static "./$archive_name"
ext=".zip"
zip -r "release-github/$archive_name$ext" "./$archive_name"
mv "./$archive_name" ./release-static
fi
echo "done (release-github/$archive_name)"
mkdir -p "release-gcp/$VERSION"
cp "release-github/$archive_name$ext" "./release-gcp/$VERSION/$OS-$ARCH$ext"
mkdir -p "release-gcp/latest"
cp "./release-github/$archive_name$ext" "./release-gcp/latest/$OS-$ARCH$ext"
}
main "$@"

29
ci/build/build-code-server.sh Executable file
View File

@ -0,0 +1,29 @@
#!/usr/bin/env bash
set -euo pipefail
# Builds code-server into out and the frontend into dist.
# MINIFY controls whether parcel minifies dist.
MINIFY=${MINIFY-true}
main() {
cd "$(dirname "${0}")/../.."
npx tsc --outDir out --tsBuildInfoFile .cache/out.tsbuildinfo
# If out/node/entry.js does not already have the shebang,
# we make sure to add it and make it executable.
if ! grep -q -m1 "^#!/usr/bin/env node" out/node/entry.js; then
sed -i.bak "1s;^;#!/usr/bin/env node\n;" out/node/entry.js && rm out/node/entry.js.bak
chmod +x out/node/entry.js
fi
npx parcel build \
--public-url "/static/$(git rev-parse HEAD)/dist" \
--out-dir dist \
$([[ $MINIFY ]] || echo --no-minify) \
src/browser/pages/app.ts \
src/browser/register.ts \
src/browser/serviceWorker.ts
}
main "$@"

127
ci/build/build-release.sh Executable file
View File

@ -0,0 +1,127 @@
#!/usr/bin/env bash
set -euo pipefail
# This script requires code-server and vscode to be built with
# matching MINIFY.
# RELEASE_PATH is the destination directory for the release from the root.
# Defaults to release
RELEASE_PATH="${RELEASE_PATH-release}"
# STATIC controls whether node and node_modules are packaged into the release.
# Disabled by default.
STATIC="${STATIC-}"
# MINIFY controls whether minified vscode is bundled and whether
# any included node_modules are pruned for production.
MINIFY="${MINIFY-true}"
VSCODE_SRC_PATH="lib/vscode"
VSCODE_OUT_PATH="$RELEASE_PATH/lib/vscode"
main() {
cd "$(dirname "${0}")/../.."
source ./ci/lib.sh
mkdir -p "$RELEASE_PATH"
bundle_code_server
bundle_vscode
rsync README.md "$RELEASE_PATH"
rsync LICENSE.txt "$RELEASE_PATH"
rsync ./lib/vscode/ThirdPartyNotices.txt "$RELEASE_PATH"
if [[ $STATIC ]]; then
rsync "$RELEASE_PATH/" "$RELEASE_PATH-static"
RELEASE_PATH+=-static
VSCODE_OUT_PATH="$RELEASE_PATH/lib/vscode"
bundle_node
else
rm -Rf "$VSCODE_OUT_PATH/extensions/node_modules"
fi
}
rsync() {
command rsync -a --del "$@"
}
bundle_code_server() {
rsync out dist "$RELEASE_PATH"
# For source maps and images.
mkdir -p "$RELEASE_PATH/src/browser"
rsync src/browser/media/ "$RELEASE_PATH/src/browser/media"
mkdir -p "$RELEASE_PATH/src/browser/pages"
rsync src/browser/pages/*.html "$RELEASE_PATH/src/browser/pages"
rsync yarn.lock "$RELEASE_PATH"
# Adds the commit to package.json
jq --slurp '.[0] * .[1]' package.json <(
cat << EOF
{
"commit": "$(git rev-parse HEAD)",
"scripts": {
"postinstall": "cd lib/vscode && yarn --production && cd extensions && yarn --production"
}
}
EOF
) > "$RELEASE_PATH/package.json"
}
bundle_vscode() {
mkdir -p "$VSCODE_OUT_PATH"
rsync "$VSCODE_SRC_PATH/out-vscode${MINIFY+-min}/" "$VSCODE_OUT_PATH/out"
rsync "$VSCODE_SRC_PATH/.build/extensions/" "$VSCODE_OUT_PATH/extensions"
rsync "$VSCODE_SRC_PATH/extensions/package.json" "$VSCODE_OUT_PATH/extensions"
rsync "$VSCODE_SRC_PATH/extensions/yarn.lock" "$VSCODE_OUT_PATH/extensions"
rsync "$VSCODE_SRC_PATH/extensions/postinstall.js" "$VSCODE_OUT_PATH/extensions"
mkdir -p "$VSCODE_OUT_PATH/resources/linux"
rsync "$VSCODE_SRC_PATH/resources/linux/code.png" "$VSCODE_OUT_PATH/resources/linux/code.png"
rsync "$VSCODE_SRC_PATH/yarn.lock" "$VSCODE_OUT_PATH"
# Adds the commit and date to product.json
jq --slurp '.[0] * .[1]' "$VSCODE_SRC_PATH/product.json" <(
cat << EOF
{
"commit": "$(git rev-parse HEAD)",
"date": $(jq -n 'now | todate')
}
EOF
) > "$VSCODE_OUT_PATH/product.json"
# We remove the scripts field so that later on we can run
# yarn to fetch node_modules if necessary without build scripts
# being ran.
# We cannot use --no-scripts because we still want dependant package scripts to run
# for native modules to be rebuilt.
jq 'del(.scripts)' < "$VSCODE_SRC_PATH/package.json" > "$VSCODE_OUT_PATH/package.json"
}
bundle_node() {
# We cannot find the path to node from $PATH because yarn shims a script to ensure
# we use the same version it's using so we instead run a script with yarn that
# will print the path to node.
local node_path
node_path="$(yarn -s node <<< 'console.info(process.execPath)')"
mkdir -p "$RELEASE_PATH/bin"
rsync ./ci/build/code-server.sh "$RELEASE_PATH/bin/code-server"
rsync "$node_path" "$RELEASE_PATH/lib/node"
rsync node_modules "$RELEASE_PATH"
rsync "$VSCODE_SRC_PATH/node_modules" "$VSCODE_OUT_PATH"
if [[ $MINIFY ]]; then
pushd "$RELEASE_PATH"
yarn --production
popd
fi
}
main "$@"

24
ci/build/build-static-pkgs.sh Executable file
View File

@ -0,0 +1,24 @@
#!/usr/bin/env bash
set -euo pipefail
# Generates deb and rpm packages for CI.
# Assumes a static release has already been built.
main() {
cd "$(dirname "${0}")/../.."
source ./ci/lib.sh
VERSION="$(pkg_json_version)"
export VERSION
ARCH="$(arch)"
export ARCH
local nfpm_config
nfpm_config=$(envsubst < ./ci/build/nfpm.yaml)
nfpm pkg -f <(echo "$nfpm_config") --target release-github/code-server-"$VERSION-$ARCH.deb"
nfpm pkg -f <(echo "$nfpm_config") --target release-github/code-server-"$VERSION-$ARCH.rpm"
}
main "$@"

21
ci/build/build-vscode.sh Executable file
View File

@ -0,0 +1,21 @@
#!/usr/bin/env bash
set -euo pipefail
# Builds vscode into lib/vscode/out-vscode.
# MINIFY controls whether a minified version of vscode is built.
MINIFY=${MINIFY-true}
main() {
cd "$(dirname "${0}")/../.."
cd lib/vscode
yarn gulp compile-build
yarn gulp compile-extensions-build
yarn gulp optimize --gulpfile ./coder.js
if [[ $MINIFY ]]; then
yarn gulp minify --gulpfile ./coder.js
fi
}
main "$@"

12
ci/build/clean.sh Executable file
View File

@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -euo pipefail
main() {
cd "$(dirname "${0}")/../.."
git clean -Xffd
git submodule foreach --recursive git clean -xffd
git submodule foreach --recursive git reset --hard
}
main "$@"

3
ci/build/code-server-nfpm.sh Executable file
View File

@ -0,0 +1,3 @@
#!/usr/bin/env sh
exec /usr/lib/code-server/bin/code-server "$@"

20
ci/build/code-server.sh Executable file
View File

@ -0,0 +1,20 @@
#!/usr/bin/env sh
# This script is intended to be bundled into the static releases.
# Runs code-server with the bundled Node binary.
# More complicated than readlink -f or realpath to support macOS.
# See https://github.com/cdr/code-server/issues/1537
bin_dir() {
# We read the symlink, which may be relative from $0.
dst="$(readlink "$0")"
# We cd into the $0 directory.
cd "$(dirname "$0")" || exit 1
# Now we can cd into the dst directory.
cd "$(dirname "$dst")" || exit 1
# Finally we use pwd -P to print the absolute path of the directory of $dst.
pwd -P || exit 1
}
BIN_DIR=$(bin_dir)
exec "$BIN_DIR/../lib/node" "$BIN_DIR/.." "$@"

16
ci/build/nfpm.yaml Normal file
View File

@ -0,0 +1,16 @@
name: "code-server"
arch: "${ARCH}"
platform: "linux"
version: "v${VERSION}"
section: "devel"
priority: "optional"
maintainer: "Anmol Sethi <hi@nhooyr.io>"
description: |
Run VS Code in the browser.
vendor: "Coder"
homepage: "https://github.com/cdr/code-server"
license: "MIT"
bindir: "/usr/bin"
files:
./ci/build/code-server-nfpm.sh: /usr/bin/code-server
./release-static/**/*: "/usr/lib/code-server/"

20
ci/build/test-static-release.sh Executable file
View File

@ -0,0 +1,20 @@
#!/usr/bin/env bash
set -euo pipefail
# Makes sure the release works.
# This is to make sure we don't have Node version errors or any other
# compilation-related errors.
main() {
cd "$(dirname "${0}")/../.."
local output
output=$(./release-static/bin/code-server --list-extensions 2>&1)
if echo "$output" | grep 'was compiled against a different Node.js version'; then
echo "$output"
exit 1
fi
echo "Build ran successfully"
}
main "$@"