Path: blob/main/components/ide/jetbrains/backend-plugin/hot-swap.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.45set -Eeuo pipefail67# This script builds the backend plugin, replaces the backend plugin on a running workspace and restarts the JB backend.89workspaceUrl=${1-}10[ -z "$workspaceUrl" ] && echo "Please provide a workspace URL as first argument." && exit 111workspaceUrl=$(echo "$workspaceUrl" |sed -e "s/\/$//")12echo "URL: $workspaceUrl"1314workspaceDesc=$(gpctl workspaces describe "$workspaceUrl" -o=json)1516podName=$(echo "$workspaceDesc" | jq .runtime.pod_name -r)17echo "Pod: $podName"1819workspaceId=$(echo "$workspaceDesc" | jq .metadata.meta_id -r)20echo "ID: $workspaceId"2122clusterHost=$(kubectl exec -it "$podName" -- printenv GITPOD_WORKSPACE_CLUSTER_HOST |sed -e "s/\s//g")23echo "Cluster Host: $clusterHost"2425qualifier=$(kubectl exec -it "$podName" -- printenv JETBRAINS_BACKEND_QUALIFIER |sed -e "s/\s//g")26echo "Version Qualifier: $qualifier"2728# prepare build29component="gitpod-remote-$qualifier-$(date +%F_T"%H-%M-%S")"30tarDir="/tmp/hot-swap/$component"31mkdir -p "$tarDir"32echo "Build Dir: $tarDir"3334# prepare ssh35ownerToken=$(kubectl get pod "$podName" -o=json | jq ".metadata.annotations.\"gitpod\/ownerToken\"" -r)36sshConfig="$tarDir/ssh-config"37echo "Host $workspaceId" > "$sshConfig"38echo " Hostname \"$workspaceId.ssh.$clusterHost\"" >> "$sshConfig"39echo " User \"$workspaceId#$ownerToken\"" >> "$sshConfig"4041# build42tarFile="$tarDir/build.tar.gz"43leeway build -DnoVerifyJBPlugin=true .:"plugin-$qualifier" --save "$tarFile"44tar -xf "$tarFile" -C "$tarDir"4546# upload47uploadDest="/ide-desktop-plugins/$component"48echo "Upload Dest: $uploadDest"49scp -F "$sshConfig" -r "$tarDir/build/gitpod-remote" "$workspaceId":"$uploadDest"5051# link52link="/ide-desktop/backend/plugins/gitpod-remote"53ssh -F "$sshConfig" "$workspaceId" ln -sfn "$uploadDest" "$link"54echo "Link: $link -> $uploadDest"5556# restart57ssh -F "$sshConfig" "$workspaceId" curl http://localhost:24000/restart58echo "Restarted: please reconenct to JB backend to try new changes."5960# clean up61rm -rf "$tarDir"626364