#!/bin/bash # ./btrix: Browsertrix Cloud dev environment utility # # Note: btrix helper expects a local.yaml file to exist in # the chart directory alongside values.yaml. # # The utility will check if microk8s is installed and if so # will preface all helm and kubectl commands with microk8s. # # Test commands require installing pytest first, e.g.: # python3 -m pip install pytest # # Usage: # # $ ./btrix bootstrap # Build frontend and backend and upgrade # Optional args: # -wait: Wait until pods are ready # # $ ./btrix reset # Uinstall, delete data, then bootstrap # Optional args: # -wait: Wait until pods are ready # # $ ./btrix test # Run backend tests # # $ ./btrix nightly # Run nightly backend tests bootstrap(){ echo "Building backend..." ./scripts/build-backend.sh echo "Building frontend..." ./scripts/build-frontend.sh echo "Installing..." helm upgrade --install -f ./chart/values.yaml -f ./chart/local.yaml btrix ./chart } bootstrapMicrok8s(){ echo "Building backend..." ./scripts/build-backend.sh echo "Building frontend..." ./scripts/build-frontend.sh echo "Installing..." microk8s helm upgrade --install -f ./chart/values.yaml -f ./chart/local.yaml btrix ./chart } waitUntilReady(){ echo "Waiting until ready..." kubectl wait --for=condition=ready pod --all --timeout=300s } waitUntilReadyMicrok8s(){ echo "Waiting until ready..." microk8s kubectl wait --for=condition=ready pod --all --timeout=300s } reset(){ echo "Uninstalling..." helm uninstall btrix echo "Deleting data..." kubectl delete pvc --all } resetMicrok8s(){ echo "Uninstalling..." microk8s helm uninstall btrix echo "Deleting data..." microk8s kubectl delete pvc --all } runTests() { echo "Running backend tests..." python3 -m pytest backend/test/*.py } runNightlyTests() { echo "Running nightly backend tests..." python3 -m pytest backend/test_nightly/*.py } microk8s=false if [[ $(microk8s) ]]; then microk8s=true fi # bootstrap: build frontend and backend, upgrade and wait until ready if [[ $1 = "bootstrap" ]]; then if [ "$microk8s" = true ] ; then bootstrapMicrok8s else bootstrap fi if [[ $2 = "-wait" ]]; then if [ "$microk8s" = true ] ; then waitUntilReadyMicrok8s else waitUntilReady fi fi fi # reset: uninstall, delete data, then bootstrap if [[ $1 = "reset" ]]; then if [ "$microk8s" = true ] ; then resetMicrok8s bootstrapMicrok8s else reset bootstrap fi if [[ $2 = "-wait" ]]; then if [ "$microk8s" = true ] ; then waitUntilReadyMicrok8s else waitUntilReady fi fi fi # test: run backend tests if [[ $1 = "test" ]]; then runTests fi # nightly: run nightly backend tests if [[ $1 = "nightly" ]]; then runNightlyTests fi echo "Done"