Skip to content

Commit d39a141

Browse files
committed
Add linkup command to enable linking
The linkup command is the successor to coder-cloud. It enables port-forwarding via URL, uses WebRTC internally, and will enable greater linking functionality longer-term. A Link extension will be published once this is merged. We are not removing the old link functionality yet... we eventually will, but want to ensure a smooth transition.
1 parent c7a5263 commit d39a141

File tree

6 files changed

+55
-0
lines changed

6 files changed

+55
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ node_modules
1212
node-*
1313
/plugins
1414
/lib/coder-cloud-agent
15+
/lib/linkup
1516
.home
1617
coverage
1718
**/.DS_Store

ci/build/build-code-server.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,20 @@ main() {
2929
set -e
3030
fi
3131

32+
if ! [ -f ./lib/linkup ]; then
33+
echo "Downloading Link agent..."
34+
35+
# for arch; we do not use OS from lib.sh and get our own.
36+
# lib.sh normalizes macos to darwin - but cloud-agent's binaries do not
37+
source ./ci/lib.sh
38+
OS="$(uname | tr '[:upper:]' '[:lower:]')"
39+
40+
set +e
41+
curl -fsSL "https://storage.googleapis.com/coder-link-releases/latest/linkup-$OS-$ARCH" -o ./lib/linkup
42+
chmod +x ./lib/linkup
43+
set -e
44+
fi
45+
3246
yarn browserify out/browser/register.js -o out/browser/register.browserified.js
3347
yarn browserify out/browser/pages/login.js -o out/browser/pages/login.browserified.js
3448
yarn browserify out/browser/pages/vscode.js -o out/browser/pages/vscode.browserified.js

ci/build/build-release.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ EOF
6060
rsync node_modules/ "$RELEASE_PATH/node_modules"
6161
mkdir -p "$RELEASE_PATH/lib"
6262
rsync ./lib/coder-cloud-agent "$RELEASE_PATH/lib"
63+
rsync ./lib/linkup "$RELEASE_PATH/lib"
6364
fi
6465
}
6566

ci/build/npm-postinstall.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ main() {
6363
echo "Failed to download cloud agent; --link will not work"
6464
fi
6565

66+
if curl -fsSL "https://storage.googleapis.com/coder-link-releases/latest/linkup-$OS-$ARCH" -o ./lib/linkup; then
67+
chmod +x ./lib/linkup
68+
else
69+
echo "Failed to download Link agent; the Link extension will not work"
70+
fi
71+
6672
if ! vscode_yarn; then
6773
echo "You may not have the required dependencies to build the native modules."
6874
echo "Please see https://github.com/cdr/code-server/blob/master/docs/npm.md"

src/node/link.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { logger } from "@coder/logger"
2+
import { spawn } from "child_process"
3+
import path from "path"
4+
5+
export function startLink(port: number): Promise<void> {
6+
logger.debug(`running link targetting ${port}`)
7+
8+
const agent = spawn(path.resolve(__dirname, "../../lib/linkup"), ["--devurl", `code:${port}:code-server`], {
9+
stdio: "ignore",
10+
shell: false,
11+
})
12+
return new Promise((res, rej) => {
13+
agent.on("error", rej)
14+
agent.on("close", (code) => {
15+
if (code !== 0) {
16+
return rej({
17+
message: `Link exited with ${code}`,
18+
})
19+
}
20+
res()
21+
})
22+
})
23+
}

src/node/main.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { createApp, ensureAddress } from "./app"
88
import { AuthType, DefaultedArgs, Feature } from "./cli"
99
import { coderCloudBind } from "./coder_cloud"
1010
import { commit, version } from "./constants"
11+
import { startLink } from "./link"
1112
import { register } from "./routes"
1213
import { humanPath, isFile, open } from "./util"
1314

@@ -128,6 +129,15 @@ export const runCodeServer = async (args: DefaultedArgs): Promise<http.Server> =
128129
await coderCloudBind(serverAddress.replace(/^https?:\/\//, ""), args.link.value)
129130
logger.info(" - Connected to cloud agent")
130131
}
132+
133+
try {
134+
const port = parseInt(serverAddress.split(":").pop() as string, 10)
135+
startLink(port).catch((ex) => {
136+
logger.debug("Link daemon exited!", field("error", ex))
137+
})
138+
} catch (ex) {
139+
logger.debug("Failed to start link daemon!", ex)
140+
}
131141

132142
if (args.enable && args.enable.length > 0) {
133143
logger.info("Enabling the following experimental features:")

0 commit comments

Comments
 (0)