diff --git a/sample-applications/vehicle-dealership-sample-app/ImageServiceApp/ImageServiceApp/settings.py b/sample-applications/vehicle-dealership-sample-app/ImageServiceApp/ImageServiceApp/settings.py index 2d920fbb4..cb2b3833c 100644 --- a/sample-applications/vehicle-dealership-sample-app/ImageServiceApp/ImageServiceApp/settings.py +++ b/sample-applications/vehicle-dealership-sample-app/ImageServiceApp/ImageServiceApp/settings.py @@ -15,6 +15,10 @@ import os from pathlib import Path +from dotenv import load_dotenv + +load_dotenv() + # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent @@ -78,8 +82,12 @@ DATABASES = { "default": { - "ENGINE": "django.db.backends.sqlite3", - "NAME": BASE_DIR / "db.sqlite3", + "ENGINE": "django.db.backends.postgresql", + "USER": os.environ.get("POSTGRES_USER"), + "NAME": os.environ.get("POSTGRES_DATABASE"), + "PASSWORD": os.environ.get("POSTGRES_PASSWORD"), + "HOST": os.environ.get("DB_SERVICE_HOST"), + "PORT": os.environ.get("DB_SERVICE_PORT"), } } diff --git a/sample-applications/vehicle-dealership-sample-app/ImageServiceApp/requirements.txt b/sample-applications/vehicle-dealership-sample-app/ImageServiceApp/requirements.txt index e5d1a2059..b329cbad0 100644 --- a/sample-applications/vehicle-dealership-sample-app/ImageServiceApp/requirements.txt +++ b/sample-applications/vehicle-dealership-sample-app/ImageServiceApp/requirements.txt @@ -1,4 +1,5 @@ Django~=5.0 requests~=2.31.0 boto3~=1.34.14 -python-dotenv~=1.0.0 \ No newline at end of file +python-dotenv~=1.0.0 +psycopg2~=2.9.9 \ No newline at end of file diff --git a/sample-applications/vehicle-dealership-sample-app/README.md b/sample-applications/vehicle-dealership-sample-app/README.md index f123a7956..dcdbf8a83 100644 --- a/sample-applications/vehicle-dealership-sample-app/README.md +++ b/sample-applications/vehicle-dealership-sample-app/README.md @@ -89,7 +89,8 @@ IMAGE_BACKEND_SERVICE_PORT=8000 python3.11 manage.py migrate --noinput && python3.11 manage.py runserver 0.0.0.0:8001 ``` -7. Connect to the `image-service` EC2 instance and run the following: +7. Go to the EC2 console and select the `image-service`, Go Actions -> Networking -> Connect RDS database. +8. Connect to the `image-service` EC2 instance and run the following: ``` sudo dnf install python3.11 sudo dnf install python3.11-pip diff --git a/sample-applications/vehicle-dealership-sample-app/docker-compose.yaml b/sample-applications/vehicle-dealership-sample-app/docker-compose.yaml index 89cd3a07c..0de46070c 100644 --- a/sample-applications/vehicle-dealership-sample-app/docker-compose.yaml +++ b/sample-applications/vehicle-dealership-sample-app/docker-compose.yaml @@ -51,6 +51,10 @@ services: - $HOME/.aws/credentials:/home/app/.aws/credentials:ro ports: - "8000:8000" + depends_on: + db: + condition: service_healthy + volumes: data: diff --git a/sample-applications/vehicle-dealership-sample-app/eks/image-backend-deployment.yaml b/sample-applications/vehicle-dealership-sample-app/eks/image-backend-deployment.yaml index 7e2321bb6..2e623731a 100644 --- a/sample-applications/vehicle-dealership-sample-app/eks/image-backend-deployment.yaml +++ b/sample-applications/vehicle-dealership-sample-app/eks/image-backend-deployment.yaml @@ -43,5 +43,11 @@ spec: env: - name: S3_BUCKET value: ${S3_BUCKET} + - name: POSTGRES_DATABASE + value: vehicle_inventory + - name: POSTGRES_PASSWORD + value: ${POSTGRES_PASSWORD} + - name: POSTGRES_USER + value: djangouser restartPolicy: Always status: {} diff --git a/sample-applications/vehicle-dealership-sample-app/local_script.sh b/sample-applications/vehicle-dealership-sample-app/local_script.sh index 0f1625ffc..12e4de963 100644 --- a/sample-applications/vehicle-dealership-sample-app/local_script.sh +++ b/sample-applications/vehicle-dealership-sample-app/local_script.sh @@ -31,6 +31,11 @@ echo "DB_SERVICE_PORT=5432" >> VehicleInventoryApp/.env echo "IMAGE_BACKEND_SERVICE_HOST=image-service-backend" >> VehicleInventoryApp/.env echo "IMAGE_BACKEND_SERVICE_PORT=8000" >> VehicleInventoryApp/.env +echo "POSTGRES_DATABASE=vehicle_inventory" >> ImageServiceApp/.env +echo "POSTGRES_USER=djangouser" >> ImageServiceApp/.env +echo "POSTGRES_PASSWORD=${password}" >> ImageServiceApp/.env +echo "DB_SERVICE_HOST=db" >> ImageServiceApp/.env +echo "DB_SERVICE_PORT=5432" >> ImageServiceApp/.env echo "AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}" >> ImageServiceApp/.env echo "AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}" >> ImageServiceApp/.env echo "AWS_SESSION_TOKEN=${AWS_SESSION_TOKEN}" >> ImageServiceApp/.env