Skip to content

Commit

Permalink
Add ability to run with ACTUAL db
Browse files Browse the repository at this point in the history
  • Loading branch information
KenwoodFox committed Jan 11, 2025
1 parent c9c660c commit 34938d7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
libpq-dev \
python3-dev \
python3-psycopg2 \
gettext \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
Expand Down
7 changes: 7 additions & 0 deletions battery/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@
}
}

# Use PostgreSQL if DATABASE_URL is provided
DATABASE_URL = os.getenv("DATABASE_URL")
if DATABASE_URL:
import dj_database_url

DATABASES["default"] = dj_database_url.parse(DATABASE_URL)


# Password validation
# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators
Expand Down
10 changes: 6 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

services:
db:
image: postgres:10.5
image: postgres:15
restart: "no"
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_USER=battery_user
- POSTGRES_PASSWORD=battery_password
- POSTGRES_DB=battery_db
healthcheck:
test: ["CMD", "pg_isready", "-q", "-d", "battery_db", "-U", "postgres"]
test:
["CMD", "pg_isready", "-q", "-d", "battery_db", "-U", "battery_user"]
interval: 10s
timeout: 5s
retries: 5
Expand Down Expand Up @@ -43,5 +44,6 @@ services:
dockerfile: Dockerfile
environment:
LOG_LEVEL: "DEBUG"
DATABASE_URL: postgres://battery_user:battery_password@db:5432/battery_db
restart: "no"
command: "true"
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# App
django

# DB
dj-database-url
psycopg2

# WSGI
gunicorn

0 comments on commit 34938d7

Please sign in to comment.