|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +#assuming we're launched from inside the configuration-anomaly-detection repository |
| 5 | +CAD_REPO_PATH=$(git rev-parse --show-toplevel) |
| 6 | +echo "Assuming CAD repository root is ${CAD_REPO_PATH}" |
| 7 | + |
| 8 | +#check presence of binary, assume the dnf package name is the same |
| 9 | +check_presence () { |
| 10 | + # $1 - name of the binary |
| 11 | + echo -n "Checking presence of $1..." |
| 12 | + if ! which $1 2>/dev/null >/dev/null; then |
| 13 | + echo "Not Found" |
| 14 | + echo "Try 'dnf install $1' on Fedora" |
| 15 | + exit -1 |
| 16 | + else |
| 17 | + echo "Found" |
| 18 | + fi |
| 19 | +} |
| 20 | + |
| 21 | +# clean up child processes on SIGINT |
| 22 | +trap "kill -- -$$" EXIT |
| 23 | + |
| 24 | +check_presence "jq" |
| 25 | +check_presence "openssl" |
| 26 | +check_presence "tinyproxy" |
| 27 | +check_presence "haproxy" |
| 28 | +check_presence "proxytunnel" |
| 29 | + |
| 30 | +#loading env vars |
| 31 | +. ${CAD_REPO_PATH}/test/set_stage_env.sh |
| 32 | + |
| 33 | +#checking env vars |
| 34 | +set +u |
| 35 | +if [[ -z "${OCM_BACKPLANE_REPO_PATH}" ]]; then |
| 36 | + echo "Please set OCM_BACKPLANE_REPO_PATH variable to the path of the OCM Backplane code repository" |
| 37 | + exit -1 |
| 38 | +fi |
| 39 | +set -u |
| 40 | + |
| 41 | +if ! [ $(cat ${OCM_BACKPLANE_REPO_PATH}/configs/ocm.json | jq -r .client_id) = "ocm-backplane-staging" ]; then |
| 42 | + echo "OCM Backplane ocm.json (${OCM_BACKPLANE_REPO_PATH}/configs/ocm.json) isn't the ocm-backplane-staging config." |
| 43 | + echo "Please get the config from a backplane pod on a staging backplanes0* cluster (in /ocm inside the pod)" |
| 44 | + echo "and place it in the configs subdirectory of the backplane-api repo." |
| 45 | + exit -1 |
| 46 | +fi |
| 47 | + |
| 48 | +#checking certificate validity |
| 49 | +if ! openssl verify ${OCM_BACKPLANE_REPO_PATH}/localhost.crt; then |
| 50 | + echo "Certificate ${OCM_BACKPLANE_REPO_PATH}/localhost.crt not valid, please run make dev-certs in the OCM Backplane directory as root to generate and trust the localhost certificates" |
| 51 | + exit -1 |
| 52 | +fi |
| 53 | + |
| 54 | +#creating certificate file for the HAProxy |
| 55 | +cat ${OCM_BACKPLANE_REPO_PATH}/localhost.crt ${OCM_BACKPLANE_REPO_PATH}/localhost.key > ${CAD_REPO_PATH}/test/testinfra/localhost.pem |
| 56 | + |
| 57 | +#checking BACKPLANE_PROXY reachability reachability |
| 58 | +echo "Checking Proxy reachability" |
| 59 | +if ! curl ${BACKPLANE_PROXY} -o /dev/null; then |
| 60 | + echo "Proxy ${BACKPLANE_PROXY} not reachable, check VPN connection" |
| 61 | + exit -1 |
| 62 | +fi |
| 63 | + |
| 64 | +#run the env |
| 65 | +echo "Starting tinyproxy on port 8888" |
| 66 | +tinyproxy -d -c ${CAD_REPO_PATH}/test/testinfra/tinyproxy.conf > ${CAD_REPO_PATH}/test/testinfra/tinyproxy.log 2> ${CAD_REPO_PATH}/test/testinfra/tinyproxy.error.log& |
| 67 | + |
| 68 | +echo "Starting proxytunnel on port 8091" |
| 69 | +proxytunnel -v -p squid.corp.redhat.com:3128 -d api.stage.backplane.openshift.com:443 -a 8091 > ${CAD_REPO_PATH}/test/testinfra/proxytunnel.log 2> ${CAD_REPO_PATH}/test/testinfra/proxytunnel.error.log & |
| 70 | + |
| 71 | +echo "Starting haproxy on port 8443" |
| 72 | +pushd ${CAD_REPO_PATH}/test/testinfra/ |
| 73 | +haproxy -f haproxy.cfg > ${CAD_REPO_PATH}/test/testinfra/haproxy.log 2> ${CAD_REPO_PATH}/test/testinfra/haproxy.error.log & |
| 74 | +popd |
| 75 | + |
| 76 | +echo "Starting backplane-api on port 8001" |
| 77 | +pushd $OCM_BACKPLANE_REPO_PATH |
| 78 | +GIT_REPO=${CAD_REPO_PATH} make run-local-with-testremediation > ${CAD_REPO_PATH}/test/testinfra/backplan-api.log 2> ${CAD_REPO_PATH}/test/testinfra/backplan-api.error.log & |
| 79 | +popd |
| 80 | + |
| 81 | +echo "Environment started. Check ${CAD_REPO_PATH}/test/testinfra/ directory for logs" |
| 82 | +echo "Run cadctl with the following command to test against the local backplane-api for remediations" |
| 83 | +echo "" |
| 84 | +echo "BACKPLANE_URL=https://localhost:8443 HTTP_PROXY=http://127.0.0.1:8888 HTTPS_PROXY=http://127.0.0.1:8888 BACKPLANE_PROXY=http://127.0.0.1:8888 ./bin/cadctl investigate --payload-path ./payload --log-level debug" |
| 85 | +echo "" |
| 86 | +echo "Send SIGINT (Ctrl+C) to terminate the local infrastructure" |
| 87 | +#keep the script alive until all child processes are cleaned up |
| 88 | +wait |
0 commit comments