Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/ide/jetbrains/backend-plugin/hot-swap.sh
2500 views
1
#!/bin/bash
2
# Copyright (c) 2022 Gitpod GmbH. All rights reserved.
3
# Licensed under the GNU Affero General Public License (AGPL).
4
# See License.AGPL.txt in the project root for license information.
5
6
set -Eeuo pipefail
7
8
# This script builds the backend plugin, replaces the backend plugin on a running workspace and restarts the JB backend.
9
10
workspaceUrl=${1-}
11
[ -z "$workspaceUrl" ] && echo "Please provide a workspace URL as first argument." && exit 1
12
workspaceUrl=$(echo "$workspaceUrl" |sed -e "s/\/$//")
13
echo "URL: $workspaceUrl"
14
15
workspaceDesc=$(gpctl workspaces describe "$workspaceUrl" -o=json)
16
17
podName=$(echo "$workspaceDesc" | jq .runtime.pod_name -r)
18
echo "Pod: $podName"
19
20
workspaceId=$(echo "$workspaceDesc" | jq .metadata.meta_id -r)
21
echo "ID: $workspaceId"
22
23
clusterHost=$(kubectl exec -it "$podName" -- printenv GITPOD_WORKSPACE_CLUSTER_HOST |sed -e "s/\s//g")
24
echo "Cluster Host: $clusterHost"
25
26
qualifier=$(kubectl exec -it "$podName" -- printenv JETBRAINS_BACKEND_QUALIFIER |sed -e "s/\s//g")
27
echo "Version Qualifier: $qualifier"
28
29
# prepare build
30
component="gitpod-remote-$qualifier-$(date +%F_T"%H-%M-%S")"
31
tarDir="/tmp/hot-swap/$component"
32
mkdir -p "$tarDir"
33
echo "Build Dir: $tarDir"
34
35
# prepare ssh
36
ownerToken=$(kubectl get pod "$podName" -o=json | jq ".metadata.annotations.\"gitpod\/ownerToken\"" -r)
37
sshConfig="$tarDir/ssh-config"
38
echo "Host $workspaceId" > "$sshConfig"
39
echo " Hostname \"$workspaceId.ssh.$clusterHost\"" >> "$sshConfig"
40
echo " User \"$workspaceId#$ownerToken\"" >> "$sshConfig"
41
42
# build
43
tarFile="$tarDir/build.tar.gz"
44
leeway build -DnoVerifyJBPlugin=true .:"plugin-$qualifier" --save "$tarFile"
45
tar -xf "$tarFile" -C "$tarDir"
46
47
# upload
48
uploadDest="/ide-desktop-plugins/$component"
49
echo "Upload Dest: $uploadDest"
50
scp -F "$sshConfig" -r "$tarDir/build/gitpod-remote" "$workspaceId":"$uploadDest"
51
52
# link
53
link="/ide-desktop/backend/plugins/gitpod-remote"
54
ssh -F "$sshConfig" "$workspaceId" ln -sfn "$uploadDest" "$link"
55
echo "Link: $link -> $uploadDest"
56
57
# restart
58
ssh -F "$sshConfig" "$workspaceId" curl http://localhost:24000/restart
59
echo "Restarted: please reconenct to JB backend to try new changes."
60
61
# clean up
62
rm -rf "$tarDir"
63
64