learnscripture / learnscripture.net

Source code for https://learnscripture.net
Other
5 stars 2 forks source link

Initial devcontainer setup #207

Open jerivas opened 10 months ago

jerivas commented 10 months ago

Closes #204

Still a WIP, but wanted to save my progress before stopping for a few days. The steps to test are

First time (or after changes to docker-compose.yml or Dockerfile)

docker compose build # Builds application and DB containers

Database container

docker compose run --rm postgres bash
# You are now inside the DB container. The `learnscripture` DB is already created, just need to create another one for word suggesstions
createdb -U learnscripture -O learnscripture learnscripture_wordsuggestions
exit

Dev container

Add learnscripture/settings_local.py. We just need to update the database host to use the DB container

from .settings import *  # noqa
from .settings import DB_LABEL_DEFAULT, DB_LABEL_WORDSUGGESTIONS

DATABASES = {
    DB_LABEL_DEFAULT: {
        "ENGINE": "django.db.backends.postgresql",
        "NAME": "learnscripture",
        "USER": "learnscripture",
        "PASSWORD": "learnscripture",
        "HOST": "postgres", # <--------------------------------------------------------
        "PORT": 5432,
        "ATOMIC_REQUESTS": False,
        "CONN_MAX_AGE": 120,
    },
    DB_LABEL_WORDSUGGESTIONS: {
        "ENGINE": "django.db.backends.postgresql",
        "NAME": "learnscripture_wordsuggestions",
        "USER": "learnscripture",
        "PASSWORD": "learnscripture",
        "HOST": "postgres", # <--------------------------------------------------------
        "PORT": 5432,
        "ATOMIC_REQUESTS": False,
        "CONN_MAX_AGE": 120,
    },
}

Now we can run migrations

docker compose run --rm web bash
# You are now inside the web container, with Python, Node, and Elm installed
./manage.py migrate
./manage.py migrate --database wordsuggestions

# Haven't tested further than this...

Open questions