diff --git a/.pythonstartup.py b/.pythonstartup.py new file mode 100644 index 000000000..717cffd9f --- /dev/null +++ b/.pythonstartup.py @@ -0,0 +1,47 @@ +import os +import sys +import atexit +import readline +import rlcompleter +import traceback +from pprint import pprint + + +readline.parse_and_bind('tab: complete') +history_path = os.path.expanduser('~/.pyhistory') + + +@atexit.register +def save_history(): + readline.write_history_file(history_path) + + +if os.path.exists(history_path): + readline.read_history_file(history_path) + +try: + import cherrypy + import sideboard + from uber.config import c + from uber.models import AdminAccount, Attendee, initialize_db, Session + + initialize_db() + + # Make it easier to do session stuff at the command line + session = Session().session + + admin = session.query(AdminAccount).filter( + AdminAccount.attendee_id == Attendee.id, + Attendee.email == 'magfest@example.com' + ).order_by(AdminAccount.id).first() + + if admin: + # Make it easier to do site section testing at the command line + cherrypy.session = {'account_id': admin.id} + print('Logged in as {} <{}>'.format(admin.attendee.full_name, admin.attendee.email)) + else: + print('INFO: Could not find Test Developer admin account') + +except Exception as ex: + print('ERROR: Could not initialize ubersystem environment') + traceback.print_exc() \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index abb938f1c..2864f78ae 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,6 +15,8 @@ ADD uber-development.ini.template ./uber-development.ini.template ADD sideboard-development.ini.template ./sideboard-development.ini.template ADD uber-wrapper.sh /usr/local/bin/ RUN chmod +x /usr/local/bin/uber-wrapper.sh +ADD rebuild-config.sh /usr/local/bin/ +RUN chmod +x /usr/local/bin/rebuild-config.sh ADD . plugins/uber/ diff --git a/docker-compose.override.yml.template b/docker-compose.override.yml.template index 32b6c3938..3f6cfa2a9 100644 --- a/docker-compose.override.yml.template +++ b/docker-compose.override.yml.template @@ -3,40 +3,60 @@ # 1. Download all plugins into one root directory; multiple event plugins can live side-by-side # 2. For each event you want to develop for, create `development-EVENTNAME.ini` in this directory # where EVENTNAME matches the name of the event plugin. The new file does not need to contain anything. -# 3. Copy this file to docker-compose.override.yml -# 4. Run `docker-compose -p EVENTNAME up -d` -# 5. Run `docker exec EVENTNAME-web-1 /app/env/bin/python /app/plugins/uber/make_config.py --repo https://github.com/magfest/terraform-aws-magfest.git --paths uber_config/environments/dev uber_config/events/EVENT/YEAR` +# 3. Copy this template file to docker-compose.override.yml +# 4. Run `docker compose -p EVENTNAME --profile dev up -d` +# 5. Run `env CONFIG_CMD="/usr/local/bin/rebuild-config.sh git EVENT YEAR" bash -c 'docker compose -p EVENTNAME exec web $CONFIG_CMD exec celery-worker $CONFIG_CMD exec celery-beat $CONFIG_CMD'` # where EVENT is the config folder name (e.g., `stock` not `magstock`) and year is the config year (e.g., 2023) +# 6. Run `docker compose -p EVENTNAME restart` # -# Repeat step 5 whenever you want to reset your config to the git repo +# Repeat step 5 whenever you want to reset your config; it will pull from uber-development.ini.template, then the git repo +# When you want into the Python REPL, run `docker-compose -p EVENTNAME restart python-repl && docker attach EVENTNAME-python-repl` + +x-dev-volumes: + volumes: + - &extra-plugin-1 $PWD/../covid:/app/plugins/covid + - &extra-plugin-2 $PWD/../${COMPOSE_PROJECT_NAME}/:/app/plugins/${COMPOSE_PROJECT_NAME} + - &config-file $PWD/development-${COMPOSE_PROJECT_NAME}.ini:/app/plugins/uber/development.ini services: + python-repl: + container_name: ${COMPOSE_PROJECT_NAME}-python-repl + build: . + volumes: + - $PWD:/app/plugins/uber + - *extra-plugin-1 + - *extra-plugin-2 + - *config-file + - $PWD/.pythonstartup.py:/app/.pythonstartup.py + stdin_open: true + tty: true + environment: + - DB_CONNECTION_STRING=postgresql://uber_db:uber_db@db:5432/uber_db + - PYTHONSTARTUP=/app/.pythonstartup.py + command: ['/app/env/bin/python3'] + profiles: ["dev"] + stop_grace_period: 1s web: extends: file: docker-compose.yml service: web - # Uncomment the environment settings below to automatically pull config from a git repo - # This will ALWAYS UNDO any local changes you make to development.ini - # Be sure to set your UBER_CONFIG_EVENT and UBER_CONFIG_YEAR env variables to match the folders in your git repo - # - #environment: - # - UBERSYSTEM_GIT_CONFIG=https://github.com/magfest/terraform-aws-magfest.git - # - UBERSYSTEM_GIT_CONFIG_PATHS=uber_config/environments/dev uber_config/events/${UBER_CONFIG_EVENT:-super}/${UBER_CONFIG_YEAR:-2024} volumes: - - $PWD/../covid:/app/plugins/covid - - $PWD/../${COMPOSE_PROJECT_NAME}/:/app/plugins/${COMPOSE_PROJECT_NAME} - - $PWD/development-${COMPOSE_PROJECT_NAME}.ini:/app/plugins/uber/development.ini + - *extra-plugin-1 + - *extra-plugin-2 + - *config-file celery-beat: extends: file: docker-compose.yml service: celery-beat volumes: - - $PWD/../covid:/app/plugins/covid - - $PWD/../${COMPOSE_PROJECT_NAME}/:/app/plugins/${COMPOSE_PROJECT_NAME} + - *extra-plugin-1 + - *extra-plugin-2 + - *config-file celery-worker: extends: file: docker-compose.yml service: celery-worker volumes: - - $PWD/../covid:/app/plugins/covid - - $PWD/../${COMPOSE_PROJECT_NAME}/:/app/plugins/${COMPOSE_PROJECT_NAME} \ No newline at end of file + - *extra-plugin-1 + - *extra-plugin-2 + - *config-file diff --git a/docker-compose.yml b/docker-compose.yml index 9df7d5cfd..085f5596b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,15 +1,25 @@ # docker-compose for development of ubersystem +x-uber: &uber + build: . + environment: + - &uber-db-connect DB_CONNECTION_STRING=postgresql://uber_db:uber_db@db:5432/uber_db + volumes: + - $PWD:/app/plugins/uber services: web: - build: . + <<: *uber ports: - 80:80 environment: - - DB_CONNECTION_STRING=postgresql://uber_db:uber_db@db:5432/uber_db + - *uber-db-connect - PORT=80 - volumes: - - $PWD:/app/plugins/uber + celery-beat: + <<: *uber + command: ['celery-beat'] + celery-worker: + <<: *uber + command: ['celery-worker'] db: image: postgres environment: @@ -25,18 +35,4 @@ services: environment: - RABBITMQ_DEFAULT_USER=celery - RABBITMQ_DEFAULT_PASS=celery - - RABBITMQ_DEFAULT_VHOST=uber - celery-beat: - build: . - command: ['celery-beat'] - environment: - - DB_CONNECTION_STRING=postgresql://uber_db:uber_db@db:5432/uber_db - volumes: - - $PWD:/app/plugins/uber - celery-worker: - build: . - command: ['celery-worker'] - environment: - - DB_CONNECTION_STRING=postgresql://uber_db:uber_db@db:5432/uber_db - volumes: - - $PWD:/app/plugins/uber \ No newline at end of file + - RABBITMQ_DEFAULT_VHOST=uber \ No newline at end of file diff --git a/rebuild-config.sh b/rebuild-config.sh new file mode 100644 index 000000000..882ab60d1 --- /dev/null +++ b/rebuild-config.sh @@ -0,0 +1,12 @@ +#!/bin/bash +set -e + +# This will replace any variable references in these files +# If you want to add any additional settings here just add +# the variables to the environment when running this. +envsubst < "uber-development.ini.template" > /app/plugins/uber/development.ini +envsubst < "sideboard-development.ini.template" > /app/development.ini + +if [ "$1" = 'git' ]; then +/app/env/bin/python /app/plugins/uber/make_config.py --repo https://github.com/magfest/terraform-aws-magfest.git --paths uber_config/environments/dev uber_config/events/$2 uber_config/events/$2/$3 +fi \ No newline at end of file