Lab-Lab-Lab / CPR-Music-Backend

MIT License
0 stars 9 forks source link

TeleBand

The music education learning management system

Built with Cookiecutter Django Black code style

License: MIT

Settings

Moved to settings.

Basic Commands

Setting Up Postgres

Install all Requirements

    $ pip install -r requirements/local.txt

Create .env File in Project Root

Create Postgres Database

Run Migrate

    $ python manage.py migrate

Setting Up Your Users

For convenience, you can keep your normal user logged in on Chrome and your superuser logged in on Firefox (or similar), so that you can see how the site behaves for both kinds of users.

Type checks

Running type checks with mypy:

$ mypy teleband

Test coverage

To run the tests, check your test coverage, and generate an HTML coverage report:

$ coverage run -m pytest
$ coverage html
$ open htmlcov/index.html

Running tests with pytest

$ pytest

Live reloading and Sass CSS compilation

Moved to Live reloading and SASS compilation.

Email Server

In development, it is often nice to be able to see emails that are being sent from your application. If you choose to use MailHog when generating the project a local SMTP server with a web interface will be available.

  1. Download the latest MailHog release for your OS.

  2. Rename the build to MailHog.

  3. Copy the file to the project root.

  4. Make it executable:

    $ chmod +x MailHog
  5. Spin up another terminal window and start it there:

    ./MailHog
  6. Check out http://127.0.0.1:8025/ to see how it goes.

Now you have your own mail server running locally, ready to receive whatever you send it.

Deployment

The following details how to deploy this application.

  1. tag the version git tag <whatever, e.g. v0.2.2>
  2. push the tag git push origin <whatever, e.g. v0.2.2>
  3. on the server, get to the main repo root e.g. cd ~/MusicCPRDev
  4. pull on server git pull
  5. checkout a new worktree for the recently pushed/fetched/tagged version git worktree add ../dev-versions/v0.2.2 v0.2.2
  6. cd ~/dev-versions/v0.2.2/
  7. cp ..//.env* .
  8. source ~/venv-dev/bin/activate
  9. stop old version sudo supervisorctl stop dev_api_musiccpr
  10. migrate python manage.py migrate
  11. change symlink cd ~/dev-versions; ls -al; rm live; ln -s /data/dev-versions/v2.0.3 live
  12. sudo supervisorctl start dev_api_musiccpr

Deployment Notes

  1. I was bad and used a non-historical model-related code in assignments/migrations/0033...
    • if this migrations fails, try migrating the instruments app before the assignments app
      • python manage.py migrate instruments
      • TODO: probably I should just make the assignments migration depend on this instruments migration?

Renewing SSL Certs (requires creating DNS TXT Entries rn 😕)

  1. maybe this is the command?
    • sudo certbot certonly --manual --server https://acme-v02.api.letsencrypt.org/directory --preferred-challenges dns-01 -d "*.musiccpr.org,musiccpr.org"

      Deploying to Prod first time

      Prefer to have:

  2. same ec2 instance as dev
  3. a different RDS instance (for postgres database)
  4. a different s3 bucket (or path?)

Creating RDS Instance

  1. use web console. choose postgres, accept defaults, but choose free tier, choose some sort of connectivity thing that goes to the ec2 instance, choose existing security group(s) ("default")
  2. create a user for the app
    1. connect to new db via psql like psql postgres://...
    2. create user with CREATE USER youruser WITH ENCRYPTED PASSWORD 'yourpass';
  3. create database CREATE DATABASE yourdbname;
  4. give user privileges GRANT ALL PRIVILEGES ON DATABASE yourdbname TO youruser;
  5. copy dev's .env and make new (prod) values.
    • where to get aws access stuff?
      1. create IAM user
        • permissions policies: AnyMailSESRecommended
        • go to security credentials tab and create access key
  6. create s3 bucket, copy settings from existing bucket
  7. activate venv
  8. pip install -r requirements/production.txt
  9. python manage.py migrate
  10. copy (and update) nginx fe and be configs from dev for prod
  11. copy (and update) supervisor config from dev for prod see: `/etc/supervisorctl
  12. sudo supervisorctl reread

Media (sample audio) Files not working in deployed environment

  1. i needed to tell s3 bucket that it should make another directory public access