Anton Kosyakov 9b3f8a2cc4 gp rebuild with isolated debug workspace
Co-authored-by: Pudong Zheng <tianshi8650@gmail.com>
2023-02-06 14:47:44 +01:00

41 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
# Copyright (c) 2022 Gitpod GmbH. All rights reserved.
# Licensed under the GNU Affero General Public License (AGPL).
# See License.AGPL.txt in the project root for license information.
set -Eeuo pipefail
component=${PWD##*/}
workspaceUrl=$(echo "${1}" |sed -e "s/\/$//")
echo "URL: $workspaceUrl"
workspaceDesc=$(gpctl workspaces describe "$workspaceUrl" -o=json)
podName=$(echo "$workspaceDesc" | jq .runtime.pod_name -r)
echo "Pod: $podName"
workspaceId=$(echo "$workspaceDesc" | jq .metadata.meta_id -r)
echo "ID: $workspaceId"
clusterHost=$(kubectl exec -it "$podName" -- printenv GITPOD_WORKSPACE_CLUSTER_HOST |sed -e "s/\s//g")
echo "Cluster Host: $clusterHost"
# prepare ssh
ownerToken=$(kubectl get pod "$podName" -o=json | jq ".metadata.annotations.\"gitpod\/ownerToken\"" -r)
sshConfig=$(mktemp)
echo "Host $workspaceId" > "$sshConfig"
echo " Hostname \"$workspaceId.ssh.$clusterHost\"" >> "$sshConfig"
echo " User \"$workspaceId#$ownerToken\"" >> "$sshConfig"
# build
go build .
echo "$component built"
# upload
uploadDest="/.supervisor/$component"
echo "Upload Dest: $uploadDest"
ssh -F "$sshConfig" "$workspaceId" "sudo chown -R gitpod:gitpod /.supervisor && rm $uploadDest 2> /dev/null"
echo "Permissions granted"
scp -F "$sshConfig" -r "./$component" "$workspaceId":"$uploadDest"
echo "Swap complete"