diff --git a/sample-applications/vehicle-dealership-sample-app/README.md b/sample-applications/vehicle-dealership-sample-app/README.md index 5b706d000..f123a7956 100644 --- a/sample-applications/vehicle-dealership-sample-app/README.md +++ b/sample-applications/vehicle-dealership-sample-app/README.md @@ -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 ` +`bash script.sh ` This will create the docker images, upload them to ECR and then create pods on EKS with those images. @@ -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. @@ -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 -P 3306 -u root -p +createdb vehicle_inventory -h -U root +createuser djangouser -h -U root -CREATE DATABASE vehicle_inventory; +psql -h -d vehicle_inventory -U root -CREATE USER 'djangouser'@'%' IDENTIFIED BY ''; - -GRANT ALL PRIVILEGES ON vehicle_inventory.* TO 'djangouser'@'%' WITH GRANT OPTION; - -FLUSH PRIVILEGES; +alter user djangouser with encrypted password ''; +grant all privileges on database vehicle_inventory to djangouser; aws s3 sync s3:// . @@ -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= -MYSQL_DATABASE=vehicle_inventory -MYSQL_USER=djangouser -MYSQL_PASSWORD= +POSTGRES_ROOT_PASSWORD= +POSTGRES_DATABASE=vehicle_inventory +POSTGRES_USER=djangouser +POSTGRES_PASSWORD= DB_SERVICE_HOST= DB_SERVICE_PORT=3306 IMAGE_BACKEND_SERVICE_HOST= @@ -113,7 +110,7 @@ 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 `. +1. Run `bash local_script.sh `. 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. @@ -121,10 +118,10 @@ They should be accessible through `0.0.0.0:8000` for the image service and `0.0. ## 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/: returns vehicle entry with id = 4. GET /vehicle-inventory//image: returns image file information from S3 for the specific vehicle by calling the image microservice 5. GET /images/name/: returns image information for from S3 if present. -6. PUT /images/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/: 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. \ No newline at end of file diff --git a/sample-applications/vehicle-dealership-sample-app/docker-compose.yaml b/sample-applications/vehicle-dealership-sample-app/docker-compose.yaml index 4b73b4d4a..89cd3a07c 100644 --- a/sample-applications/vehicle-dealership-sample-app/docker-compose.yaml +++ b/sample-applications/vehicle-dealership-sample-app/docker-compose.yaml @@ -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 diff --git a/sample-applications/vehicle-dealership-sample-app/eks/db-deployment.yaml b/sample-applications/vehicle-dealership-sample-app/eks/db-deployment.yaml index aafef6a6d..5f9a7d208 100644 --- a/sample-applications/vehicle-dealership-sample-app/eks/db-deployment.yaml +++ b/sample-applications/vehicle-dealership-sample-app/eks/db-deployment.yaml @@ -29,7 +29,7 @@ spec: spec: containers: - env: - - name: POSTGRES_DATABASE + - name: POSTGRES_DB value: vehicle_inventory - name: POSTGRES_PASSWORD value: ${POSTGRES_PASSWORD} diff --git a/sample-applications/vehicle-dealership-sample-app/eks/db-service.yaml b/sample-applications/vehicle-dealership-sample-app/eks/db-service.yaml index b1188e47e..dcb601c67 100644 --- a/sample-applications/vehicle-dealership-sample-app/eks/db-service.yaml +++ b/sample-applications/vehicle-dealership-sample-app/eks/db-service.yaml @@ -12,7 +12,7 @@ metadata: name: db spec: ports: - - port: 3306 + - port: 5432 selector: io.kompose.service: db status: 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 d37a8e6ef..7e2321bb6 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 @@ -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