Skip to content

Commit 8e5b819

Browse files
committed
Add deb/rpm packages to CI
1 parent d3c28e6 commit 8e5b819

18 files changed

+199
-112
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
.cache
33
dist*
44
out*
5-
release
5+
release/
6+
release-static/
67
release-github/
78
release-gcp/
89
node_modules

.travis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ jobs:
1010
# if: tag IS present
1111
script:
1212
- travis_wait 60 ./ci/container/exec.sh ./ci/steps/static-release.sh
13+
# We do not use the travis npm deploy integration as it does not allow us to
14+
# deploy a subpath and and v2 which should, just errors out that the src does not exist
1315
- cd release && npm publish
14-
# - ./ci/release-container/push.sh
16+
- ./ci/release-container/push.sh
17+
- ./ci/steps/build-static-pkgs.sh
1518
- name: Linux ARM64 Release
1619
if: tag IS present
1720
script:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Use [sshcode](https://github.com/codercom/sshcode) for a simple setup.
4141

4242
1. [Download a release](https://github.com/cdr/code-server/releases). (Linux and
4343
OS X supported. Windows support planned.)
44-
2. Unpack the downloaded release then run the included `code-server` script.
44+
2. Unpack the downloaded release then run the included `bin/code-server` script.
4545
3. In your browser navigate to `localhost:8080`.
4646

4747
## FAQ

ci/README.md

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,38 @@ This directory contains the scripts used to build code-server.
3737
- Builds vscode into ./lib/vscode/out-vscode.
3838
- [./build/build-release.sh](./build/build-release.sh) (`yarn release`)
3939
- Bundles the output of the above two scripts into a single node module at ./release.
40+
- Will build a static release with node/node_modules into `./release-static`
41+
if `STATIC=1` is set.
4042
- [./build/clean.sh](./build/clean.sh) (`yarn clean`)
4143
- Removes all git ignored files like build artifacts.
4244
- Will also `git reset --hard lib/vscode`
4345
- Useful to do a clean build.
44-
- Will build a static release if `PACKAGE_NODE=1` is set.
4546
- [./build/code-server.sh](./build/code-server.sh)
4647
- Copied into static releases to run code-server with the bundled node binary.
47-
- [./build/archive-release.sh](./build/archive-release.sh)
48-
- Archives `./release` into a tar/zip for CI with the proper directory name scheme
49-
- [./build/test-release.sh](./build/test-release.sh)
50-
- Ensures code-server in the `./release` directory runs
48+
- [./build/archive-static-release.sh](./build/archive-static-release.sh)
49+
- Archives `./release-static` into a tar/zip for CI with the proper directory name scheme
50+
- [./build/test-release.sh](./build/test-static-release.sh)
51+
- Ensures code-server in the `./release-static` directory runs
52+
- [./build/build-static-pkgs.sh](./build/build-static-pkgs.sh) (`yarn pkg`)
53+
- Uses [nfpm](https://github.com/goreleaser/nfpm) to generate .deb and .rpm from a static release
54+
- [./build/nfpm.yaml](./build/nfpm.yaml)
55+
- Used to configure [nfpm](https://github.com/goreleaser/nfpm) to generate .deb and .rpm
56+
- [./build/code-server-nfpm.sh](./build/code-server-nfpm.sh)
57+
- Entrypoint script for code-server for .deb and .rpm
5158

5259
## release-container
5360

5461
This directory contains the release docker container.
5562

63+
## container
64+
65+
This directory contains the container for CI.
66+
5667
## steps
5768

58-
This directory contains the steps used in CI. It helps avoid
69+
This directory contains a few scripts used in CI. Just helps avoid clobbering .travis.yml.
70+
71+
- [./steps/test.sh](./steps/test.sh)
72+
- Runs `yarn ci` after ensuring VS Code is patched.
73+
- [./steps/static-release.sh](./steps/static-release.sh)
74+
- Runs the full static build process for CI.

ci/build/archive-release.sh

Lines changed: 0 additions & 51 deletions
This file was deleted.

ci/build/archive-static-release.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Generates static code-server releases for CI.
5+
# This script assumes that a static release is built already.
6+
7+
main() {
8+
cd "$(dirname "${0}")/../.."
9+
source ./ci/lib.sh
10+
11+
VERSION="$(pkg_json_version)"
12+
13+
local OS
14+
OS="$(os)"
15+
16+
local ARCH
17+
ARCH="$(arch)"
18+
19+
local archive_name="code-server-$VERSION-$OS-$ARCH"
20+
mkdir -p release-github
21+
22+
local ext
23+
if [[ $OS == "linux" ]]; then
24+
ext=".tar.gz"
25+
tar -czf "release-github/$archive_name$ext" --transform "s/^\.\/release-static/$archive_name/" ./release-static
26+
else
27+
mv ./release-static "./$archive_name"
28+
ext=".zip"
29+
zip -r "release-github/$archive_name$ext" "./$archive_name"
30+
mv "./$archive_name" ./release-static
31+
fi
32+
33+
echo "done (release-github/$archive_name)"
34+
35+
mkdir -p "release-gcp/$VERSION"
36+
cp "release-github/$archive_name$ext" "./release-gcp/$VERSION/$OS-$ARCH$ext"
37+
mkdir -p "release-gcp/latest"
38+
cp "./release-github/$archive_name$ext" "./release-gcp/latest/$OS-$ARCH$ext"
39+
}
40+
41+
main "$@"

ci/build/build-release.sh

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@ set -euo pipefail
88
# Defaults to release
99
RELEASE_PATH="${RELEASE_PATH-release}"
1010

11-
# PACKAGE_NODE controls whether node and node_modules are packaged into the release.
11+
# STATIC controls whether node and node_modules are packaged into the release.
1212
# Disabled by default.
13-
PACKAGE_NODE="${PACKAGE_NODE-}"
13+
STATIC="${STATIC-}"
1414

1515
# MINIFY controls whether minified vscode is bundled and whether
1616
# any included node_modules are pruned for production.
1717
MINIFY="${MINIFY-true}"
1818

19+
VSCODE_SRC_PATH="lib/vscode"
20+
21+
VSCODE_OUT_PATH="$RELEASE_PATH/lib/vscode"
22+
1923
main() {
2024
cd "$(dirname "${0}")/../.."
2125
source ./ci/lib.sh
@@ -29,12 +33,11 @@ main() {
2933
rsync LICENSE.txt "$RELEASE_PATH"
3034
rsync ./lib/vscode/ThirdPartyNotices.txt "$RELEASE_PATH"
3135

32-
if [[ $PACKAGE_NODE ]]; then
33-
rsync "$(command -v node)" "$RELEASE_PATH/node"
34-
rsync ./ci/build/code-server.sh "$RELEASE_PATH/code-server"
35-
else
36-
rm -Rf "$RELEASE_PATH/node"
37-
rm -Rf "$RELEASE_PATH/code-server"
36+
if [[ $STATIC ]]; then
37+
rsync "$RELEASE_PATH/" "$RELEASE_PATH-static"
38+
RELEASE_PATH+=-static
39+
40+
bundle_node
3841
fi
3942
}
4043

@@ -53,35 +56,20 @@ bundle_code_server() {
5356

5457
rsync yarn.lock "$RELEASE_PATH"
5558

56-
if [[ $PACKAGE_NODE ]]; then
57-
rsync node_modules "$RELEASE_PATH"
58-
else
59-
rm -Rf "$RELEASE_PATH/node_modules"
60-
fi
61-
62-
if [[ $PACKAGE_NODE && $MINIFY ]]; then
63-
pushd "$RELEASE_PATH"
64-
yarn --production
65-
popd
66-
fi
67-
6859
# Adds the commit to package.json
6960
jq --slurp '.[0] * .[1]' package.json <(
70-
cat << EOF
61+
cat <<EOF
7162
{
7263
"commit": "$(git rev-parse HEAD)",
7364
"scripts": {
7465
"install": "cd lib/vscode && yarn --production"
7566
}
7667
}
7768
EOF
78-
) > "$RELEASE_PATH/package.json"
69+
) >"$RELEASE_PATH/package.json"
7970
}
8071

8172
bundle_vscode() {
82-
local VSCODE_SRC_PATH="lib/vscode"
83-
local VSCODE_OUT_PATH="$RELEASE_PATH/lib/vscode"
84-
8573
mkdir -p "$VSCODE_OUT_PATH"
8674
rsync "$VSCODE_SRC_PATH/out-vscode${MINIFY+-min}/" "$VSCODE_OUT_PATH/out"
8775
rsync "$VSCODE_SRC_PATH/.build/extensions/" "$VSCODE_OUT_PATH/extensions"
@@ -91,29 +79,38 @@ bundle_vscode() {
9179

9280
rsync "$VSCODE_SRC_PATH/yarn.lock" "$VSCODE_OUT_PATH"
9381

94-
if [[ $PACKAGE_NODE ]]; then
95-
rsync "$VSCODE_SRC_PATH/node_modules" "$VSCODE_OUT_PATH"
96-
else
97-
rm -Rf "$VSCODE_OUT_PATH/node_modules"
98-
fi
99-
10082
# Adds the commit and date to product.json
10183
jq --slurp '.[0] * .[1]' "$VSCODE_SRC_PATH/product.json" <(
102-
cat << EOF
84+
cat <<EOF
10385
{
10486
"commit": "$(git rev-parse HEAD)",
10587
"date": $(jq -n 'now | todate')
10688
}
10789
EOF
108-
) > "$VSCODE_OUT_PATH/product.json"
90+
) >"$VSCODE_OUT_PATH/product.json"
10991

11092
# We remove the scripts field so that later on we can run
11193
# yarn to fetch node_modules if necessary without build scripts
11294
# being ran.
113-
jq 'del(.scripts)' < "$VSCODE_SRC_PATH/package.json" > "$VSCODE_OUT_PATH/package.json"
95+
jq 'del(.scripts)' <"$VSCODE_SRC_PATH/package.json" >"$VSCODE_OUT_PATH/package.json"
96+
}
11497

115-
if [[ $PACKAGE_NODE && $MINIFY ]]; then
116-
pushd "$VSCODE_OUT_PATH"
98+
bundle_node() {
99+
# We cannot find the path to node from $PATH because yarn shims a script to ensure
100+
# we use the same version it's using so we instead run a script with yarn that
101+
# will print the path to node.
102+
local node_path
103+
node_path="$(yarn -s node <<<'console.info(process.execPath)')"
104+
105+
mkdir -p "$RELEASE_PATH/bin"
106+
rsync ./ci/build/code-server.sh "$RELEASE_PATH/bin/code-server"
107+
rsync "$node_path" "$RELEASE_PATH/lib/node"
108+
109+
rsync node_modules "$RELEASE_PATH"
110+
rsync "$VSCODE_SRC_PATH/node_modules" "$VSCODE_OUT_PATH"
111+
112+
if [[ $MINIFY ]]; then
113+
pushd "$RELEASE_PATH"
117114
yarn --production
118115
popd
119116
fi

ci/build/build-static-pkgs.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Generates deb and rpm packages for CI.
5+
# Assumes a static release has already been built.
6+
7+
main() {
8+
cd "$(dirname "${0}")/../.."
9+
source ./ci/lib.sh
10+
11+
VERSION="$(pkg_json_version)"
12+
export VERSION
13+
14+
ARCH="$(arch)"
15+
export ARCH
16+
17+
local nfpm_config
18+
nfpm_config=$(envsubst <./ci/build/nfpm.yaml)
19+
20+
nfpm pkg -f <(echo "$nfpm_config") --target release-github/code-server-"$VERSION.deb"
21+
nfpm pkg -f <(echo "$nfpm_config") --target release-github/code-server-"$VERSION.rpm"
22+
}
23+
24+
main "$@"

ci/build/code-server-nfpm.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env sh
2+
3+
exec /usr/lib/code-server/bin/code-server "$@"

ci/build/code-server.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/usr/bin/env sh
22

3-
# This script is intended to be bundled into the self contained releases.
3+
# This script is intended to be bundled into the static releases.
44
# Runs code-server with the bundled Node binary.
55

66
# More complicated than readlink -f or realpath to support macOS.
77
# See https://github.com/cdr/code-server/issues/1537
8-
get_installation_dir() {
8+
bin_dir() {
99
# We read the symlink, which may be relative from $0.
1010
dst="$(readlink "$0")"
1111
# We cd into the $0 directory.
@@ -16,5 +16,5 @@ get_installation_dir() {
1616
pwd -P || exit 1
1717
}
1818

19-
dir=$(get_installation_dir)
20-
exec "$dir/node" "$dir" "$@"
19+
BIN_DIR=$(bin_dir)
20+
exec "$BIN_DIR/../lib/node" "$BIN_DIR/.." "$@"

ci/build/nfpm.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: "code-server"
2+
arch: "${ARCH}"
3+
platform: "linux"
4+
version: "v${VERSION}"
5+
section: "devel"
6+
priority: "optional"
7+
maintainer: "Anmol Sethi <hi@nhooyr.io>"
8+
description: |
9+
Run VS Code in the web browser.
10+
vendor: "Coder"
11+
homepage: "https://github.com/cdr/code-server"
12+
license: "MIT"
13+
bindir: "/usr/bin"
14+
files:
15+
./ci/build/code-server-nfpm.sh: /usr/bin/code-server
16+
./release-static/**/*: "/usr/lib/code-server/"

ci/build/test-release.sh renamed to ci/build/test-static-release.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ main() {
88
cd "$(dirname "${0}")/../.."
99

1010
local output
11-
output=$(./release/code-server --list-extensions 2>&1)
11+
output=$(./release-static/code-server --list-extensions 2>&1)
1212
if echo "$output" | grep 'was compiled against a different Node.js version'; then
1313
echo "$output"
1414
exit 1

0 commit comments

Comments
 (0)