diff --git a/config/settings.py b/config/settings.py index d08c807..e778ad7 100644 --- a/config/settings.py +++ b/config/settings.py @@ -131,9 +131,9 @@ "ENGINE": "django.db.backends.postgresql", "HOST": env("DB_HOST", default="localhost"), "PORT": env("DB_PORT", default="5432"), - "NAME": env("DB_NAME", default="postgres"), - "USER": env("DB_USER", default="postgres"), - "PASSWORD": env("DB_PASSWORD"), + "NAME": env("DB_NAME", default="connthreads"), + "USER": env("DB_USER", default="connthreads"), + "PASSWORD": env("DB_PASS", default="password"), } } diff --git a/docker-compose.yml b/docker-compose.yml index 7f7d711..0efbc45 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,14 +11,34 @@ services: - DJANGO_SECRET_KEY=thisisnotasecretkey - DJANGO_ALLOWED_HOSTS=localhost - DJANGO_CSRF_TRUSTED_ORIGINS=http://localhost - - SQLITE_PATH=/db/db.sqlite3 - volumes: - - dj-sqlite:/db + - DB_HOST=db + - DB_PORT=5432 + - DB_NAME=connthreads + - DB_USER=connthreads + - DB_PASS=password command: > sh -c " poetry run python manage.py migrate && poetry run python manage.py runserver 0.0.0.0:8000 " + volumes: + - dj-data:/app/media + + db: + image: postgres:16 + volumes: + - pg-data:/var/lib/postgresql/data + environment: + - POSTGRES_DB=connthreads + - POSTGRES_USER=connthreads + - POSTGRES_PASSWORD=password + - POSTGRES_HOST=db + healthcheck: + test: ["CMD-SHELL", "pg_isready -U connthreads"] + interval: 2s + timeout: 5s + retries: 3 volumes: - dj-sqlite: + dj-data: + pg-data: diff --git a/docker-compose.yml.j2 b/docker-compose.yml.j2 index 72606c8..74958ef 100644 --- a/docker-compose.yml.j2 +++ b/docker-compose.yml.j2 @@ -16,7 +16,11 @@ services: - DJANGO_SECRET_KEY={{ template.env.secret_key }} - DJANGO_ALLOWED_HOSTS={{ template.env.allowed_hosts }} - DJANGO_CSRF_TRUSTED_ORIGINS={{ template.env.trusted_origins }} - - SQLITE_PATH={{ template.env.sqlite_path }} + - DB_HOST=db + - DB_PORT={{ template.env.host_db_port }} + - DB_NAME={{ template.env.db_name }} + - DB_USER={{ template.env.db_user }} + - DB_PASSWORD={{ template.env.db_pass }} command: > sh -c " poetry run python manage.py migrate && @@ -34,6 +38,33 @@ services: {% endif %} {% endif %} + {% set service = 'db' %} + + db: + image: postgres:12 + restart: unless-stopped + environment: + - POSTGRES_DB={{ template.env.db_name }} + - POSTGRES_USER={{ template.env.db_user }} + - POSTGRES_PASSWORD={{ template.env.db_pass }} + - POSTGRES_HOST=db + {% if template.volumes is defined %} + {% set vols = (template.volumes | selectattr('service', 'eq', service)) %} + {% if vols is iterable and vols | length > 0 %} + + volumes: + {% for vol in vols %} + + - {{ vol.name }}:{{ vol.container_path }} + {% endfor %} + {% endif %} + {% endif %} + + healthcheck: + test: ["CMD-SHELL", "pg_isready -U {{ template.env.db_user }}"] + interval: 5s + timeout: 5s + retries: 5 # external volumes managed and defined by ansible volumes: