This app accompanies the Broadway With a Twist open mic nights. It allows singers to sign up for songs, organizes the lineup in a fair manner, searches for song lyrics and allows people to suggest individual and group songs.
- Create a python3.10 virtualenv and install requirements (If you want to run directly on host system and not only with docker)
python3 -m venv .venv
source ./.venv/bin/activate
pip install -r requirements.txt
- Run docker-compose to spin up dev environment. Containers include django, postgres database, redis database, and celery workers. The following script destroys the containers spins them back up, and sets up two superusers (
Alon
andShani
) along with all other settings required for running the site. Passing-v
to the script will destroy the docker volumes as well.
./start-dev.sh [-v]
- Run django server in a separate terminal (so you can use pdb interactively):
./run-dev.sh
Django server is now accessible on localhost:8000. Login as a singer with passcod 'dev' and order number '123456'
- Stop containers in the same way:
./stop-dev.sh [-v]
- In order to make migrations, run the following script and exit with Ctrl-C when done.
You can then run
start-dev.sh
to apply migrations.
./makemigrations.sh
If make migrations requires interactive input, run docker exec -it twist-django-1 /bin/bash
while the containers
are running, and run ./manage.py makemigrations
within the container. Then rerun start-dev.sh
to apply migrations.
- Connect PyCharm to Docker to run tests:
- Settings -> Python interpreter -> Add interpreter -> On docker-compose.
- Select Docker service, add
docker-compose.dev.yml
as configuration file, and selectdjango
container as service. - Select python interpreter within the container, and run tests from within IDE.
- Verify that docker and docker-compose (version 2) are installed on production host.
- Run as sudoer user (not root) for improved security.
- Clone repo to user homedir.
- Create dir
twist-logs
in project root. - Create file
.env
in project root. It should look like this (with real passwords):
POSTGRES_USER=twistdbadmin
POSTGRES_PASSWORD=123456
[email protected]
EMAIL_HOST_PASSWORD=123456
ALON_PASSWORD=123456
SHANI_PASSWORD=123456
- Create file
twist/local_settings.py
in project root with the following content. Replace with relevant server IP and domain name, and use django's get_random_secret_key function to generate a new key:
ALLOWED_HOSTS = ['138.68.64.78', 'broadwaywithatwist.xyz', 'www.broadwaywithatwist.xyz']
DOMAIN = 'http://broadwaywithatwist.xyz'
DEBUG=False
SECRET_KEY = xxxxxxxxxxxxxx
- Create dir
/home/alona/db_backups
(in soduer user homedir). DB backups will be saved here (persistent across docker restarts). If you change this path name, change the path indocker-compose.prod.yml
as well. - Run
sudo ./deploy.sh init
. This will spin up the docker containers, setup superusersAlon
andShani
according to the.env
passwords, and perform db migration. Website will now be live on port 80. - Harden server security:
- In
/etc/ssh/sshd_config
setPermitRootLogin no
,PasswordAuthentication no
and choose a different SSH port number (not 22). - Enable
ufw
, and only allow incoming TCP port 80 and the custom SSH port.
- In
- Push changes to git branch
- Run migration with
sudo ./migrate.sh
- If needed, delete all docker volumes with
sudo docker compose -f docker-compose.prod.yml down -v
. This shouldn't delete the db backups mounted locally, but best make copies first. - Run
sudo ./deploy
to pull branch changes, rebuild docker images and run docker-compose. - If you run out of space at any point - run
sudo docker system prune -a
and thensudo ./deploy
(It won't delete your volumes, will just re-download the images).
- Run song_signup/tests from pycharm after selecting the docker compose file.
- If you get the error
database "test_twist_db" already exists
, delete all volumes with the command./stop-dev.sh -v
- Start containers with
./start-dev.sh
- Connect to django container with
docker exec -it twist-django-1 /bin/bash
- In container, run
coverage run --source='.' manage.py test song_signup && coverage html
- Exit container and run
open ./htmlcov/index.html
locally
- Go to Lineapp website: צפיה בהכל or הזמנות -> ניהול הזמנות
- Filter according to the relevant event, the correct dates (default is only 2 weeks back!) and שולם + מומש
- Download excel with ייצוא מותאם אישית using the BWT template
- Login as admin and go to
/upload_lineapp_orders
- Upload excel. The ticket orders are persistant through DB resets.
- We saved our group songs list on a Google Drive spreadsheet in
Broadway With a Twist/Good Group Songs
- Download as CSV (make sure you filled the type with the correct option) to
/twist/group-songs.csv
- Push to origin and restart container (the files need to be recopyied into the container)
- Connect to django container with
docker exec -it twist-django-1 /bin/bash
- Run
./manage.py import_group_songs
to import from the path above. Can also pass in a custom path.
- Download DB backup from server to twist/db_backups:
$twist git:(master): scp digital-ocean-twist:~/db_backups/default-5e939168e488-2024-05-06-112039.psql
db_backups/16-4-24-friends.psql
- Connect to running django container:
docker exec -it twist-django-1 /bin/bash
- Run restore:
./manage.py dbrestore -I db_backups/16-4-24-friends.psql
- Use restored DB on local system. Remember that your admin pass is now the production one.
- Run JMeter and open the JMX file in twist/jmeter
- Reset production DB and set passcode to
dev
- Play on JMeter, and 100 threads (40 singers and 60 audience) will run. Singers use different names for each and sign up with 2 different songs each (all data taken from CSV files in the twist/jmeter dir).
- I have an AWS instance for this -
bwt-stress
. Has jmeter installed. TURN OFF INSTANCE WHEN DONE. - If you made changes, scp the file
twist/jmeter.stress-test.jmx
to the instance's home path (user ubuntu). - Run the test from the instance like this:
jmeter -n -t stress-test.jmx -l result.jtl -j jmeter.log
- View failures in
jmeter.log
- TURN OFF INSTANCE!!
- Restart app when done - otherwise celery will keep working hard