def run_dev(context): """Run the Django development server""" init_db(context) create_django_superuser(context) export_cmd = get_export_db_val_cmds() fab_local(f'{export_cmd}; python manage.py runserver')
def run_local_cmd(cmd, description=None): """Run a command on the host""" print('-' * 40) if description: print(description) print(cmd) print('-' * 40) fab_local(cmd)
def dc_init_db(context): """Docker compose: Initialize the django database (if needed)""" cmds = ( f'docker-compose run opendp_server python server/manage.py check;' 'docker-compose run opendp_server python server/manage.py migrate;') print("Docker Compose: Run init_db") fab_local(cmds)
def redis_stop(context): """Clear data from the *running* local redis server""" redis_cmd = 'docker stop dpcreator-redis' fab_local(redis_cmd) return #redis_cmd = 'pkill -f redis' redis_cmd = 'docker stop dpcreator-redis' with settings(warn_only=True): result = fab_local(redis_cmd, capture=True) if result.failed: print('Nothing to stop')
def celery_run(context): """Clear redis and Start celery""" import random, string rand_str = ''.join( random.choices(string.ascii_letters + string.digits, k=6)) redis_clear(context) export_cmd = get_export_db_val_cmds() celery_cmd = (f'{export_cmd}; ' f'celery -A opendp_project worker' f' -l info -n worker_{rand_str}@%%h') fab_local(celery_cmd)
def init_db(context): """Initialize the django database (if needed)""" export_cmd = get_export_db_val_cmds() cmds = (f'{export_cmd};' f'python manage.py check;' f'python manage.py migrate;' f'python manage.py loaddata opendp_apps/dataverses/fixtures/*.json' f' opendp_apps/dataset/fixtures/*.json;') # f'python manage.py loaddata opendp_apps/dataverses/fixtures/test_dataverses_01.json' # f' opendp_apps/dataverses/fixtures/test_manifest_params_04.json;') print("Run init_db") print(f'Commands: {cmds}') fab_local(cmds)
def run_postgres(context): """Run Postgres via Docker on a local machine""" path_to_db_files = join(FAB_BASE_DIR, 'test_setup', 'postgres_data') if not isdir(path_to_db_files): os.makedirs(path_to_db_files, exist_ok=True) path_to_db_files = abspath(path_to_db_files) db_vals = get_test_db_vals() cmd = ('docker run --rm --name postgres-opendp-ux' f' -e POSTGRES_DB={db_vals["DB_NAME"]}' f' -e POSTGRES_USER={db_vals["DB_USER"]}' f' -e POSTGRES_PASSWORD={db_vals["DB_PASSWORD"]}' f' -v {path_to_db_files}:/var/lib/postgresql/data' ' -p 5432:5432 postgres') print(f'run-postgres: {cmd}') fab_local(cmd)
def redis_clear(context): """Clear data from the *running* local redis server""" redis_cmd = 'redis-cli flushall' # /usr/local/etc/redis.conf' fab_local(redis_cmd)
def redis_run(context): """Run the redis server via Docker""" from django.conf import settings #redis_cmd = 'redis-server /usr/local/etc/redis.conf' redis_cmd = 'docker run --rm --name dpcreator-redis -p 6379:6379 -d redis:6' fab_local(redis_cmd)
def dc_create_superuser(context): """Dockder compose: create a test superuser""" cmd = 'docker-compose run opendp_server fab -r ./server/ create-django-superuser' print("Docker Compose: create superuser") fab_local(cmd)
def run_npm(context): """Run the Django development server""" fab_local(f'cd ../client; npm run serve')
def collect_static(context): """Run the Django collectstatic command""" fab_local('python manage.py collectstatic --noinput')