-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PT-502 Experimental: SSH to github actions
Signed-off-by: James Newman <[email protected]>
- Loading branch information
1 parent
e4e908a
commit f7e9510
Showing
2 changed files
with
76 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
name: 'Tailscale SSH' | ||
description: 'Join tailnet in SSH mode for debugging' | ||
branding: | ||
icon: terminal | ||
|
||
inputs: | ||
ssh-timeout: | ||
required: false | ||
type: number | ||
default: 10 | ||
description: Number of minutes to wait for SSH connection at end of workflow before timing out | ||
ts-authkey: | ||
required: true | ||
description: Tailscale authkey | ||
|
||
runs: | ||
using: 'composite' | ||
steps: | ||
- name: Start tailscale | ||
uses: tailscale/github-action@v2 | ||
with: | ||
authkey: ${{ inputs.ts-authkey }} | ||
tags: tag:ci-builder | ||
# tailscaled-args: -verbose 1 | ||
args: --ssh | ||
- name: Show connection command | ||
shell: bash | ||
run: | | ||
echo "::notice::README: SSH Connection instructions" | ||
echo "::notice::To connect using SSH, run the following from inside the tailnet:" | ||
echo "::notice:: ssh runner@github-$HOSTNAME" | ||
echo "::notice::Your tailscale user must be in group:developers" | ||
- name: Wait for SSH sessions | ||
uses: srz-zumix/post-run-action@v1 | ||
with: | ||
post-run: | | ||
# This gets called with the -e option, which is inconvenient if you | ||
# get impatient and kill the initial sleep or tail etc, as it aborts | ||
# the whole script and your SSH is killed immediately. | ||
set +e | ||
log() { echo "$(date '+%F %T') $@"; } | ||
tail -fn+0 --pid $$ /home/runner/tailscaled.log & | ||
# Give the output that follows an imperfect chance to | ||
# avoid getting lost in tail output | ||
sleep 1 | ||
timout="${{inputs.ssh-timeout}}" | ||
[[ -z $timeout ]] && timeout=10 | ||
log "Waiting $timeout minutes for SSH connections" | ||
sleep $(( $timeout * 60 )) | ||
# tailscaled spawns login processes for each SSH session | ||
while true; do | ||
log "Waiting for open sessions to close" | ||
ps -C login -o pid=,stime=,cmd= || break | ||
# Check every 10 seconds, report evety 5 minutes | ||
for((i=0; i < (6*5-1); i++)); do | ||
sleep 10 | ||
pgrep -x login > /dev/null || break 2 | ||
done | ||
sleep 10 | ||
done | ||
log "All sessions closed - exiting" |