Skip to content

Commit

Permalink
updating deployment to postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
qtrinh2 committed Sep 26, 2024
1 parent cc15507 commit 4dc876e
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 8 deletions.
6 changes: 3 additions & 3 deletions config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}
}

Expand Down
28 changes: 24 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
33 changes: 32 additions & 1 deletion docker-compose.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand All @@ -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:
Expand Down

0 comments on commit 4dc876e

Please sign in to comment.