Skip to content

Commit

Permalink
updated image service to use postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
AsakerMohd committed Feb 1, 2024
1 parent 5de7ae8 commit 146ad83
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"),
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Django~=5.0
requests~=2.31.0
boto3~=1.34.14
python-dotenv~=1.0.0
python-dotenv~=1.0.0
psycopg2~=2.9.9
3 changes: 2 additions & 1 deletion sample-applications/vehicle-dealership-sample-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ services:
- $HOME/.aws/credentials:/home/app/.aws/credentials:ro
ports:
- "8000:8000"
depends_on:
db:
condition: service_healthy

volumes:
data:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 146ad83

Please sign in to comment.