gitpod/dev/preview/ssh-proxy-command.sh
Mads Hartmann afa2bd1cb8 Allow for branch name lengths of 45
This relaxes the branch name restriction from 20 characters to 45. This is achieved by constructing the preview name based on the first 10 characters of the branch name and then the first 10 characters of the hashed value of the branch name.

All places that (to my knowledge) rely on the preview name has been updated.

Fixes https://github.com/gitpod-io/ops/issues/1252
2022-03-11 13:50:18 +05:30

33 lines
766 B
Bash
Executable File

#!/usr/bin/env bash
source ./dev/preview/util/preview-name-from-branch.sh
VM_NAME="$(preview-name-from-branch)"
NAMESPACE="preview-${VM_NAME}"
while getopts n:p: flag
do
case "${flag}" in
n) NAMESPACE="${OPTARG}";;
p) PORT="${OPTARG}";;
*) ;;
esac
done
pkill -f "kubectl --context=harvester (.*)${PORT}:2200"
kubectl \
--context=harvester \
--kubeconfig=/home/gitpod/.kube/config \
-n "${NAMESPACE}" port-forward service/proxy "${PORT}:2200" > /dev/null 2>&1 &
# Wait for the port to be read
while true; do
sleep 1
if [[ "$(netcat -z localhost 8022)" -eq 0 ]]; then
break
fi
done
# Use netcat as SSH expects ProxyCommand to read and write using stdin/stdout
netcat -X connect localhost "${PORT}"