From af28885ea677586b1447698870efbafff15a2ef4 Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Mon, 27 Apr 2020 09:22:52 -0400 Subject: [PATCH 1/2] Deprecate --host and --port in favour of --bind-addr --- .gitignore | 2 +- ci/release-image/Dockerfile | 2 +- src/node/cli.ts | 10 ++++++++-- src/node/entry.ts | 12 ++++++++++-- test/cli.test.ts | 3 +++ 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 99cc47e6d..4b45161eb 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,6 @@ build dist* out* -release* +release/ node_modules binaries diff --git a/ci/release-image/Dockerfile b/ci/release-image/Dockerfile index 14854e4b6..9e30d30d0 100644 --- a/ci/release-image/Dockerfile +++ b/ci/release-image/Dockerfile @@ -40,4 +40,4 @@ RUN cd /tmp && tar -xzf code-server*.tar.gz && rm code-server*.tar.gz && \ EXPOSE 8080 USER coder WORKDIR /home/coder -ENTRYPOINT ["dumb-init", "fixuid", "-q", "/usr/local/bin/code-server", "--host", "0.0.0.0", "."] +ENTRYPOINT ["dumb-init", "fixuid", "-q", "/usr/local/bin/code-server", "--bind-addr", "0.0.0.0:8080", "."] diff --git a/src/node/cli.ts b/src/node/cli.ts index 0bb0364e9..b2e7a2a5c 100644 --- a/src/node/cli.ts +++ b/src/node/cli.ts @@ -30,6 +30,7 @@ export interface Args extends VsArgs { log?: LogLevel readonly open?: boolean readonly port?: number + readonly "bind-addr"?: string readonly socket?: string readonly version?: boolean readonly force?: boolean @@ -88,11 +89,16 @@ const options: Options> = { "cert-key": { type: "string", path: true, description: "Path to certificate key when using non-generated cert." }, "disable-updates": { type: "boolean", description: "Disable automatic updates." }, "disable-telemetry": { type: "boolean", description: "Disable telemetry." }, - host: { type: "string", description: "Host for the HTTP server." }, help: { type: "boolean", short: "h", description: "Show this output." }, json: { type: "boolean" }, open: { type: "boolean", description: "Open in browser on startup. Does not work remotely." }, - port: { type: "number", description: "Port for the HTTP server." }, + + "bind-addr": { type: "string", description: "Address to bind to in host:port." }, + + // These two have been deprecated by bindAddr. + host: { type: "string", description: "" }, + port: { type: "number", description: "" }, + socket: { type: "string", path: true, description: "Path to a socket (host and port will be ignored)." }, version: { type: "boolean", short: "v", description: "Display version information." }, _: { type: "string[]" }, diff --git a/src/node/entry.ts b/src/node/entry.ts index 49fff6f49..e8e3b00b3 100644 --- a/src/node/entry.ts +++ b/src/node/entry.ts @@ -35,13 +35,21 @@ const main = async (args: Args): Promise => { const auth = args.auth || AuthType.Password const originalPassword = auth === AuthType.Password && (process.env.PASSWORD || (await generatePassword())) + let host = args.host + let port = args.port + if (args["bind-addr"] !== undefined) { + const u = new URL(`http://${args["bind-addr"]}`) + host = u.hostname + port = parseInt(u.port, 10) + } + // Spawn the main HTTP server. const options: HttpServerOptions = { auth, commit, - host: args.host || (args.auth === AuthType.Password && typeof args.cert !== "undefined" ? "0.0.0.0" : "localhost"), + host: host || (args.auth === AuthType.Password && args.cert !== undefined ? "0.0.0.0" : "localhost"), password: originalPassword ? hash(originalPassword) : undefined, - port: typeof args.port !== "undefined" ? args.port : process.env.PORT ? parseInt(process.env.PORT, 10) : 8080, + port: port !== undefined ? port : process.env.PORT ? parseInt(process.env.PORT, 10) : 8080, proxyDomains: args["proxy-domain"], socket: args.socket, ...(args.cert && !args.cert.value diff --git a/test/cli.test.ts b/test/cli.test.ts index 2b222bc6d..41489a035 100644 --- a/test/cli.test.ts +++ b/test/cli.test.ts @@ -19,6 +19,7 @@ describe("cli", () => { it("should parse all available options", () => { assert.deepEqual( parse([ + "--bind-addr=192.169.0.1:8080", "--auth", "none", "--extensions-dir", @@ -74,6 +75,7 @@ describe("cli", () => { "user-data-dir": path.resolve("bar"), verbose: true, version: true, + "bind-addr": "192.169.0.1:8080", }, ) }) @@ -117,6 +119,7 @@ describe("cli", () => { assert.throws(() => parse(["--auth=", "--log=debug"]), /--auth requires a value/) assert.throws(() => parse(["--auth", "--log"]), /--auth requires a value/) assert.throws(() => parse(["--auth", "--invalid"]), /--auth requires a value/) + assert.throws(() => parse(["--bind-addr"]), /--bind-addr requires a value/) }) it("should error if value is invalid", () => { From 2dd27b4cb81bb77eec6e75e3e637755f7dc57a1b Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Tue, 28 Apr 2020 14:14:38 -0400 Subject: [PATCH 2/2] gitignore release-upload --- .gitignore | 1 + ci/release.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 4b45161eb..fdb006ed8 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,6 @@ build dist* out* release/ +release-upload/ node_modules binaries diff --git a/ci/release.sh b/ci/release.sh index 86b89177a..6b7b47544 100755 --- a/ci/release.sh +++ b/ci/release.sh @@ -43,6 +43,7 @@ function package() { echo "done (release/$archive_name)" + # release-upload is for uploading to the GCP bucket whereas release is used for GitHub. mkdir -p "./release-upload/$VERSION" cp "./release/$archive_name$ext" "./release-upload/$VERSION/$target-$arch$ext" mkdir -p "./release-upload/latest"