From a9c1c54194a3558a4314cf962bff7b5c0d210da2 Mon Sep 17 00:00:00 2001 From: Tessa Walsh Date: Tue, 18 Apr 2023 08:50:46 -0400 Subject: [PATCH] Make btrix helper work with microk8s (#768) * Check for microk8s * Use python3 * Add note about installing pytest * Add chart/local.yaml to .gitignore to avoid committing --- .gitignore | 1 + btrix | 77 ++++++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 67 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index baa3ce0b50..404577e9b7 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ private.yml # microk8s playbook hosts hosts +chart/local.yaml diff --git a/btrix b/btrix index 6645a0fe8d..1017ded82e 100755 --- a/btrix +++ b/btrix @@ -2,6 +2,15 @@ # ./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 @@ -32,11 +41,27 @@ bootstrap(){ 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 @@ -45,44 +70,74 @@ reset(){ kubectl delete pvc --all } -run_tests() { +resetMicrok8s(){ + echo "Uninstalling..." + microk8s helm uninstall btrix + + echo "Deleting data..." + microk8s kubectl delete pvc --all +} + +runTests() { echo "Running backend tests..." - python -m pytest backend/test/*.py + python3 -m pytest backend/test/*.py } -run_nightly_tests() { +runNightlyTests() { echo "Running nightly backend tests..." - python -m pytest backend/test_nightly/*.py + 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 - bootstrap + if [ "$microk8s" = true ] ; then + bootstrapMicrok8s + else + bootstrap + fi if [[ $2 = "-wait" ]]; then - waitUntilReady + if [ "$microk8s" = true ] ; then + waitUntilReadyMicrok8s + else + waitUntilReady + fi fi fi # reset: uninstall, delete data, then bootstrap if [[ $1 = "reset" ]]; then - reset - bootstrap + if [ "$microk8s" = true ] ; then + resetMicrok8s + bootstrapMicrok8s + else + reset + bootstrap + fi if [[ $2 = "-wait" ]]; then - waitUntilReady + if [ "$microk8s" = true ] ; then + waitUntilReadyMicrok8s + else + waitUntilReady + fi fi fi # test: run backend tests if [[ $1 = "test" ]]; then - run_tests + runTests fi # nightly: run nightly backend tests if [[ $1 = "nightly" ]]; then - run_nightly_tests + runNightlyTests fi echo "Done"