Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion session-7/calculator/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from prometheus_client import Summary, Counter, Histogram, Gauge
import time
from flask_cors import CORS
import os

#app = Flask(__name__)
#mongo = MongoClient('database', 27017)
Expand All @@ -14,7 +15,13 @@


app = Flask(__name__)
app.config["MONGO_URI"] = "mongodb://root:root@mongo-service.default.svc.cluster.local:27017/admin"
mongo_user = os.getenv('MONGO_USER')
mongo_pass = os.getenv('MONGO_PASS')
mongo_host = os.getenv('MONGO_HOST')
mongo_port = os.getenv('MONGO_PORT')

mongo_uri = f"mongodb://{mongo_user}:{mongo_pass}@{mongo_host}:{mongo_port}/admin"
app.config["MONGO_URI"] = mongo_uri
mongo = PyMongo(app)
hits_collection = mongo.db.usage

Expand Down
7 changes: 7 additions & 0 deletions session-7/deployment_yamls/app-configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: mongo-config
data:
MONGO_HOST: "mongo-service.default.svc.cluster.local"
MONGO_PORT: "27017"
23 changes: 22 additions & 1 deletion session-7/deployment_yamls/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,30 @@ spec:
serviceAccountName: mongo-admin
containers:
- name: calculator-app
image: syednadeembe/myflaskapp:productionImage_app
image: linuxshakil/myflaskapp:productionImage_app-v1
ports:
- containerPort: 9000
env:
- name: MONGO_HOST
valueFrom:
configMapKeyRef:
name: mongo-config
key: MONGO_HOST
- name: MONGO_PORT
valueFrom:
configMapKeyRef:
name: mongo-config
key: MONGO_PORT
- name: MONGO_USER
valueFrom:
secretKeyRef:
name: db-secrets
key: MONGO_USER
- name: MONGO_PASS
valueFrom:
secretKeyRef:
name: db-secrets
key: MONGO_PASS
---
apiVersion: v1
kind: Service
Expand Down
9 changes: 9 additions & 0 deletions session-7/deployment_yamls/db-secrets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v1
kind: Secret
metadata:
name: db-secrets
type: Opaque
data:
MONGO_USER: cm9vdA==
MONGO_PASS: cm9vdA==

12 changes: 9 additions & 3 deletions session-7/deployment_yamls/dbase.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,20 @@ spec:
serviceAccountName: mongo-admin
containers:
- name: mongodb
image: mongo:latest
image: mongo:4.4
ports:
- containerPort: 27017
env:
- name: MONGO_INITDB_ROOT_USERNAME
value: root
valueFrom:
secretKeyRef:
name: db-secrets
key: MONGO_USER
- name: MONGO_INITDB_ROOT_PASSWORD
value: root
valueFrom:
secretKeyRef:
name: db-secrets
key: MONGO_PASS
---
apiVersion: v1
kind: Service
Expand Down
6 changes: 6 additions & 0 deletions session-7/deployment_yamls/ui-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: ui-config
data:
BASE_URL: "http://192.168.1.103:30080"
9 changes: 8 additions & 1 deletion session-7/deployment_yamls/ui.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,16 @@ spec:
spec:
containers:
- name: ui
image: syednadeembe/myflaskapp:productionImage_ui
image: linuxshakil/myflaskapp:productionImage_ui-v1
ports:
- containerPort: 80
env:
- name: BASE_URL
valueFrom:
configMapKeyRef:
name: ui-config
key: BASE_URL

---
apiVersion: v1
kind: Service
Expand Down
16 changes: 11 additions & 5 deletions session-7/ui/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# Use a lightweight HTTP server image as the base
FROM nginx:alpine

# Copy the HTML and JavaScript files to the default Nginx public directory
COPY index.html /usr/share/nginx/html
COPY calculator.js /usr/share/nginx/html
# Install envsubst
RUN apk add --no-cache gettext

# Copy your HTML and JS as-is
COPY index.html /usr/share/nginx/html/
COPY calculator.js /usr/share/nginx/html/
COPY entrypoint.sh /entrypoint.sh

RUN chmod +x /entrypoint.sh

# Expose port 80
EXPOSE 80

CMD ["/entrypoint.sh"]
4 changes: 2 additions & 2 deletions session-7/ui/calculator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Configure the base URL for the backend services
const baseUrl = "http://localhost:30080"; // Use the actual service name and port
const baseUrl = "${BASE_URL}";


// Function to update and display website hits
Expand Down Expand Up @@ -41,4 +41,4 @@ document.getElementById("multiplyBtn").addEventListener("click", () => calculate
document.getElementById("divideBtn").addEventListener("click", () => calculate("divide"));

// Initial update and display of website hits
updateHits();
updateHits();
8 changes: 8 additions & 0 deletions session-7/ui/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

# Replace ${BASE_URL} in-place in calculator.js
envsubst '${BASE_URL}' < /usr/share/nginx/html/calculator.js > /usr/share/nginx/html/calculator.tmp.js && \
mv /usr/share/nginx/html/calculator.tmp.js /usr/share/nginx/html/calculator.js

# Start Nginx
nginx -g 'daemon off;'
Loading