From 0c766f9867b6faf4134d3f5a6d61cddbcf00d3e4 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 27 Mar 2020 13:04:06 -0700 Subject: [PATCH] Keep more development environment options --- .env.example | 4 ++-- README.md | 31 +++++++++++++++++++++++++++---- docker-compose.yml | 2 +- fedireads/settings.py | 21 ++++++++++++++++----- 4 files changed, 46 insertions(+), 12 deletions(-) diff --git a/.env.example b/.env.example index 83290d9f5..4d9815fe7 100644 --- a/.env.example +++ b/.env.example @@ -18,8 +18,8 @@ FEDIREADS_DATABASE_BACKEND=postgres MEDIA_ROOT="images/" POSTGRES_PASSWORD="fedireads" -POSTGRES_USER="postgres" -POSTGRES_DB="postgres" +POSTGRES_USER="fedireads" +POSTGRES_DB="fedireads" RABBITMQ_DEFAULT_USER=rabbit RABBITMQ_DEFAULT_PASS=changeme diff --git a/README.md b/README.md index b4a33ba2f..68156d06e 100644 --- a/README.md +++ b/README.md @@ -45,19 +45,42 @@ This project is still in its very early stages, but these are the higher-level f But this isn't a set in stone, unchangeable list, so if you have ideas about how this could be tweaked, changed, or improved, please open an issue and start a conversation about it. ## Setting up the developer environment +You will need postgres installed and running on your computer. -Install docker and run: ``` bash -docker-compose build -docker-compose up -docker-compose exec web python manage.py migrate +python3 -m venv venv +source venv/bin/activate +pip install -r requirements.txt +createdb fedireads ``` +Create the psql user in `psql fedireads`: +``` psql +CREATE ROLE fedireads WITH LOGIN PASSWORD 'fedireads'; +GRANT ALL PRIVILEGES ON DATABASE fedireads TO fedireads; +``` + +Initialize the database (or, more specifically, delete the existing database, run migrations, and start fresh): +``` bash +./rebuilddb.sh +``` +This creates two users, `mouse` with password `password123` and `rat` with password `ratword`. + And go to the app at `localhost:8000` For most testing, you'll want to use ngrok. Remember to set the DOMAIN in `.env` to your ngrok domain. +### Docker +You can also run the application in a docker container. You'll have to install the Docker and docker-compose: + +```bash +docker-compose build +docker-compose up +docker-compose exec web python manage.py migrate +``` + + ## Project structure All the url routing is in `fedireads/urls.py`. This includes the application views (your home page, user page, book page, etc), application endpoints (things that happen when you click buttons), and federation api endpoints (inboxes, outboxes, webfinger, etc). diff --git a/docker-compose.yml b/docker-compose.yml index 6be457262..a119f25d0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,7 +5,7 @@ services: image: postgres env_file: .env volumes: - - pgdata:/var/lib/posgresql/data + - pgdata:/var/lib/postgresql/data networks: - main web: diff --git a/fedireads/settings.py b/fedireads/settings.py index 23b2c1fd4..c4ce0b2c8 100644 --- a/fedireads/settings.py +++ b/fedireads/settings.py @@ -76,17 +76,28 @@ WSGI_APPLICATION = 'fedireads.wsgi.application' # Database # https://docs.djangoproject.com/en/2.0/ref/settings/#databases -DATABASES = { - 'default': { +FEDIREADS_DATABASE_BACKEND = env('FEDIREADS_DATABASE_BACKEND', 'postgres') + +FEDIREADS_DBS = { + 'postgres': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', - 'NAME': 'postgres', - 'USER': 'postgres', - 'PASSWORD': '%s' % env('POSTGRES_PASSWORD', 'fedireads'), + 'NAME': env('POSTGRES_DB', 'fedireads'), + 'USER': env('POSTGRES_USER', 'fedireads'), + 'PASSWORD': env('POSTGRES_PASSWORD', 'fedireads'), 'HOST': 'db', 'PORT': 5432 + }, + 'sqlite': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'fedireads.db') } } +DATABASES = { + 'default': FEDIREADS_DBS[FEDIREADS_DATABASE_BACKEND] +} + + LOGIN_URL = '/login/' AUTH_USER_MODEL = 'fedireads.User'