Path: blob/main/components/ide/jetbrains/backend-plugin/remote-debug.sh
2500 views
#!/bin/bash1# Copyright (c) 2022 Gitpod GmbH. All rights reserved.2# Licensed under the GNU Affero General Public License (AGPL).3# See License.AGPL.txt in the project root for license information.45# This script configure remote debugging in a workspace running in a preview environment.6# It updates VM options with remote debug agent, restart the JB backend to apply them,7# and start port forwarding of the remote debug port. You can configure `Remote JVM Debug`8# run configuration using the forwarded port.9#10# ./remote-debug.sh <workspaceUrl> (<localPort>)?1112workspaceUrl=${1-}13[ -z "$workspaceUrl" ] && echo "Please provide a workspace URL as first argument." && exit 114workspaceUrl=$(echo "$workspaceUrl" |sed -e "s/\/$//")15echo "URL: $workspaceUrl"1617workspaceDesc=$(gpctl workspaces describe "$workspaceUrl" -o=json)1819podName=$(echo "$workspaceDesc" | jq .runtime.pod_name -r)20echo "Pod: $podName"2122workspaceId=$(echo "$workspaceDesc" | jq .metadata.meta_id -r)23echo "ID: $workspaceId"2425clusterHost=$(kubectl exec -it "$podName" -- printenv GITPOD_WORKSPACE_CLUSTER_HOST |sed -e "s/\s//g")26echo "Cluster Host: $clusterHost"2728# prepare ssh29ownerToken=$(kubectl get pod "$podName" -o=json | jq ".metadata.annotations.\"gitpod\/ownerToken\"" -r)30sshConfig="/tmp/$workspaceId-ssh-config"31echo "Host $workspaceId" > "$sshConfig"32echo " Hostname \"$workspaceId.ssh.$clusterHost\"" >> "$sshConfig"33echo " User \"$workspaceId#$ownerToken\"" >> "$sshConfig"3435while true36do37# configure remote debugging38remotePort=$(ssh -F "$sshConfig" "$workspaceId" curl http://localhost:24000/debug)39if [ -n "$remotePort" ]; then40localPort=${2-$remotePort}41# forward42echo "Forwarding Debug Port: $localPort -> $remotePort"43ssh -F "$sshConfig" -L "$remotePort:localhost:$localPort" "$workspaceId" -N44fi4546sleep 147done484950