From 1df19caf57eb01a56414ba6a4ccc94145b9503a8 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Mon, 9 Nov 2020 14:57:55 -0500 Subject: [PATCH] WIP support for tmate [CI SKIP] --- engine/compiler/shell/shell.go | 41 ++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/engine/compiler/shell/shell.go b/engine/compiler/shell/shell.go index aad15ab..8630a08 100644 --- a/engine/compiler/shell/shell.go +++ b/engine/compiler/shell/shell.go @@ -18,6 +18,7 @@ func Script(commands []string) string { buf := new(bytes.Buffer) fmt.Fprintln(buf) fmt.Fprintf(buf, optionScript) + fmt.Fprintf(buf, tmateScript) fmt.Fprintln(buf) for _, command := range commands { escaped := fmt.Sprintf("%q", command) @@ -54,3 +55,43 @@ const traceScript = ` echo + %s %s ` + +const tmateScript = ` +remote_debug() { + if [ "$?" -ne "0" ]; + then + + if command -v apt-get &> /dev/null + then + apt-get update -qq + apt-get install xz-utils --assume-yes -qq + fi + + rm -rf tmate-2.4.0-static-linux-amd64.tar.xz + wget https://github.com/tmate-io/tmate/releases/download/2.4.0/tmate-2.4.0-static-linux-amd64.tar.xz + tar -xf tmate-2.4.0-static-linux-amd64.tar.xz + mv tmate-2.4.0-static-linux-amd64/tmate /usr/bin/ + chmod +x /usr/bin/tmate + rm -rf tmate-2.4.0-static-linux-amd64 + tmate -F + + fi +} + +if [ "${DRONE_DEBUG}" = "true" ]; then + trap remote_debug EXIT +fi +` + +// TODO(bradrydzewski) add timeout 30m to tmate + +// +// TODO(bradrydzewski) support custom tmate config options: +// +// if [ ! -z "${DRONE_TMATE_SERVER_HOST}" ]; then +// echo "set -g tmate-server-host \"$DRONE_TMATE_SERVER_HOST\"" >> $HOME/.tmate.conf +// echo "set -g tmate-server-port $DRONE_TMATE_SERVER_PORT" >> $HOME/.tmate.conf +// echo "set -g tmate-server-rsa-fingerprint \"$DRONE_TMATE_SERVER_RSA_FINGERPRINT\"" >> $HOME/.tmate.conf +// echo "set -g tmate-server-ed25519-fingerprint \"$DRONE_TMATE_SERVER_ED25519_FINGERPRINT\"" >> $HOME/.tmate.conf +// fi +//