Skip to content

Add linkup command to improve link functionality #4128

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

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ node_modules
node-*
/plugins
/lib/coder-cloud-agent
/lib/linkup
.home
coverage
**/.DS_Store
Expand Down
14 changes: 14 additions & 0 deletions ci/build/build-code-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ main() {
set -e
fi

if ! [ -f ./lib/linkup ]; then
echo "Downloading Link agent..."

# for arch; we do not use OS from lib.sh and get our own.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love comments ❤️

# lib.sh normalizes macos to darwin - but cloud-agent's binaries do not
source ./ci/lib.sh
OS="$(uname | tr '[:upper:]' '[:lower:]')"

set +e
curl -fsSL "https://storage.googleapis.com/coder-link-releases/latest/linkup-$OS-$ARCH" -o ./lib/linkup
chmod +x ./lib/linkup
set -e
fi

yarn browserify out/browser/register.js -o out/browser/register.browserified.js
yarn browserify out/browser/pages/login.js -o out/browser/pages/login.browserified.js
yarn browserify out/browser/pages/vscode.js -o out/browser/pages/vscode.browserified.js
Expand Down
1 change: 1 addition & 0 deletions ci/build/build-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ EOF
rsync node_modules/ "$RELEASE_PATH/node_modules"
mkdir -p "$RELEASE_PATH/lib"
rsync ./lib/coder-cloud-agent "$RELEASE_PATH/lib"
rsync ./lib/linkup "$RELEASE_PATH/lib"
fi
}

Expand Down
6 changes: 6 additions & 0 deletions ci/build/npm-postinstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ main() {
echo "Failed to download cloud agent; --link will not work"
fi

if curl -fsSL "https://storage.googleapis.com/coder-link-releases/latest/linkup-$OS-$ARCH" -o ./lib/linkup; then
chmod +x ./lib/linkup
else
echo "Failed to download Link agent; the Link extension will not work"
fi

if ! vscode_yarn; then
echo "You may not have the required dependencies to build the native modules."
echo "Please see https://github.com/cdr/code-server/blob/master/docs/npm.md"
Expand Down
23 changes: 23 additions & 0 deletions src/node/link.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { logger } from "@coder/logger"
import { spawn } from "child_process"
import path from "path"

export function startLink(port: number): Promise<void> {
logger.debug(`running link targetting ${port}`)

const agent = spawn(path.resolve(__dirname, "../../lib/linkup"), ["--devurl", `code:${port}:code-server`], {
stdio: "ignore",
shell: false,
})
return new Promise((res, rej) => {
agent.on("error", rej)
agent.on("close", (code) => {
if (code !== 0) {
return rej({
message: `Link exited with ${code}`,
})
}
res()
})
})
}
10 changes: 10 additions & 0 deletions src/node/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { createApp, ensureAddress } from "./app"
import { AuthType, DefaultedArgs, Feature } from "./cli"
import { coderCloudBind } from "./coder_cloud"
import { commit, version } from "./constants"
import { startLink } from "./link"
import { register } from "./routes"
import { humanPath, isFile, open } from "./util"

Expand Down Expand Up @@ -129,6 +130,15 @@ export const runCodeServer = async (args: DefaultedArgs): Promise<http.Server> =
logger.info(" - Connected to cloud agent")
}

try {
const port = parseInt(serverAddress.split(":").pop() as string, 10)
startLink(port).catch((ex) => {
logger.debug("Link daemon exited!", field("error", ex))
})
} catch (ex) {
logger.debug("Failed to start link daemon!", ex)
}

if (args.enable && args.enable.length > 0) {
logger.info("Enabling the following experimental features:")
args.enable.forEach((feature) => {
Expand Down