Skip to content

Commit

Permalink
Merge pull request #4140 from magfest/upgrade-local-dev
Browse files Browse the repository at this point in the history
Improve local development experience
  • Loading branch information
kitsuta committed Jul 6, 2023
2 parents 744718e + 7e0fa64 commit 669f46f
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 37 deletions.
47 changes: 47 additions & 0 deletions .pythonstartup.py
Original file line number Diff line number Diff line change
@@ -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 == '[email protected]'
).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()
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/

Expand Down
56 changes: 38 additions & 18 deletions docker-compose.override.yml.template
Original file line number Diff line number Diff line change
Expand Up @@ -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}
- *extra-plugin-1
- *extra-plugin-2
- *config-file
34 changes: 15 additions & 19 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
- RABBITMQ_DEFAULT_VHOST=uber
12 changes: 12 additions & 0 deletions rebuild-config.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 669f46f

Please sign in to comment.