Skip to content

Deprecate --host and --port in favour of --bind-addr #1562

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
build
dist*
out*
release*
release/
release-upload/
node_modules
binaries
2 changes: 1 addition & 1 deletion ci/release-image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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", "."]
1 change: 1 addition & 0 deletions ci/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 8 additions & 2 deletions src/node/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -88,11 +89,16 @@ const options: Options<Required<Args>> = {
"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[]" },
Expand Down
12 changes: 10 additions & 2 deletions src/node/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,21 @@ const main = async (args: Args): Promise<void> => {
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
Expand Down
3 changes: 3 additions & 0 deletions test/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -74,6 +75,7 @@ describe("cli", () => {
"user-data-dir": path.resolve("bar"),
verbose: true,
version: true,
"bind-addr": "192.169.0.1:8080",
},
)
})
Expand Down Expand Up @@ -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", () => {
Expand Down