Skip to content

Commit

Permalink
updated eks configs for postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
AsakerMohd committed Jan 29, 2024
1 parent 5e64cfd commit 23c62c8
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 23 deletions.
35 changes: 16 additions & 19 deletions sample-applications/vehicle-dealership-sample-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ This directory contains code for a microservices based sample app that is used t

### EKS
To get started with AWS EKS, you can run the one touch script as below.
`bash script.sh <account_id> <cluster_name> <region> <mysql_password> <s3_bucket_name>`
`bash script.sh <account_id> <cluster_name> <region> <postgres_password> <s3_bucket_name>`

This will create the docker images, upload them to ECR and then create pods on EKS with those images.

Expand Down Expand Up @@ -52,7 +52,7 @@ To deploy to EC2, you will have to go through the following steps.
- AmazonS3FullAccess
- AmazonSQSFullAccess
- Name one vehicle-service and the other image-service
5. Go to RDS and create a MySQL DB with the following configurations:
5. Go to RDS and create a Postgres DB with the following configurations:
- Use the Dev/Test template
- Update the Master username to `root` and create a password of your choosing. Write it down since you will need it later.
- In the Connectivity settings, choose the VPC and security group created in step 3.
Expand All @@ -61,18 +61,15 @@ To deploy to EC2, you will have to go through the following steps.
```
sudo dnf install python3.11
sudo dnf install python3.11-pip
sudo dnf install mariadb105
sudo dnf install -y mariadb105-devel gcc python3.11-devel
sudo dnf install postgresql15
mysql -h <RDS_DB_Endpoint> -P 3306 -u root -p<password_from_step_5>
createdb vehicle_inventory -h <rds_url> -U root
createuser djangouser -h <rds_url> -U root
CREATE DATABASE vehicle_inventory;
psql -h <rds_url> -d vehicle_inventory -U root
CREATE USER 'djangouser'@'%' IDENTIFIED BY '<password_of_your_choosing>';
GRANT ALL PRIVILEGES ON vehicle_inventory.* TO 'djangouser'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
alter user djangouser with encrypted password '<password_of_your_choosing>';
grant all privileges on database vehicle_inventory to djangouser;
aws s3 sync s3://<s3_bucket_that_has_python_code> .
Expand All @@ -81,10 +78,10 @@ cd to the vehicle microservice directory and run:
python3.11 -m pip install -r requirements.txt
Create a .env file with the following:
MYSQL_ROOT_PASSWORD=<password_from_RDS_setup>
MYSQL_DATABASE=vehicle_inventory
MYSQL_USER=djangouser
MYSQL_PASSWORD=<password_from_this_step>
POSTGRES_ROOT_PASSWORD=<password_from_RDS_setup>
POSTGRES_DATABASE=vehicle_inventory
POSTGRES_USER=djangouser
POSTGRES_PASSWORD=<password_from_this_step>
DB_SERVICE_HOST=<RDS_DB_endpoint>
DB_SERVICE_PORT=3306
IMAGE_BACKEND_SERVICE_HOST=<image-service_ec2_public_IP>
Expand Down Expand Up @@ -113,18 +110,18 @@ Now you should be able to access the APIs below through the EC2 addr:port of eac

### Locally with Docker
To get started, make sure you either have you AWS creds in `$HOME/.aws` or the following: `AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN` are exported.
1. Run `bash local_script.sh <mysql_pass> <s3_bucket_name>`.
1. Run `bash local_script.sh <postgres_pass> <s3_bucket_name>`.
This will create docker containers, move the requirement env variables there and start them up.

They should be accessible through `0.0.0.0:8000` for the image service and `0.0.0.0:8001` for the vehicle service.

## APIs

The following are the APIs and what they do:
1. GET /vehicle-inventory/: returns all the vehicles entries for mysql db
2. PUT /vehicle-inventory/: puts vehicle into db. For example: `curl -X POST http://0.0.0.0:8001/vehicle-inventory/ -d '{"make": "BMW","model": "M340","year": 2022,"image_name": "newCar.jpg"}'`
1. GET /vehicle-inventory/: returns all the vehicles entries for postgres db
2. POST /vehicle-inventory/: puts vehicle into db. For example: `curl -X POST http://0.0.0.0:8001/vehicle-inventory/ -d '{"make": "BMW","model": "M340","year": 2022,"image_name": "newCar.jpg"}'`
3. GET /vehicle-inventory/<int>: returns vehicle entry with id = <int>
4. GET /vehicle-inventory/<int>/image: returns image file information from S3 for the specific vehicle by calling the image microservice
5. GET /images/name/<image_name>: returns image information for <image_name> from S3 if present.
6. PUT /images/name/<image_name>: creates an empty file in S3. This is an async endpoint since it will put image name in an SQS queue and not wait for the file to be created in S3. Instead, a long running thread will poll SQS and then create the image file later.
6. POST /images/name/<image_name>: creates an empty file in S3. This is an async endpoint since it will put image name in an SQS queue and not wait for the file to be created in S3. Instead, a long running thread will poll SQS and then create the image file later.
7. GET /image/remote-image: makes a remote http call to google.com.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ services:
context: .
dockerfile: ImageServiceApp/Dockerfile
container_name: image-service-backend
command: sh -c "python3 manage.py migrate --noinput && python3 manage.py collectstatic --noinput && python3 manage.py runserver 0.0.0.0:8000"
command: sh -c "python3 manage.py runserver 0.0.0.0:8000"
restart: always
volumes:
- ./ImageServiceApp/.:/image-service-app
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ spec:
spec:
containers:
- env:
- name: POSTGRES_DATABASE
- name: POSTGRES_DB
value: vehicle_inventory
- name: POSTGRES_PASSWORD
value: ${POSTGRES_PASSWORD}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ metadata:
name: db
spec:
ports:
- port: 3306
- port: 5432
selector:
io.kompose.service: db
status:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ spec:
- args:
- sh
- -c
- python3 manage.py migrate --noinput; python3 manage.py collectstatic --noinput; python3 manage.py runserver 0.0.0.0:8000
- python3 manage.py runserver 0.0.0.0:8000
image: ${REPOSITORY_PREFIX}/pythonsampleapp/image-service:latest
name: image-service-backend
imagePullPolicy: Always
Expand Down

0 comments on commit 23c62c8

Please sign in to comment.