Skip to content

Instantly share code, notes, and snippets.

@jonasfj
Created November 7, 2016 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonasfj/ff8783ecc73720213e2b96034215b681 to your computer and use it in GitHub Desktop.
Save jonasfj/ff8783ecc73720213e2b96034215b681 to your computer and use it in GitHub Desktop.
Connect to a one-click-loaner shell using local terminal emulator.

How to use this

  1. Find a task on treeherder
  2. Use the "inspect-task" link to get to the task-inspector
  3. Use the "one-click-loaner" link to get a loaner task
  4. Click the taskId of the loaner task
  5. List artifacts
  6. Find "private/docker-worker/shell.html"
  7. Right click and copy URL (ensure that you are logged into the tools.taskcluster.net with an LDAP user with commit level 1)
  8. Run npm install
  9. Run node shell.js <URL>

Happy hacking.

{
"private": true,
"dependencies": {
"docker-exec-websocket-server": "^1.3.1"
}
}
let https = require('https')
let URL = require('url');
let querystring = require('querystring');
let DockerClient = require('docker-exec-websocket-server').DockerExecClient;
https.get(process.argv[2], res => {
if (res.statusCode != 303) {
console.log("Bad request");
}
let socketUrl = querystring.parse(URL.parse(res.headers.location).query).socketUrl;
let client = new DockerClient({
url: socketUrl,
tty: true,
command: [
'sh', '-c', [
'if [ -f "/etc/taskcluster-motd" ]; then cat /etc/taskcluster-motd; fi;',
'if [ -z "$TERM" ]; then export TERM=xterm; fi;',
'if [ -z "$HOME" ]; then export HOME=/root; fi;',
'if [ -z "$USER" ]; then export USER=root; fi;',
'if [ -z "$LOGNAME" ]; then export LOGNAME=root; fi;',
'if [ -z `which "$SHELL"` ]; then export SHELL=bash; fi;',
'if [ -z `which "$SHELL"` ]; then export SHELL=sh; fi;',
'if [ -z `which "$SHELL"` ]; then export SHELL="/.taskclusterutils/busybox sh"; fi;',
'SPAWN="$SHELL";',
'if [ "$SHELL" = "bash" ]; then SPAWN="bash -li"; fi;',
'if [ -f "/bin/taskcluster-interactive-shell" ]; then SPAWN="/bin/taskcluster-interactive-shell"; fi;',
'exec $SPAWN;'
].join('')
]
});
client.execute().then(() => {
process.stdin.setRawMode(true);
process.on('exit', () => {
process.stdin.setRawMode(false);
});
process.stdout.on('resize', () => {
client.resize(process.stdout.rows, process.stdout.columns);
});
process.stdin.pipe(client.stdin);
client.stdout.pipe(process.stdout);
client.stderr.pipe(process.stderr);
client.on('exit', (exitCode) => {
process.exit(exitCode);
});
client.resize(process.stdout.rows, process.stdout.columns);
}).catch(err => {
console.log("Error: %s", err);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment