diff --git a/training-portal/.dockerignore b/training-portal/.dockerignore index c10140fe..ff346490 100644 --- a/training-portal/.dockerignore +++ b/training-portal/.dockerignore @@ -1,6 +1,7 @@ .git* .docker* data/db.sqlite3 +data/secret-key.txt src/static testing venv diff --git a/training-portal/Makefile b/training-portal/Makefile new file mode 100644 index 00000000..4957381c --- /dev/null +++ b/training-portal/Makefile @@ -0,0 +1,26 @@ +all: + +venv: + python3 -m venv venv + +update-packages: + venv/bin/pip install -r requirements.txt + +.PHONY: src/static + +src/static: + venv/bin/python src/manage.py collectstatic --no-input + +.PHONY: requirements.txt + +requirements.txt: requirements.in + pip-compile $< + +build-project: venv update-packages src/static + +clean-project: + rm -rf src/project/__pycache__ src/project/*/__pycache__ + rm -rf src/project/*/*/__pycache__ src/project/*/*/*/__pycache__ + rm -f data/db.sqlite3 data/secret-key.txt + rm -rf src/static + rm -rf venv diff --git a/training-portal/bin/start-container b/training-portal/bin/start-container index ec6180c2..1e471439 100755 --- a/training-portal/bin/start-container +++ b/training-portal/bin/start-container @@ -12,11 +12,13 @@ fi # Calculate base directories for source code, config and data. # Make sure we are in the source directory when being run. -SRC_DIR=${SRC_DIR=`pwd`} +ROOT_DIR=$(cd `dirname $0`/..; pwd) -VENV_DIR=$SRC_DIR/../venv -DATA_DIR=$SRC_DIR/../data -CONFIG_DIR=$SRC_DIR/../config +SRC_DIR=$ROOT_DIR/src + +VENV_DIR=$ROOT_DIR/venv +DATA_DIR=$ROOT_DIR/data +CONFIG_DIR=$ROOT_DIR/config cd $SRC_DIR @@ -43,12 +45,12 @@ if [ ! -f $DATA_DIR/db.sqlite3 ]; then THIS_IS_THE_FIRST_TIME=true fi -python manage.py migrate +python $SRC_DIR/manage.py migrate if [ x"$THIS_IS_THE_FIRST_TIME" = x"true" ]; then if [ x"$ADMIN_PASSWORD" != x"" ]; then echo " -----> Creating predefined Django super user" - (cat - | python manage.py shell) << ! + (cat - | python $SRC_DIR/manage.py shell) << ! from django.contrib.auth.models import User try: User.objects.get(username='$ADMIN_USERNAME') @@ -58,7 +60,7 @@ except User.DoesNotExist: else if (tty > /dev/null 2>&1); then echo " -----> Running Django super user creation" - python manage.py createsuperuser + python $SRC_DIR/manage.py createsuperuser fi fi fi @@ -85,4 +87,4 @@ SERVER_ARGS="$SERVER_ARGS --trust-proxy-header X-Forwarded-Port" SERVER_ARGS="$SERVER_ARGS --log-to-terminal" SERVER_ARGS="$SERVER_ARGS --access-log" -exec python manage.py runmodwsgi $SERVER_ARGS +exec python $SRC_DIR/manage.py runmodwsgi $SERVER_ARGS diff --git a/training-portal/requirements.txt b/training-portal/requirements.txt index 0fe5fe3e..95282cf7 100644 --- a/training-portal/requirements.txt +++ b/training-portal/requirements.txt @@ -1,8 +1,8 @@ # -# This file is autogenerated by pip-compile with python 3.9 +# This file is autogenerated by pip-compile with python 3.10 # To update, run: # -# pip-compile +# pip-compile requirements.in # aiohttp==3.8.1 # via kopf @@ -24,14 +24,14 @@ charset-normalizer==2.0.12 # via # aiohttp # requests -click==8.1.1 +click==8.1.2 # via # black # kopf # pip-tools confusable-homoglyphs==3.2.0 # via django-registration -cryptography==36.0.2 +cryptography==37.0.0 # via jwcrypto deprecated==1.2.13 # via jwcrypto @@ -81,7 +81,7 @@ pep517==0.12.0 # via pip-tools pip-tools==6.5.1 # via -r requirements.in -platformdirs==2.5.1 +platformdirs==2.5.2 # via black pycparser==2.21 # via cffi @@ -106,10 +106,8 @@ tomli==2.0.1 # via # black # pep517 -typing-extensions==4.1.1 - # via - # black - # kopf +typing-extensions==4.2.0 + # via kopf urllib3==1.26.9 # via requests warpdrive==0.34.0 diff --git a/training-portal/testing/cleanup-sessions b/training-portal/testing/cleanup-sessions deleted file mode 100755 index cdffd55a..00000000 --- a/training-portal/testing/cleanup-sessions +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - - -set -x - -cd `dirname $0`/.. - -TRAINING_PORTAL=portal-testing - -kubectl delete workshopsessions -l training.educates.dev/portal.name=$TRAINING_PORTAL - -rm -f data/db.sqlite3 diff --git a/training-portal/testing/prune-environments b/training-portal/testing/prune-environments new file mode 100755 index 00000000..0230c2ad --- /dev/null +++ b/training-portal/testing/prune-environments @@ -0,0 +1,12 @@ +#!/bin/bash + + +set -x + +cd `dirname $0`/.. + +TRAINING_PORTAL=portal-testing + +kubectl delete workshopenvironments -l training.educates.dev/portal.name=$TRAINING_PORTAL --cascade=foreground + +rm -f data/db.sqlite3 data/secret-key.txt diff --git a/training-portal/testing/start-server b/training-portal/testing/start-training-portal similarity index 66% rename from training-portal/testing/start-server rename to training-portal/testing/start-training-portal index 12e07f6a..3e2d54e0 100755 --- a/training-portal/testing/start-server +++ b/training-portal/testing/start-training-portal @@ -1,11 +1,14 @@ #!/bin/sh +set -eo pipefail set -x -cd `dirname $0`/../src +cd `dirname $0`/.. TRAINING_PORTAL=portal-testing +PORTAL_UID=`kubectl get trainingportal/$TRAINING_PORTAL -o go-template='{{.metadata.uid}}'` + REGISTRATION_TYPE=${REGISTRATION_TYPE:-anonymous} OPERATOR_API_GROUP=educates.dev @@ -24,6 +27,8 @@ export OPERATOR_STATUS_KEY export OPERATOR_NAME_PREFIX export TRAINING_PORTAL +export PORTAL_UID + export REGISTRATION_TYPE export INGRESS_DOMAIN @@ -31,8 +36,10 @@ export INGRESS_PROTOCOL export PORTAL_HOSTNAME -python manage.py collectstatic --no-input - kubectl scale --replicas=0 deployment/training-portal -n ${TRAINING_PORTAL}-ui -exec ../bin/start-container +kubectl delete workshopenvironments -l training.educates.dev/portal.name=$TRAINING_PORTAL --cascade=foreground + +rm -f data/db.sqlite3 data/secret-key.txt + +exec bin/start-container