gitpod/dev/preview/ssh-vm.sh
Pudong 1bc46bd2a5
Refactor preview environment and image build methods (#19652)
* [dev-image] upgrade terraform and gcloud

* update leeway version and use new cache bucket

* update image tag

* use oidc

* fix bob

* Add code web extension as package

* gcr token refresh

* fluentbit use service account

* Add xterm web ide as package

* add ide configmap patch

* fix ide first page 502

* remove secret manager

* fix monitoring

* fix integration and delete preview

* cleanup

* use previewctl:install

* change folder

* cleanup

* change leeway cache bucket for main branch

* cleanup

* fix

* hot-deploy
2024-04-26 20:50:04 +02:00

50 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# Provides SSH access to the VM where your preview environment is installed.
#
set -euo pipefail
PRIVATE_KEY=$HOME/.ssh/vm_ed25519
PUBLIC_KEY=$HOME/.ssh/vm_ed25519.pub
PORT=2222
USER="ubuntu"
COMMAND=""
BRANCH=""
while getopts c:p:u:b:v: flag
do
case "${flag}" in
c) COMMAND="${OPTARG}";;
p) PORT="${OPTARG}";;
u) USER="${OPTARG}";;
v) VM_NAME="${OPTARG}";;
b) BRANCH="${OPTARG}";;
*) ;;
esac
done
if [ -z "${VM_NAME:-}" ]; then
if [[ "${BRANCH}" == "" ]]; then
VM_NAME="$(previewctl get name)"
else
VM_NAME="$(previewctl get name --branch "$BRANCH")"
fi
fi
function set-up-ssh {
if [[ (! -f $PRIVATE_KEY) || (! -f $PUBLIC_KEY) ]]; then
echo Generate ssh-keys
ssh-keygen -t ed25519 -q -N "" -f "$PRIVATE_KEY"
fi
}
set-up-ssh
zone=$(gcloud compute instances list --project gitpod-dev-preview --format="value(zone)" preview-"$VM_NAME")
gcloud compute ssh "$USER@preview-$VM_NAME" \
--project gitpod-dev-preview \
--ssh-key-file "$PRIVATE_KEY" \
--ssh-flag="-p $PORT" \
--zone="$zone" \
-- "$COMMAND"