Skip to content

Commit

Permalink
Restore ability to run training portal on local machine for testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamDumpleton committed Apr 27, 2022
1 parent b4f5797 commit bb5ccb8
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 33 deletions.
1 change: 1 addition & 0 deletions training-portal/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.git*
.docker*
data/db.sqlite3
data/secret-key.txt
src/static
testing
venv
26 changes: 26 additions & 0 deletions training-portal/Makefile
Original file line number Diff line number Diff line change
@@ -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
18 changes: 10 additions & 8 deletions training-portal/bin/start-container
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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')
Expand All @@ -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
Expand All @@ -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
16 changes: 7 additions & 9 deletions training-portal/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 0 additions & 12 deletions training-portal/testing/cleanup-sessions

This file was deleted.

12 changes: 12 additions & 0 deletions training-portal/testing/prune-environments
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -24,15 +27,19 @@ export OPERATOR_STATUS_KEY
export OPERATOR_NAME_PREFIX

export TRAINING_PORTAL
export PORTAL_UID

export REGISTRATION_TYPE

export INGRESS_DOMAIN
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

0 comments on commit bb5ccb8

Please sign in to comment.