Skip to content

Instantly share code, notes, and snippets.

@nickboldt
Created November 29, 2024 21:51
Show Gist options
  • Save nickboldt/66e56bec319b32d9853ecefdd069bb7a to your computer and use it in GitHub Desktop.
Save nickboldt/66e56bec319b32d9853ecefdd069bb7a to your computer and use it in GitHub Desktop.
helm and operator smoke test installer
#!/bin/bash
usage() {
echo "Usage:
$0 --helm --op --next -b rhdh-1-rhel-9
$0 --helm --latest -b rhdh-1.4-rhel-9
$0 --op -b rhdh-1.3-rhel-9
"
}
DO_HELM_INSTALL=0
DO_OPERATOR_INSTALL=0
BRANCH=""
while [[ "$#" -gt 0 ]]; do
case $1 in
'--next') CATALOG_SOURCE_FLAG="$1"; BRANCH="rhdh-1-rhel-9";;
'--latest') CATALOG_SOURCE_FLAG="$1";;
'-b') BRANCH="$2"; shift 1;;
'--helm') DO_HELM_INSTALL=1;;
'--op') DO_OPERATOR_INSTALL=1;;
'-h'|'--help') usage; exit 0;;
*) echo "[ERROR] Unknown parameter is used: $1."; usage; exit 1;;
esac
shift 1
done
if [[ ! $BRANCH ]]; then usage; exit 1; fi
# shellcheck disable=SC1090
source ~/bin/quay.rhdh.login.sh
echo; echo "[INFO]: Add registry logins to OCP for $QUAY_USER and $RRIO_USERNAME ... "
# get global secret and update it for your registry logins
oc get secret/pull-secret -n openshift-config --template='{{index .data ".dockerconfigjson" | base64decode}}' >/tmp/oc_secret
oc registry login --registry="quay.io" --auth-basic="$QUAY_USER:$QUAY_TOKEN" --to=/tmp/oc_secret
oc registry login --registry="registry.redhat.io" --auth-basic="$RRIO_USERNAME:$RRIO_PASSWORD" --to=/tmp/oc_secret
oc set data secret/pull-secret -n openshift-config --from-file=.dockerconfigjson=/tmp/oc_secret
# cat <<EOF > /tmp/nb_quay_secret
# apiVersion: v1
# kind: Secret
# metadata:
# name: rhdh-pull-secret
# data:
# .dockerconfigjson: ewogICJhdXRocyI6IHsKICAgICJxdWF5LmlvIjogewogICAgICAiYXV0aCI6ICJibWxqYTJKdmJHUjBPa0ZCTDNreGJWSjJRM2Q1ZVdOSFUxUnlRbllyWWtWd1QxSkxTVTFMV1VsR1JIZGxOU3RVUkZCdE1EQmtjMHBxZUhObFVEQTBjVFpvYW5wMVZXeG9UMmc9IiwKICAgICAgImVtYWlsIjogIiIKICAgIH0KICB9Cn0=
# type: kubernetes.io/dockerconfigjson
# EOF
# echo "oc create -f /tmp/nb_quay_secret -n \$project"
echo "[INFO] Creating projects for helm or operator install... "
oc new-project rhdh-helm
oc new-project rhdh-operator
oc delete secret rhdh-pull-secret || true
kubectl -n rhdh-operator create secret docker-registry rhdh-pull-secret --from-file=.dockerconfigjson=/tmp/oc_secret
kubectl -n rhdh-helm create secret docker-registry rhdh-pull-secret --from-file=.dockerconfigjson=/tmp/oc_secret
cd /tmp
curl -sSLO https://raw.githubusercontent.com/redhat-developer/rhdh-operator/main/.rhdh/scripts/install-rhdh-catalog-source.sh && chmod +x *.sh
if [[ $CATALOG_SOURCE_FLAG ]] && [[ $DO_OPERATOR_INSTALL -eq 1 ]]; then
./install-rhdh-catalog-source.sh ${CATALOG_SOURCE_FLAG} --install-operator rhdh &
fi
if [[ $BRANCH ]] && [[ $DO_HELM_INSTALL -eq 1 ]]; then
curl -sSL https://raw.githubusercontent.com/rhdh-bot/openshift-helm-charts/refs/heads/${BRANCH}/installation/install.sh -o install-rhdh-helm.sh && chmod +x *.sh
NUM=$(cat install-rhdh-helm.sh | grep -- " -n rhdh-ci" | sed -r -e "s|.+ ([0-9]+\.[0-9]+-[0-9]+-CI).+|\1|")
NUM_LOWER=$(echo ${NUM/./-} | tr "A-Z" "a-z")
./install-rhdh-helm.sh ${NUM} --namespace ${NUM_LOWER} --chartrepo
else
# shellcheck disable=SC2028 disable=SC2016
echo '
### FOR HELM (if not using --latest or --nest flag)
BRANCH=rhdh-1.y-rhel-9 # or rhdh-1-rhel-9
cd /tmp
curl -sSL https://raw.githubusercontent.com/rhdh-bot/openshift-helm-charts/refs/heads/${BRANCH}/installation/install.sh -o install-rhdh-helm.sh && chmod +x *.sh
NUM=$(cat install-rhdh-helm.sh | grep -- " -n rhdh-ci" | sed -r -e "s|.+ ([0-9]+\.[0-9]+-[0-9]+-CI).+|\1|") # compute version from install script
NUM_LOWER=$(echo ${NUM/./-} | tr "A-Z" "a-z")
./install-rhdh-helm.sh ${NUM} --namespace ${NUM_LOWER} --chartrepo
'
fi
CLUSTER_ROUTER_BASE=$(oc get route console -n openshift-console -o=jsonpath='{.spec.host}' | sed 's/^[^.]*\.//')
if [[ $CATALOG_SOURCE_FLAG ]] && [[ $DO_OPERATOR_INSTALL -eq 1 ]]; then
# wait up to 5 mins until the CRD is defined
count=0
while true; do
if [[ $(oc get crd | grep backstages || true) == "" ]]; then
echo "Backstage CRD does not exist yet... sleep 10s"; sleep 10
((count = count + 10 ))
if [[ $count -ge 300 ]]; then
echo " !!!! ERROR !!!!
Could not install automatically after 5 mins!
To install via UI, go to:
https://console-openshift-console.${CLUSTER_ROUTER_BASE}/k8s/all-namespaces/operators.coreos.com~v1alpha3~ClusterServiceVersion (review installed operators)
https://console-openshift-console.${CLUSTER_ROUTER_BASE}/catalog/ns/rhdh-operator?catalogType=OperatorBackedService (create new Backstage instance)
Once deployed, Developer Hub will be available via operator at:
https://console-openshift-console.${CLUSTER_ROUTER_BASE}/topology/ns/rhdh-operator?view=graph
https://backstage-developer-hub-rhdh-operator.${CLUSTER_ROUTER_BASE}
"
exit 0
fi
else
break
fi
done
echo "apiVersion: rhdh.redhat.com/v1alpha3
kind: Backstage
metadata:
name: developer-hub
namespace: rhdh-operator
spec:
application:
appConfig:
mountPath: /opt/app-root/src
extraFiles:
mountPath: /opt/app-root/src
replicas: 1
route:
enabled: true
database:
enableLocalDb: true
" | oc apply -f-
# TODO remove this once it's in the upstream script - https://github.com/redhat-developer/rhdh-operator/pull/241/files
echo "
### FOR OPERATOR
Once deployed, Developer Hub will be available via operator at
https://console-openshift-console.${CLUSTER_ROUTER_BASE}/topology/ns/rhdh-operator?view=graph
https://backstage-developer-hub-rhdh-operator.${CLUSTER_ROUTER_BASE}
"
else
# shellcheck disable=SC2028 disable=SC2016
echo '
### FOR OPERATOR (manual steps, if not using --latest or --nest flag)
cd /tmp
curl -sSLO https://raw.githubusercontent.com/redhat-developer/rhdh-operator/main/.rhdh/scripts/install-rhdh-catalog-source.sh
chmod +x install-rhdh-catalog-source.sh
# install catalog source and operator subscription, for the latest stable RC or GA from 1.yy.x branch
./install-rhdh-catalog-source.sh --latest --install-operator rhdh
# OR, install catalog source and operator subscription, for the next CI build from main branch
./install-rhdh-catalog-source.sh --next --install-operator rhdh
'
echo "
To install via UI, go to:
https://console-openshift-console.${CLUSTER_ROUTER_BASE}/k8s/all-namespaces/operators.coreos.com~v1alpha3~ClusterServiceVersion (review installed operators)
https://console-openshift-console.${CLUSTER_ROUTER_BASE}/catalog/ns/rhdh-operator?catalogType=OperatorBackedService (create new Backstage instance)
Once deployed, Developer Hub will be available via operator at:
https://console-openshift-console.${CLUSTER_ROUTER_BASE}/topology/ns/rhdh-operator?view=graph
https://backstage-developer-hub-rhdh-operator.${CLUSTER_ROUTER_BASE}
"
fi
if [[ $BRANCH ]] && [[ $DO_HELM_INSTALL -eq 1 ]]; then
echo "
### FOR HELM
Once deployed, Developer Hub will be available via helm at:
https://console-openshift-console.${CLUSTER_ROUTER_BASE}/topology/ns/${NUM_LOWER}?view=graph
https://redhat-developer-hub-${NUM_LOWER}.${CLUSTER_ROUTER_BASE}
"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment