Skip to content

Commit a2e0638

Browse files
committed
Add support for musl and centos
1 parent bcdbd90 commit a2e0638

File tree

5 files changed

+84
-5
lines changed

5 files changed

+84
-5
lines changed

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ matrix:
77
include:
88
- os: linux
99
dist: trusty
10+
env:
11+
- TARGET="centos"
12+
- os: linux
13+
dist: trusty
14+
env:
15+
- TARGET="alpine"
1016
- os: osx
1117
before_install:
1218
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install libxkbfile-dev

build/platform.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Script that detects platform name and arch.
3+
* Cannot use os.platform() as that won't detect libc version
4+
*/
5+
import * as cp from "child_process";
6+
import * as fs from "fs";
7+
import * as os from "os";
8+
9+
enum Lib {
10+
GLIBC,
11+
MUSL,
12+
}
13+
14+
const CLIB: Lib | undefined = ((): Lib | undefined => {
15+
if (os.platform() !== "linux") {
16+
return;
17+
}
18+
const glibc = cp.spawnSync("getconf", ["GNU_LIBC_VERSION"]);
19+
if (glibc.status === 0) {
20+
return Lib.GLIBC;
21+
}
22+
23+
const ldd = cp.spawnSync("ldd", ["--version"]);
24+
if (ldd.stdout && ldd.stdout.indexOf("musl") !== -1) {
25+
return Lib.MUSL;
26+
}
27+
28+
const muslFile = fs.readdirSync("/lib").find((value) => value.startsWith("libc.musl"));
29+
if (muslFile) {
30+
return Lib.MUSL;
31+
}
32+
33+
return Lib.GLIBC;
34+
})();
35+
36+
export const platform = (): NodeJS.Platform | "musl" => {
37+
if (CLIB === Lib.MUSL) {
38+
return "musl";
39+
}
40+
41+
return os.platform();
42+
};

build/tasks.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { register, run } from "@coder/runner";
22
import * as fs from "fs";
33
import * as fse from "fs-extra";
44
import * as os from "os";
5+
import { platform } from "./platform";
56
import * as path from "path";
67
import * as zlib from "zlib";
78
import * as https from "https";
@@ -180,12 +181,12 @@ register("package", async (runner, releaseTag) => {
180181

181182
const releasePath = path.resolve(__dirname, "../release");
182183

183-
const archiveName = `code-server${releaseTag}-${os.platform()}-${os.arch()}`;
184+
const archiveName = `code-server${releaseTag}-${platform()}-${os.arch()}`;
184185
const archiveDir = path.join(releasePath, archiveName);
185186
fse.removeSync(archiveDir);
186187
fse.mkdirpSync(archiveDir);
187188

188-
const binaryPath = path.join(__dirname, `../packages/server/cli-${os.platform()}-${os.arch()}`);
189+
const binaryPath = path.join(__dirname, `../packages/server/cli-${platform()}-${os.arch()}`);
189190
const binaryDestination = path.join(archiveDir, "code-server");
190191
fse.copySync(binaryPath, binaryDestination);
191192
fs.chmodSync(binaryDestination, "755");

packages/server/scripts/nbin.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import { Binary } from "@coder/nbin";
22
import * as fs from "fs";
33
import * as os from "os";
44
import * as path from "path";
5+
import { platform } from "../../../build/platform";
56

6-
const target = `${os.platform()}-${os.arch()}`;
7+
const target = `${platform()}-${os.arch()}`;
78
const rootDir = path.join(__dirname, "..");
89
const bin = new Binary({
910
mainFile: path.join(rootDir, "out", "cli.js"),
11+
target: platform() === "darwin" ? "darwin" : platform() === "musl" ? "alpine" : "linux",
1012
});
1113
bin.writeFiles(path.join(rootDir, "build", "**"));
1214
bin.writeFiles(path.join(rootDir, "out", "**"));

scripts/build.sh

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,32 @@
11
#!/bin/bash
2-
set -e
2+
set -euxo pipefail
33

4-
yarn task build:server:binary
4+
# Variables to be set:
5+
# $IMAGE
6+
function docker_build() {
7+
containerID=$(docker create -it -v $(pwd)/.cache:/src/.cache $IMAGE)
8+
docker start $containerID
9+
docker exec $containerID mkdir -p /src
10+
11+
function exec() {
12+
docker exec $containerID bash -c "$@"
13+
}
14+
15+
docker cp ./. $containerID:/src
16+
exec "cd /src && yarn"
17+
exec "cd /src && npm rebuild"
18+
exec "cd /src && yarn task build:server:binary"
19+
exec "cd /src && yarn task package $VERSION"
20+
docker cp $containerID:/src/release/. ./release/
21+
}
22+
23+
if [[ "$OSTYPE" == "darwin"* ]]; then
24+
yarn task build:server:binary
25+
else
26+
if [[ "$TARGET" == "alpine" ]]; then
27+
IMAGE="codercom/nbin-alpine"
28+
else
29+
IMAGE="codercom/nbin-centos"
30+
fi
31+
docker_build
32+
fi

0 commit comments

Comments
 (0)