Last active
May 16, 2022 14:41
-
-
Save scottillogical/3818f8123514e07cda46da22ba70290a to your computer and use it in GitHub Desktop.
kubectl port forward in background for concourse
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -eo pipefail | |
set -x | |
error1() { | |
echo "exit whole script!!!" | |
exit 1 | |
} | |
SCRIPT_PATH="$(cd "$(dirname "$0")"; pwd -P)" | |
kubectl --context=$MY_CLUSTER -n ci port-forward svc/concourse 8080 >/dev/null 2>&1 & | |
pid=$! | |
echo $pid | |
if [ $pid -eq 0 ]; then | |
trap 'error1' ERR | |
fi | |
new_job_started="$(jobs -n)" | |
if [ -n "$new_job_started" ];then | |
echo "started" | |
else | |
echo "not started" | |
exit 1 | |
fi | |
# kill the port-forward regardless of how this script exits | |
trap '{ | |
# echo killing $pid | |
kill $pid | |
}' EXIT | |
# wait for $localport to become available | |
while ! nc -vz localhost 8080 > /dev/null 2>&1 ; do | |
# echo sleeping | |
sleep 0.1 | |
done | |
# do the thing | |
kill $pid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment