Skip to content

Commit

Permalink
chore(): added feature to use a local PostgreSQL database
Browse files Browse the repository at this point in the history
  • Loading branch information
zsinnema committed Mar 22, 2024
1 parent 3e043ea commit a7daca8
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 5 deletions.
39 changes: 36 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,50 @@ python3 manage.py migrate
python3 manage.py runsslserver
```

### Running on docker with docker-compose
### Running the Backend on docker with docker-compose
the command below will start a docker container that maps/uses the backend folder
into the container. It will also start the Django development server with DEBUG=True

```bash
BUILDKIT_PROGRESS=plain docker-compose -f docker-compose-dev.yaml up --build
```

to stop:
### Running the PostgreSQL database with docker-compose
the command below will start a docker container that runs the PostgreSQL database.
To use it within your development Django server you need to set the following env vars
in your launch(file)

```
USE_PG=True
DB_HOST=localhost
DB_PORT=5432
DB_NAME=composer
DB_USER=composer
DB_PASSWORD=composer
```

To start the database server run this command:
```
docker-compose --file docker-compose-db.yaml up --build
```

to stop the database run this command:
```bash
docker-compose -f docker-compose-dev.yaml down
docker-compose -f docker-compose-db.yaml down
```

Example to run the backend using the Docker PostgreSQL database
```
cd backend
export USE_PG=True
export DB_HOST=localhost
export DB_PORT=5432
export DB_NAME=composer
export DB_USER=composer
export DB_PASSWORD=composer
python ./manage.py runsslserver
```

### Ingest sample NLP data
Expand Down
5 changes: 3 additions & 2 deletions backend/backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

# SECURITY WARNING: don't run with debug turned on in production!
PRODUCTION = os.environ.get("PRODUCTION", "False").lower() in ("true", "1")
USE_PG = os.environ.get("USE_PG", "False").lower() in ("true", "1")
DEBUG = os.environ.get("DEBUG", str(not PRODUCTION)).lower() in ("true", "1")

ALLOWED_HOSTS = [
Expand Down Expand Up @@ -101,7 +102,7 @@

# Database
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases
if PRODUCTION:
if PRODUCTION or USE_PG:
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
Expand Down Expand Up @@ -148,7 +149,7 @@

USE_I18N = True

USE_TZ = False
USE_TZ = True


# Static files (CSS, JavaScript, Images)
Expand Down
15 changes: 15 additions & 0 deletions docker-compose-db.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: "3.9"
services:
composer-db:
image: postgres:13
restart: "on-failure"
volumes:
- composer-db-data:/var/lib/postgresql/data
ports:
- "5432:5432"
env_file:
- .env

volumes:
composer-db-data:
composer-data:

0 comments on commit a7daca8

Please sign in to comment.