diff --git a/README.md b/README.md index 02ff5380..49af870a 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ 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 @@ -56,9 +56,42 @@ into the container. It will also start the Django development server with DEBUG= 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 diff --git a/backend/backend/settings.py b/backend/backend/settings.py index 7bcb7242..cb9aa67e 100644 --- a/backend/backend/settings.py +++ b/backend/backend/settings.py @@ -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 = [ @@ -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", @@ -148,7 +149,7 @@ USE_I18N = True -USE_TZ = False +USE_TZ = True # Static files (CSS, JavaScript, Images) diff --git a/docker-compose-db.yaml b/docker-compose-db.yaml new file mode 100644 index 00000000..3f2b557f --- /dev/null +++ b/docker-compose-db.yaml @@ -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: