From f3e6c40374213d5364b4336b771367d3b4af611f Mon Sep 17 00:00:00 2001 From: GokhanDuzel Date: Fri, 15 Dec 2023 23:09:10 -0500 Subject: [PATCH] Containerized the app and Updated UI --- server/Dockerfile | 28 ++++++++ server/deployment.yaml | 29 ++++++++ server/djangoapp/restapis.py | 17 +++-- .../djangoapp/templates/djangoapp/about.html | 55 ++++++++++++--- .../templates/djangoapp/add_review.html | 8 +-- .../templates/djangoapp/contact.html | 67 +++++++++++++++++-- .../templates/djangoapp/dealer_details.html | 27 ++++---- .../djangoapp/templates/djangoapp/index.html | 11 +-- server/djangoapp/views.py | 39 ++++++----- server/entrypoint.sh | 17 +++++ 10 files changed, 235 insertions(+), 63 deletions(-) create mode 100644 server/Dockerfile create mode 100644 server/deployment.yaml create mode 100755 server/entrypoint.sh diff --git a/server/Dockerfile b/server/Dockerfile new file mode 100644 index 0000000000..25696fb89a --- /dev/null +++ b/server/Dockerfile @@ -0,0 +1,28 @@ + FROM python:3.8.2 + + ENV PYTHONBUFFERED 1 + ENV PYTHONWRITEBYTECODE 1 + + RUN apt-get update \ + && apt-get install -y netcat + + ENV APP=/app + + # Change the workdir. + WORKDIR $APP + + # Install the requirements + COPY requirements.txt $APP + + RUN pip3 install -r requirements.txt + + # Copy the rest of the files + COPY . $APP + + EXPOSE 8000 + + RUN chmod +x /app/entrypoint.sh + + ENTRYPOINT ["/bin/bash","/app/entrypoint.sh"] + + CMD ["gunicorn", "--bind", ":8000", "--workers", "3", "djangobackend.wsgi"] \ No newline at end of file diff --git a/server/deployment.yaml b/server/deployment.yaml new file mode 100644 index 0000000000..1eebbf60ce --- /dev/null +++ b/server/deployment.yaml @@ -0,0 +1,29 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + run: dealership + name: dealership +spec: + replicas: 1 + selector: + matchLabels: + run: dealership + strategy: + rollingUpdate: + maxSurge: 25% + maxUnavailable: 25% + type: RollingUpdate + template: + metadata: + labels: + run: dealership + spec: + containers: + - image: us.icr.io/sn-labs-gduzel/dealership:latest + imagePullPolicy: Always + name: dealership + ports: + - containerPort: 8000 + protocol: TCP + restartPolicy: Always \ No newline at end of file diff --git a/server/djangoapp/restapis.py b/server/djangoapp/restapis.py index ca95954155..dd4ad113a6 100644 --- a/server/djangoapp/restapis.py +++ b/server/djangoapp/restapis.py @@ -120,9 +120,9 @@ def get_dealer_by_id_from_cf(url, dealer_id): # Create a get_dealer_reviews_from_cf method to get reviews by dealer id from a cloud function # - Call get_request() with specified arguments # - Parse JSON results into a DealerView object list -def get_dealer_reviews_from_cf(url, id): +def get_dealer_reviews_from_cf(url, dealer_id): results = [] - json_result = get_request(url, id=id) + json_result = get_request(url, id=dealer_id) print(json_result) if isinstance(json_result, list): @@ -172,9 +172,14 @@ def analyze_review_sentiments(dealerreview): authenticator = IAMAuthenticator(api_key) natural_language_understanding = NaturalLanguageUnderstandingV1(version='2021-08-01',authenticator=authenticator) natural_language_understanding.set_service_url(url) - response = natural_language_understanding.analyze( text=dealerreview,features=Features(sentiment=SentimentOptions(targets=[dealerreview]))).get_result() - label=json.dumps(response, indent=2) - label = response['sentiment']['document']['label'] + try: + response = natural_language_understanding.analyze( text=dealerreview,features=Features(sentiment=SentimentOptions(targets=[dealerreview]))).get_result() + label=json.dumps(response, indent=2) + label = response['sentiment']['document']['label'] + + return(label) - return(label) + except: + print("Can't analyze the sentiment") + return 'none' diff --git a/server/djangoapp/templates/djangoapp/about.html b/server/djangoapp/templates/djangoapp/about.html index 00851adad1..fed108173f 100644 --- a/server/djangoapp/templates/djangoapp/about.html +++ b/server/djangoapp/templates/djangoapp/about.html @@ -3,22 +3,57 @@ About Us + {% load static %} -
-
-
+ + +
+
+

About Best Cars

-
-

Welcome to Best Cars dealership,

-

home to the best cars in North America

-

and soon in Canada. We sell domestic and

-

imported cars at reasonable pricessssss.

+
+
+

Welcome to Best Cars dealership, home to the best cars in North America and soon in Canada.

+

We sell domestic and imported cars at reasonable prices.

+
-
-
+
+
\ No newline at end of file diff --git a/server/djangoapp/templates/djangoapp/add_review.html b/server/djangoapp/templates/djangoapp/add_review.html index 6aa3619163..0454b2104a 100644 --- a/server/djangoapp/templates/djangoapp/add_review.html +++ b/server/djangoapp/templates/djangoapp/add_review.html @@ -22,15 +22,15 @@

Add Review for {{dealer.full_name}}

Enter your review here:
- + -
+
(select purchased car information below if checked)
-
+
Select your car (Model-Make-Year):
- {% for car in cars %} {% endfor %} diff --git a/server/djangoapp/templates/djangoapp/contact.html b/server/djangoapp/templates/djangoapp/contact.html index 2df13a6713..33267659a0 100644 --- a/server/djangoapp/templates/djangoapp/contact.html +++ b/server/djangoapp/templates/djangoapp/contact.html @@ -3,18 +3,71 @@ Contact Us + {% load static %} -
-
-
+ + +
+
+

Contact Us

-
Phone number: +1 234 567 8910
-
Some street number, in the middle of somewhere.
-
+
+
+
Phone number:
+

+1 234 567 8910

+
+
+
Email:
+

info@example.com

+
+
+
+
+
Address:
+
Some street number, in the middle of somewhere.
+
+
+
Business Hours:
+

Monday to Friday: 9 AM - 5 PM
Saturday: 10 AM - 2 PM

+
+
-
+
+
\ No newline at end of file diff --git a/server/djangoapp/templates/djangoapp/dealer_details.html b/server/djangoapp/templates/djangoapp/dealer_details.html index 8a3b36859a..7d6eadadca 100644 --- a/server/djangoapp/templates/djangoapp/dealer_details.html +++ b/server/djangoapp/templates/djangoapp/dealer_details.html @@ -10,7 +10,7 @@