Last active
February 9, 2018 14:29
-
-
Save hferentschik/78251dcc6363485fc20e3c95de64905d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env bash | |
# | |
# Used to run Proxy locally. | |
# | |
# In your shell (from the root of fabric8-jenkins-proxy): | |
# | |
# export OPENSHIFT_API_TOKEN=<your OpenShift API token> | |
# export JC_AUTH_TOKEN=<auth token> | |
# make build | |
# eval $(runLocal.sh) | |
# fabric8-jenkins-proxy | |
# | |
[ -z "${OPENSHIFT_API_TOKEN}" ] && echo "OPENSHIFT_API_TOKEN needs to be provided." && exit 1 | |
[ -z "${JC_AUTH_TOKEN}" ] && echo "JC_AUTH_TOKEN needs to be provided." && exit 1 | |
LOCAL_IDLER_PORT=${LOCAL_IDLER_PORT:-9001} | |
LOCAL_TENANT_PORT=${LOCAL_TENANT_PORT:-9002} | |
oc login https://api.rh-idev.openshift.com --token=${OPENSHIFT_API_TOKEN} > /dev/null | |
forwardIdler() { | |
pod=$(oc get pods -l deploymentconfig=jenkins-idler -o json | jq -r '.items[0].metadata.name') | |
if [ "${pod}" == "null" ] ; then | |
echo "WARN: Unable to determine Idler pod name" | |
return | |
fi | |
port=$(oc get pods -l deploymentconfig=jenkins-idler -o json | jq -r '.items[0].spec.containers[0].ports[0].containerPort') | |
if lsof -Pi :${LOCAL_IDLER_PORT} -sTCP:LISTEN -t >/dev/null ; then | |
echo "INFO: Local Idler port ${LOCAL_IDLER_PORT} already listening. Skipping oc port-forward" | |
return | |
fi | |
while : | |
do | |
oc port-forward ${pod} ${LOCAL_IDLER_PORT}:${port} | |
echo "Idler port forward stopped with exit code $?. Respawning.." >&2 | |
sleep 1 | |
done | |
echo "Idler port forward stopped." >&2 | |
} | |
forwardTenant() { | |
pod=$(oc get pods -l deploymentconfig=f8tenant -o json | jq -r '.items[0].metadata.name') | |
if [ "${pod}" == "null" ] ; then | |
echo "WARN: Unable to determine Tenant pod name" | |
return | |
fi | |
port=$(oc get pods -l deploymentconfig=f8tenant -o json | jq -r '.items[0].spec.containers[0].ports[0].containerPort') | |
if lsof -Pi :${LOCAL_TENANT_PORT} -sTCP:LISTEN -t >/dev/null ; then | |
echo "INFO: Local Tenant port ${LOCAL_TENANT_PORT} already listening. Skipping oc port-forward" | |
return | |
fi | |
while : | |
do | |
oc port-forward ${pod} ${LOCAL_TENANT_PORT}:${port} | |
echo "Tenant port forward stopped with exit code $?. Respawning.." >&2 | |
sleep 1 | |
done | |
echo "Tenant port forward stopped." >&2 | |
} | |
runPostgres() { | |
container=$(docker ps -q --filter "name=postgres") | |
if [ -z "${container}" ] ; then | |
docker run --name postgres -e POSTGRES_PASSWORD=postgres -d -p 5432:5432 postgres 1>&2 | |
fi | |
} | |
forwardIdler & | |
forwardTenant & | |
runPostgres & | |
echo export JC_KEYCLOAK_URL=https://sso.prod-preview.openshift.io | |
echo export JC_WIT_API_URL=https://api.prod-preview.openshift.io | |
echo export JC_REDIRECT_URL=https://jenkins.prod-preview.openshift.io | |
echo export JC_AUTH_URL=https://auth.prod-preview.openshift.io | |
echo export JC_POSTGRES_PORT=5432 | |
echo export JC_POSTGRES_HOST=localhost | |
echo export JC_POSTGRES_PASSWORD=postgres | |
echo export JC_POSTGRES_DATABASE=postgres | |
echo export JC_AUTH_TOKEN=${JC_AUTH_TOKEN} | |
echo export JC_IDLER_API=http://localhost:9001 | |
echo export JC_F8TENANT_API_URL=http://localhost:9002 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment