Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/gitpod-cli/hot-swap.sh
2492 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
component=${PWD##*/}
9
workspaceUrl=$(echo "${1}" |sed -e "s/\/$//")
10
echo "URL: $workspaceUrl"
11
12
workspaceDesc=$(gpctl workspaces describe "$workspaceUrl" -o=json)
13
14
podName=$(echo "$workspaceDesc" | jq .runtime.pod_name -r)
15
echo "Pod: $podName"
16
17
workspaceId=$(echo "$workspaceDesc" | jq .metadata.meta_id -r)
18
echo "ID: $workspaceId"
19
20
clusterHost=$(kubectl exec -it "$podName" -- printenv GITPOD_WORKSPACE_CLUSTER_HOST |sed -e "s/\s//g")
21
echo "Cluster Host: $clusterHost"
22
23
# prepare ssh
24
ownerToken=$(kubectl get pod "$podName" -o=json | jq ".metadata.annotations.\"gitpod\/ownerToken\"" -r)
25
sshConfig=$(mktemp)
26
echo "Host $workspaceId" > "$sshConfig"
27
echo " Hostname \"$workspaceId.ssh.$clusterHost\"" >> "$sshConfig"
28
echo " User \"$workspaceId#$ownerToken\"" >> "$sshConfig"
29
30
# build
31
go build .
32
echo "$component built"
33
34
# upload
35
uploadDest="/.supervisor/$component"
36
echo "Upload Dest: $uploadDest"
37
ssh -F "$sshConfig" "$workspaceId" "sudo chown -R gitpod:gitpod /.supervisor && rm $uploadDest 2> /dev/null"
38
echo "Permissions granted"
39
scp -F "$sshConfig" -r "./$component" "$workspaceId":"$uploadDest"
40
echo "Swap complete"
41
42