diff --git a/Helm_charts/MongoDB/Chart.yaml b/Helm_charts/MongoDB/Chart.yaml index 6cd8e87..2e3e8c2 100644 --- a/Helm_charts/MongoDB/Chart.yaml +++ b/Helm_charts/MongoDB/Chart.yaml @@ -1,6 +1,6 @@ -apiVersion: v2 -name: mongodb -description: A Helm chart for Kubernetes -type: application -version: 0.1.0 -appVersion: "1.0.0" +apiVersion: v2 +name: mongodb +description: A Helm chart for Kubernetes +type: application +version: 0.1.0 +appVersion: "1.0.0" diff --git a/Helm_charts/MongoDB/templates/configmap.yaml b/Helm_charts/MongoDB/templates/configmap.yaml index 5888e8e..f018af6 100644 --- a/Helm_charts/MongoDB/templates/configmap.yaml +++ b/Helm_charts/MongoDB/templates/configmap.yaml @@ -1,58 +1,58 @@ -apiVersion: v1 -kind: ConfigMap -metadata: - name: mongodb-configmap -data: - mongo.conf: | - storage: - dbPath: /data/db - ensure-users.js: | - const rootUser = cat('/etc/k8-test/admin/MONGO_ROOT_USERNAME'); - const rootPass = cat('/etc/k8-test/admin/MONGO_ROOT_PASSWORD'); - const usersStr = cat('/etc/k8-test/MONGO_USERS_LIST'); - const adminDb = db.getSiblingDB('admin'); - adminDb.auth(rootUser, rootPass); - print('Successfully authenticated admin user'); - - const databases = ['mp3s', 'videos']; - - databases.forEach((targetDbStr) => { - const targetDb = db.getSiblingDB(targetDbStr); - const customRoles = adminDb - .getRoles({ rolesInfo: 1, showBuiltinRoles: false }) - .map(role => role.role) - .filter(Boolean); - usersStr - .trim() - .split(';') - .map(s => s.split(':')) - .forEach(user => { - const username = user[0]; - const rolesStr = user[1]; - const password = user[2]; - if (!rolesStr || !password) { - return; - } - const roles = rolesStr.split(','); - const userDoc = { - user: username, - pwd: password, - roles: [ - { role: 'readWrite', db: targetDbStr }, - ...roles.map(role => { - if (!~customRoles.indexOf(role)) { - return { role, db: targetDbStr }; - } - return role; - }), - ], - }; - try { - targetDb.createUser(userDoc); - } catch (err) { - if (!~err.message.toLowerCase().indexOf('duplicate')) { - throw err; - } - } - }); +apiVersion: v1 +kind: ConfigMap +metadata: + name: mongodb-configmap +data: + mongo.conf: | + storage: + dbPath: /data/db + ensure-users.js: | + const rootUser = cat('/etc/k8-test/admin/MONGO_ROOT_USERNAME'); + const rootPass = cat('/etc/k8-test/admin/MONGO_ROOT_PASSWORD'); + const usersStr = cat('/etc/k8-test/MONGO_USERS_LIST'); + const adminDb = db.getSiblingDB('admin'); + adminDb.auth(rootUser, rootPass); + print('Successfully authenticated admin user'); + + const databases = ['mp3s', 'videos']; + + databases.forEach((targetDbStr) => { + const targetDb = db.getSiblingDB(targetDbStr); + const customRoles = adminDb + .getRoles({ rolesInfo: 1, showBuiltinRoles: false }) + .map(role => role.role) + .filter(Boolean); + usersStr + .trim() + .split(';') + .map(s => s.split(':')) + .forEach(user => { + const username = user[0]; + const rolesStr = user[1]; + const password = user[2]; + if (!rolesStr || !password) { + return; + } + const roles = rolesStr.split(','); + const userDoc = { + user: username, + pwd: password, + roles: [ + { role: 'readWrite', db: targetDbStr }, + ...roles.map(role => { + if (!~customRoles.indexOf(role)) { + return { role, db: targetDbStr }; + } + return role; + }), + ], + }; + try { + targetDb.createUser(userDoc); + } catch (err) { + if (!~err.message.toLowerCase().indexOf('duplicate')) { + throw err; + } + } + }); }); \ No newline at end of file diff --git a/Helm_charts/MongoDB/templates/pv.yaml b/Helm_charts/MongoDB/templates/pv.yaml index 82c78d0..cba07d6 100644 --- a/Helm_charts/MongoDB/templates/pv.yaml +++ b/Helm_charts/MongoDB/templates/pv.yaml @@ -1,14 +1,14 @@ -apiVersion: v1 -kind: PersistentVolume -metadata: - name: mongodb-pv - labels: - type: local -spec: - storageClassName: manual - capacity: - storage: 10Gi - accessModes: - - ReadWriteOnce - hostPath: - path: "/mnt/data" +apiVersion: v1 +kind: PersistentVolume +metadata: + name: mongodb-pv + labels: + type: local +spec: + storageClassName: manual + capacity: + storage: 10Gi + accessModes: + - ReadWriteOnce + hostPath: + path: "/mnt/data" diff --git a/Helm_charts/MongoDB/templates/pvc.yaml b/Helm_charts/MongoDB/templates/pvc.yaml index cd90e16..17dc66c 100644 --- a/Helm_charts/MongoDB/templates/pvc.yaml +++ b/Helm_charts/MongoDB/templates/pvc.yaml @@ -1,11 +1,11 @@ -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - name: mongodb-pvc -spec: - accessModes: - - ReadWriteOnce - resources: - requests: - storage: 1Gi - storageClassName: manual +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: mongodb-pvc +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi + storageClassName: manual diff --git a/Helm_charts/MongoDB/templates/secret.yaml b/Helm_charts/MongoDB/templates/secret.yaml index 8f280ab..f680ff1 100644 --- a/Helm_charts/MongoDB/templates/secret.yaml +++ b/Helm_charts/MongoDB/templates/secret.yaml @@ -1,11 +1,11 @@ -apiVersion: v1 -kind: Secret -metadata: - name: mongodb-secret -type: Opaque -stringData: - MONGO_ROOT_USERNAME: {{ .Values.secret.root_username }} - MONGO_ROOT_PASSWORD: {{ .Values.secret.root_password }} - MONGO_USERNAME: {{ .Values.secret.username }} - MONGO_PASSWORD: {{ .Values.secret.password }} - MONGO_USERS_LIST: {{ .Values.secret.users_list }} +apiVersion: v1 +kind: Secret +metadata: + name: mongodb-secret +type: Opaque +stringData: + MONGO_ROOT_USERNAME: {{ .Values.secret.root_username }} + MONGO_ROOT_PASSWORD: {{ .Values.secret.root_password }} + MONGO_USERNAME: {{ .Values.secret.username }} + MONGO_PASSWORD: {{ .Values.secret.password }} + MONGO_USERS_LIST: {{ .Values.secret.users_list }} diff --git a/Helm_charts/MongoDB/templates/service.yaml b/Helm_charts/MongoDB/templates/service.yaml index 73dbc69..5657bd4 100644 --- a/Helm_charts/MongoDB/templates/service.yaml +++ b/Helm_charts/MongoDB/templates/service.yaml @@ -1,13 +1,13 @@ -apiVersion: v1 -kind: Service -metadata: - name: mongodb - labels: - app: database -spec: - type: NodePort - ports: - - port: 27017 - nodePort: 30005 - selector: - app: database +apiVersion: v1 +kind: Service +metadata: + name: mongodb + labels: + app: database +spec: + type: NodePort + ports: + - port: 27017 + nodePort: 30005 + selector: + app: database diff --git a/Helm_charts/MongoDB/templates/statefulset.yaml b/Helm_charts/MongoDB/templates/statefulset.yaml index be88df1..55e2826 100644 --- a/Helm_charts/MongoDB/templates/statefulset.yaml +++ b/Helm_charts/MongoDB/templates/statefulset.yaml @@ -1,71 +1,71 @@ -apiVersion: apps/v1 -kind: StatefulSet -metadata: - name: mongodb -spec: - serviceName: mongodb - replicas: 1 - selector: - matchLabels: - app: database - template: - metadata: - labels: - app: database - selector: mongodb - spec: - containers: - - name: mongodb - image: mongo:4.0.8 - env: - - name: MONGO_INITDB_ROOT_USERNAME_FILE - value: /etc/k8-test/admin/MONGO_ROOT_USERNAME - - name: MONGO_INITDB_ROOT_PASSWORD_FILE - value: /etc/k8-test/admin/MONGO_ROOT_PASSWORD - volumeMounts: - - name: k8-test - mountPath: /etc/k8-test - readOnly: true - - name: mongodb-scripts - mountPath: /docker-entrypoint-initdb.d - readOnly: true - - name: mongodb-configmap - mountPath: /config - readOnly: true - - name: mongodb-data - mountPath: /data/db - volumes: - - name: k8-test - secret: - secretName: mongodb-secret - items: - - key: MONGO_ROOT_USERNAME - path: admin/MONGO_ROOT_USERNAME - mode: 0444 - - key: MONGO_ROOT_PASSWORD - path: admin/MONGO_ROOT_PASSWORD - mode: 0444 - - key: MONGO_USERNAME - path: MONGO_USERNAME - mode: 0444 - - key: MONGO_PASSWORD - path: MONGO_PASSWORD - mode: 0444 - - key: MONGO_USERS_LIST - path: MONGO_USERS_LIST - mode: 0444 - - name: mongodb-scripts - configMap: - name: mongodb-configmap - items: - - key: ensure-users.js - path: ensure-users.js - - name: mongodb-configmap - configMap: - name: mongodb-configmap - items: - - key: mongo.conf - path: mongo.conf - - name: mongodb-data - persistentVolumeClaim: - claimName: mongodb-pvc +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: mongodb +spec: + serviceName: mongodb + replicas: 1 + selector: + matchLabels: + app: database + template: + metadata: + labels: + app: database + selector: mongodb + spec: + containers: + - name: mongodb + image: mongo:4.0.8 + env: + - name: MONGO_INITDB_ROOT_USERNAME_FILE + value: /etc/k8-test/admin/MONGO_ROOT_USERNAME + - name: MONGO_INITDB_ROOT_PASSWORD_FILE + value: /etc/k8-test/admin/MONGO_ROOT_PASSWORD + volumeMounts: + - name: k8-test + mountPath: /etc/k8-test + readOnly: true + - name: mongodb-scripts + mountPath: /docker-entrypoint-initdb.d + readOnly: true + - name: mongodb-configmap + mountPath: /config + readOnly: true + - name: mongodb-data + mountPath: /data/db + volumes: + - name: k8-test + secret: + secretName: mongodb-secret + items: + - key: MONGO_ROOT_USERNAME + path: admin/MONGO_ROOT_USERNAME + mode: 0444 + - key: MONGO_ROOT_PASSWORD + path: admin/MONGO_ROOT_PASSWORD + mode: 0444 + - key: MONGO_USERNAME + path: MONGO_USERNAME + mode: 0444 + - key: MONGO_PASSWORD + path: MONGO_PASSWORD + mode: 0444 + - key: MONGO_USERS_LIST + path: MONGO_USERS_LIST + mode: 0444 + - name: mongodb-scripts + configMap: + name: mongodb-configmap + items: + - key: ensure-users.js + path: ensure-users.js + - name: mongodb-configmap + configMap: + name: mongodb-configmap + items: + - key: mongo.conf + path: mongo.conf + - name: mongodb-data + persistentVolumeClaim: + claimName: mongodb-pvc diff --git a/Helm_charts/MongoDB/templates/storageclass.yaml b/Helm_charts/MongoDB/templates/storageclass.yaml index e49de47..9b9fe7f 100644 --- a/Helm_charts/MongoDB/templates/storageclass.yaml +++ b/Helm_charts/MongoDB/templates/storageclass.yaml @@ -1,6 +1,6 @@ -apiVersion: storage.k8s.io/v1 -kind: StorageClass -metadata: - name: mongodb-storageclass -provisioner: kubernetes.io/no-provisioner -volumeBindingMode: WaitForFirstConsumer +apiVersion: storage.k8s.io/v1 +kind: StorageClass +metadata: + name: mongodb-storageclass +provisioner: kubernetes.io/no-provisioner +volumeBindingMode: WaitForFirstConsumer diff --git a/Helm_charts/MongoDB/values.yaml b/Helm_charts/MongoDB/values.yaml index c2677f3..fc94a22 100644 --- a/Helm_charts/MongoDB/values.yaml +++ b/Helm_charts/MongoDB/values.yaml @@ -1,6 +1,6 @@ -secret: - root_username: nasi - root_password: nasi1234 - username: nasi - password: nasi1234 +secret: + root_username: nasi + root_password: nasi1234 + username: nasi + password: nasi1234 users_list: nasi \ No newline at end of file diff --git a/Helm_charts/Postgres/Chart.yaml b/Helm_charts/Postgres/Chart.yaml index c88bd53..c7833fa 100644 --- a/Helm_charts/Postgres/Chart.yaml +++ b/Helm_charts/Postgres/Chart.yaml @@ -1,6 +1,6 @@ -apiVersion: v2 -name: postgres -description: A Helm chart for Kubernetes -type: application -version: 0.1.0 +apiVersion: v2 +name: postgres +description: A Helm chart for Kubernetes +type: application +version: 0.1.0 appVersion: "1.0.0" \ No newline at end of file diff --git a/Helm_charts/Postgres/init.sql b/Helm_charts/Postgres/init.sql index 8f7b0c7..34c8ed2 100644 --- a/Helm_charts/Postgres/init.sql +++ b/Helm_charts/Postgres/init.sql @@ -1,9 +1,9 @@ -CREATE TABLE auth_user ( - id integer GENERATED ALWAYS AS IDENTITY PRIMARY KEY, - email VARCHAR (255) NOT NULL, - password VARCHAR (255) NOT NULL -); - ---Add Username and Password for Admin User --- INSERT INTO auth_user (email, password) VALUES ('thomasfookins007helby@gmail.com', '123456'); -INSERT INTO auth_user (email, password) VALUES ('iambatmanthegoat@gmail.com', '123456'); \ No newline at end of file +CREATE TABLE auth_user ( + id integer GENERATED ALWAYS AS IDENTITY PRIMARY KEY, + email VARCHAR (255) NOT NULL, + password VARCHAR (255) NOT NULL +); + +--Add Username and Password for Admin User +-- INSERT INTO auth_user (email, password) VALUES ('thomasfookins007helby@gmail.com', '123456'); +INSERT INTO auth_user (email, password) VALUES ('dhuruv.18@gmail.com', 'adhirajsingh81'); \ No newline at end of file diff --git a/Helm_charts/Postgres/templates/postgres-deploy.yaml b/Helm_charts/Postgres/templates/postgres-deploy.yaml index 8dbce58..224d6c0 100644 --- a/Helm_charts/Postgres/templates/postgres-deploy.yaml +++ b/Helm_charts/Postgres/templates/postgres-deploy.yaml @@ -1,35 +1,35 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: postgres-deploy - labels: - name: postgres-deploy - app: auth-app -spec: - replicas: 1 - selector: - matchLabels: - name: postgres-pod - app: auth-app - template: - metadata: - name: postgres-pod - labels: - name: postgres-pod - app: auth-app - spec: - containers: - - name: postgres - image: {{ .Values.container.image }} - ports: - - containerPort: 5432 - env: - - name: POSTGRES_USER - value: {{ .Values.container.env.user }} - - name: POSTGRES_PASSWORD - value: {{ .Values.container.env.password }} - - name: POSTGRES_DB - value: {{ .Values.container.env.db }} - - name: POSTGRES_HOST_AUTH_METHOD - value: trust - +apiVersion: apps/v1 +kind: Deployment +metadata: + name: postgres-deploy + labels: + name: postgres-deploy + app: auth-app +spec: + replicas: 1 + selector: + matchLabels: + name: postgres-pod + app: auth-app + template: + metadata: + name: postgres-pod + labels: + name: postgres-pod + app: auth-app + spec: + containers: + - name: postgres + image: {{ .Values.container.image }} + ports: + - containerPort: 5432 + env: + - name: POSTGRES_USER + value: {{ .Values.container.env.user }} + - name: POSTGRES_PASSWORD + value: {{ .Values.container.env.password }} + - name: POSTGRES_DB + value: {{ .Values.container.env.db }} + - name: POSTGRES_HOST_AUTH_METHOD + value: trust + diff --git a/Helm_charts/Postgres/templates/postgres-service.yaml b/Helm_charts/Postgres/templates/postgres-service.yaml index bb126db..1ffaf8e 100644 --- a/Helm_charts/Postgres/templates/postgres-service.yaml +++ b/Helm_charts/Postgres/templates/postgres-service.yaml @@ -1,16 +1,16 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{ .Values.service.name }} - labels: - name: postgres-service - app: auth-app -spec: - type: NodePort - ports: - - port: {{ .Values.service.port }} - targetPort: {{ .Values.service.port }} - nodePort: {{ .Values.service.nodeport }} - selector: - name: postgres-pod - app: auth-app +apiVersion: v1 +kind: Service +metadata: + name: {{ .Values.service.name }} + labels: + name: postgres-service + app: auth-app +spec: + type: NodePort + ports: + - port: {{ .Values.service.port }} + targetPort: {{ .Values.service.port }} + nodePort: {{ .Values.service.nodeport }} + selector: + name: postgres-pod + app: auth-app diff --git a/Helm_charts/Postgres/values.yaml b/Helm_charts/Postgres/values.yaml index fd2d455..1e82e7c 100644 --- a/Helm_charts/Postgres/values.yaml +++ b/Helm_charts/Postgres/values.yaml @@ -1,11 +1,11 @@ -service: - name: db - port: 5432 - nodeport: 30003 - -container: - image: postgres - env: - user: nasi - password: cnd2023 +service: + name: db + port: 5432 + nodeport: 30003 + +container: + image: postgres + env: + user: nasi + password: cnd2023 db: authdb \ No newline at end of file diff --git a/Helm_charts/RabbitMQ/Chart.yaml b/Helm_charts/RabbitMQ/Chart.yaml index facf4df..96eb8c1 100644 --- a/Helm_charts/RabbitMQ/Chart.yaml +++ b/Helm_charts/RabbitMQ/Chart.yaml @@ -1,5 +1,5 @@ -apiVersion: v2 -name: rabbitmq -description: A Helm chart for Kubernetes -version: 0.1.0 +apiVersion: v2 +name: rabbitmq +description: A Helm chart for Kubernetes +version: 0.1.0 appVersion: "1.0.1" \ No newline at end of file diff --git a/Helm_charts/RabbitMQ/templates/configmap.yaml b/Helm_charts/RabbitMQ/templates/configmap.yaml index c0f15fd..c7e2783 100644 --- a/Helm_charts/RabbitMQ/templates/configmap.yaml +++ b/Helm_charts/RabbitMQ/templates/configmap.yaml @@ -1,6 +1,6 @@ -apiVersion: v1 -kind: ConfigMap -metadata: - name: rabbitmq-configmap -data: +apiVersion: v1 +kind: ConfigMap +metadata: + name: rabbitmq-configmap +data: PLACEHOLDER: "NONE" \ No newline at end of file diff --git a/Helm_charts/RabbitMQ/templates/pv.yaml b/Helm_charts/RabbitMQ/templates/pv.yaml index 007eec3..73fc37a 100644 --- a/Helm_charts/RabbitMQ/templates/pv.yaml +++ b/Helm_charts/RabbitMQ/templates/pv.yaml @@ -1,14 +1,14 @@ -apiVersion: v1 -kind: PersistentVolume -metadata: - name: rabbitmq-pv-volume - labels: - type: local -spec: - storageClassName: manual - capacity: - storage: 10Gi - accessModes: - - ReadWriteOnce - hostPath: - path: "/mnt/data" +apiVersion: v1 +kind: PersistentVolume +metadata: + name: rabbitmq-pv-volume + labels: + type: local +spec: + storageClassName: manual + capacity: + storage: 10Gi + accessModes: + - ReadWriteOnce + hostPath: + path: "/mnt/data" diff --git a/Helm_charts/RabbitMQ/templates/pvc.yaml b/Helm_charts/RabbitMQ/templates/pvc.yaml index 074febc..48212ea 100644 --- a/Helm_charts/RabbitMQ/templates/pvc.yaml +++ b/Helm_charts/RabbitMQ/templates/pvc.yaml @@ -1,11 +1,11 @@ -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - name: rabbitmq-pvc -spec: - accessModes: - - ReadWriteOnce - resources: - requests: - storage: 1Gi - storageClassName: manual +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: rabbitmq-pvc +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi + storageClassName: manual diff --git a/Helm_charts/RabbitMQ/templates/secret.yaml b/Helm_charts/RabbitMQ/templates/secret.yaml index d714599..14100fb 100644 --- a/Helm_charts/RabbitMQ/templates/secret.yaml +++ b/Helm_charts/RabbitMQ/templates/secret.yaml @@ -1,7 +1,7 @@ -apiVersion: v1 -kind: Secret -metadata: - name: rabbitmq-secret -stringData: - PLACEHOLDER: "NONE" +apiVersion: v1 +kind: Secret +metadata: + name: rabbitmq-secret +stringData: + PLACEHOLDER: "NONE" type: Opaque \ No newline at end of file diff --git a/Helm_charts/RabbitMQ/templates/service.yaml b/Helm_charts/RabbitMQ/templates/service.yaml index 137f2d7..849ae57 100644 --- a/Helm_charts/RabbitMQ/templates/service.yaml +++ b/Helm_charts/RabbitMQ/templates/service.yaml @@ -1,18 +1,18 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{ .Values.service.name }} -spec: - type: NodePort - selector: - app: rabbitmq - ports: - - name: http - protocol: TCP - port: 15672 - targetPort: 15672 - nodePort: 30004 - - name: amqp - protocol: TCP - port: 5672 - targetPort: 5672 +apiVersion: v1 +kind: Service +metadata: + name: {{ .Values.service.name }} +spec: + type: NodePort + selector: + app: rabbitmq + ports: + - name: http + protocol: TCP + port: 15672 + targetPort: 15672 + nodePort: 30004 + - name: amqp + protocol: TCP + port: 5672 + targetPort: 5672 diff --git a/Helm_charts/RabbitMQ/templates/statefulset.yaml b/Helm_charts/RabbitMQ/templates/statefulset.yaml index dbf1c47..70a620b 100644 --- a/Helm_charts/RabbitMQ/templates/statefulset.yaml +++ b/Helm_charts/RabbitMQ/templates/statefulset.yaml @@ -1,36 +1,36 @@ -apiVersion: apps/v1 -kind: StatefulSet -metadata: - name: rabbitmq -spec: - selector: - matchLabels: - app: rabbitmq - serviceName: "not-applicable" - template: - metadata: - labels: - app: rabbitmq - spec: - containers: - - name: rabbitmq - image: rabbitmq:3-management - ports: - - name: http - protocol: TCP - containerPort: 15672 - - name: amqp - protocol: TCP - containerPort: 5672 - envFrom: - - configMapRef: - name: rabbitmq-configmap - - secretRef: - name: rabbitmq-secret - volumeMounts: - - mountPath: /var/lib/rabbitmq - name: rabbitmq-volume - volumes: - - name: rabbitmq-volume - persistentVolumeClaim: +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: rabbitmq +spec: + selector: + matchLabels: + app: rabbitmq + serviceName: "not-applicable" + template: + metadata: + labels: + app: rabbitmq + spec: + containers: + - name: rabbitmq + image: rabbitmq:3-management + ports: + - name: http + protocol: TCP + containerPort: 15672 + - name: amqp + protocol: TCP + containerPort: 5672 + envFrom: + - configMapRef: + name: rabbitmq-configmap + - secretRef: + name: rabbitmq-secret + volumeMounts: + - mountPath: /var/lib/rabbitmq + name: rabbitmq-volume + volumes: + - name: rabbitmq-volume + persistentVolumeClaim: claimName: rabbitmq-pvc \ No newline at end of file diff --git a/Helm_charts/RabbitMQ/templates/storageclasses.yaml b/Helm_charts/RabbitMQ/templates/storageclasses.yaml index e6ce6fb..0dc32de 100644 --- a/Helm_charts/RabbitMQ/templates/storageclasses.yaml +++ b/Helm_charts/RabbitMQ/templates/storageclasses.yaml @@ -1,6 +1,6 @@ -apiVersion: storage.k8s.io/v1 -kind: StorageClass -metadata: - name: local-storage -provisioner: kubernetes.io/no-provisioner -volumeBindingMode: WaitForFirstConsumer +apiVersion: storage.k8s.io/v1 +kind: StorageClass +metadata: + name: local-storage +provisioner: kubernetes.io/no-provisioner +volumeBindingMode: WaitForFirstConsumer diff --git a/Helm_charts/RabbitMQ/values.yaml b/Helm_charts/RabbitMQ/values.yaml index 53003fa..7d78620 100644 --- a/Helm_charts/RabbitMQ/values.yaml +++ b/Helm_charts/RabbitMQ/values.yaml @@ -1,3 +1,3 @@ -service: - name: rabbitmq +service: + name: rabbitmq port: 15672 \ No newline at end of file diff --git a/README.md b/README.md index 09f0e4b..d3f5a12 100644 --- a/README.md +++ b/README.md @@ -1,274 +1 @@ -# Devops Project: video-converter -Converting mp4 videos to mp3 in a microservices architecture. - -## Architecture - -

- Architecture -

- -## Deploying a Python-based Microservice Application on AWS EKS - -### Introduction - -This document provides a step-by-step guide for deploying a Python-based microservice application on AWS Elastic Kubernetes Service (EKS). The application comprises four major microservices: `auth-server`, `converter-module`, `database-server` (PostgreSQL and MongoDB), and `notification-server`. - -### Prerequisites - -Before you begin, ensure that the following prerequisites are met: - -1. **Create an AWS Account:** If you do not have an AWS account, create one by following the steps [here](https://docs.aws.amazon.com/streams/latest/dev/setting-up.html). - -2. **Install Helm:** Helm is a Kubernetes package manager. Install Helm by following the instructions provided [here](https://helm.sh/docs/intro/install/). - -3. **Python:** Ensure that Python is installed on your system. You can download it from the [official Python website](https://www.python.org/downloads/). - -4. **AWS CLI:** Install the AWS Command Line Interface (CLI) following the official [installation guide](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html). - -5. **Install kubectl:** Install the latest stable version of `kubectl` on your system. You can find installation instructions [here](https://kubernetes.io/docs/tasks/tools/). - -6. **Databases:** Set up PostgreSQL and MongoDB for your application. - -### High Level Flow of Application Deployment - -Follow these steps to deploy your microservice application: - -1. **MongoDB and PostgreSQL Setup:** Create databases and enable automatic connections to them. - -2. **RabbitMQ Deployment:** Deploy RabbitMQ for message queuing, which is required for the `converter-module`. - -3. **Create Queues in RabbitMQ:** Before deploying the `converter-module`, create two queues in RabbitMQ: `mp3` and `video`. - -4. **Deploy Microservices:** - - **auth-server:** Navigate to the `auth-server` manifest folder and apply the configuration. - - **gateway-server:** Deploy the `gateway-server`. - - **converter-module:** Deploy the `converter-module`. Make sure to provide your email and password in `converter/manifest/secret.yaml`. - - **notification-server:** Configure email for notifications and two-factor authentication (2FA). - -5. **Application Validation:** Verify the status of all components by running: - ```bash - kubectl get all - ``` - -6. **Destroying the Infrastructure** - - -### Low Level Steps - -#### Cluster Creation - -1. **Log in to AWS Console:** - - Access the AWS Management Console with your AWS account credentials. - -2. **Create eksCluster IAM Role** - - Follow the steps mentioned in [this](https://docs.aws.amazon.com/eks/latest/userguide/service_IAM_role.html) documentation using root user - - After creating it will look like this: - -

- ekscluster_role -

- - - Please attach `AmazonEKS_CNI_Policy` explicitly if it is not attached by default - -3. **Create Node Role - AmazonEKSNodeRole** - - Follow the steps mentioned in [this](https://docs.aws.amazon.com/eks/latest/userguide/create-node-role.html#create-worker-node-role) documentation using root user - - Please note that you do NOT need to configure any VPC CNI policy mentioned after step 5.e under Creating the Amazon EKS node IAM role - - Simply attach the following policies to your role once you have created `AmazonEKS_CNI_Policy` , `AmazonEBSCSIDriverPolicy` , `AmazonEC2ContainerRegistryReadOnly` - incase it is not attached by default - - Your AmazonEKSNodeRole will look like this: - -

- Node_IAM -

- -4. **Open EKS Dashboard:** - - Navigate to the Amazon EKS service from the AWS Console dashboard. - -5. **Create EKS Cluster:** - - Click "Create cluster." - - Choose a name for your cluster. - - Configure networking settings (VPC, subnets). - - Choose the `eksCluster` IAM role that was created above - - Review and create the cluster. - -6. **Cluster Creation:** - - Wait for the cluster to provision, which may take several minutes. - -7. **Cluster Ready:** - - Once the cluster status shows as "Active," you can now create node groups. - -#### Node Group Creation - -1. In the "Compute" section, click on "Add node group." - -2. Choose the AMI (default), instance type (e.g., t3.medium), and the number of nodes (attach a screenshot here). - -3. Click "Create node group." - -#### Adding inbound rules in Security Group of Nodes - -**NOTE:** Ensure that all the necessary ports are open in the node security group. - -

- Inbound_rules_sg -

- -#### Enable EBS CSI Addon -1. enable addon `ebs csi` this is for enabling pvcs once cluster is created - -

- ebs_addon -

- -#### Deploying your application on EKS Cluster - -1. Clone the code from this repository. - -2. Set the cluster context: - ``` - aws eks update-kubeconfig --name --region - ``` - -### Commands - -Here are some essential Kubernetes commands for managing your deployment: - - -### MongoDB - -To install MongoDB, set the database username and password in `values.yaml`, then navigate to the MongoDB Helm chart folder and run: - -``` -cd Helm_charts/MongoDB -helm install mongo . -``` - -Connect to the MongoDB instance using: - -``` -mongosh mongodb://:@:30005/mp3s?authSource=admin -``` - -### PostgreSQL - -Set the database username and password in `values.yaml`. Install PostgreSQL from the PostgreSQL Helm chart folder and initialize it with the queries in `init.sql`. For PowerShell users: - -``` -cd .. -cd Postgres -helm install postgres . -``` - -Connect to the Postgres database and copy all the queries from the "init.sql" file. -``` -psql 'postgres://:@:30003/authdb' -``` - -### RabbitMQ - -Deploy RabbitMQ by running: - -``` -helm install rabbitmq . -``` - -Ensure you have created two queues in RabbitMQ named `mp3` and `video`. To create queues, visit `:30004>` and use default username `guest` and password `guest` - -**NOTE:** Ensure that all the necessary ports are open in the node security group. - -### Apply the manifest file for each microservice: - -- **Auth Service:** - ``` - cd auth-service/manifest - kubectl apply -f . - ``` - -- **Gateway Service:** - ``` - cd gateway-service/manifest - kubectl apply -f . - ``` - -- **Converter Service:** - ``` - cd converter-service/manifest - kubectl apply -f . - ``` - -- **Notification Service:** - ``` - cd notification-service/manifest - kubectl apply -f . - ``` - -### Application Validation - -After deploying the microservices, verify the status of all components by running: - -``` -kubectl get all -``` - -### Notification Configuration - - - -For configuring email notifications and two-factor authentication (2FA), follow these steps: - -1. Go to your Gmail account and click on your profile. - -2. Click on "Manage Your Google Account." - -3. Navigate to the "Security" tab on the left side panel. - -4. Enable "2-Step Verification." - -5. Search for the application-specific passwords. You will find it in the settings. - -6. Click on "Other" and provide your name. - -7. Click on "Generate" and copy the generated password. - -8. Paste this generated password in `converter/manifest/secret.yaml` along with your email. - -Run the application through the following API calls: - -# API Definition - -- **Login Endpoint** - ```http request - POST http://nodeIP:30002/login - ``` - - ```console - curl -X POST http://nodeIP:30002/login -u : - ``` - Expected output: success! - -- **Upload Endpoint** - ```http request - POST http://nodeIP:30002/upload - ``` - - ```console - curl -X POST -F 'file=@./video.mp4' -H 'Authorization: Bearer ' http://nodeIP:30002/upload - ``` - - Check if you received the ID on your email. - -- **Download Endpoint** - ```http request - GET http://nodeIP:30002/download?fid= - ``` - ```console - curl --output video.mp3 -X GET -H 'Authorization: Bearer ' "http://nodeIP:30002/download?fid=" - ``` - -## Destroying the Infrastructure - -To clean up the infrastructure, follow these steps: - -1. **Delete the Node Group:** Delete the node group associated with your EKS cluster. - -2. **Delete the EKS Cluster:** Once the nodes are deleted, you can proceed to delete the EKS cluster itself. \ No newline at end of file + diff --git a/src/auth-service/Dockerfile b/src/auth-service/Dockerfile index 0314d0d..48fe0ec 100644 --- a/src/auth-service/Dockerfile +++ b/src/auth-service/Dockerfile @@ -1,13 +1,13 @@ -FROM python:3.10-slim-bullseye - -RUN apt-get update && apt-get install -y --no-install-recommends --no-install-suggests build-essential libpq-dev python3-dev && pip install --no-cache-dir --upgrade pip - -WORKDIR /app -COPY ./requirements.txt /app - -RUN pip install --no-cache-dir --requirement /app/requirements.txt -COPY . /app - -EXPOSE 5000 - +FROM python:3.10-slim-bullseye + +RUN apt-get update && apt-get install -y --no-install-recommends --no-install-suggests build-essential libpq-dev python3-dev && pip install --no-cache-dir --upgrade pip + +WORKDIR /app +COPY ./requirements.txt /app + +RUN pip install --no-cache-dir --requirement /app/requirements.txt +COPY . /app + +EXPOSE 5000 + CMD ["python", "server.py"] \ No newline at end of file diff --git a/src/auth-service/manifest/configmap.yaml b/src/auth-service/manifest/configmap.yaml index c34dacc..094d162 100644 --- a/src/auth-service/manifest/configmap.yaml +++ b/src/auth-service/manifest/configmap.yaml @@ -1,9 +1,9 @@ -apiVersion: v1 -kind: ConfigMap -metadata: - name: auth-configmap -data: - DATABASE_HOST: db - DATABASE_NAME: authdb - DATABASE_USER: nasi - AUTH_TABLE: auth_user +apiVersion: v1 +kind: ConfigMap +metadata: + name: auth-configmap +data: + DATABASE_HOST: db + DATABASE_NAME: authdb + DATABASE_USER: nasi + AUTH_TABLE: auth_user diff --git a/src/auth-service/manifest/deployment.yaml b/src/auth-service/manifest/deployment.yaml index f3767e7..e12025c 100644 --- a/src/auth-service/manifest/deployment.yaml +++ b/src/auth-service/manifest/deployment.yaml @@ -1,30 +1,30 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: auth - labels: - app: auth -spec: - replicas: 2 - selector: - matchLabels: - app: auth - strategy: - type: RollingUpdate - rollingUpdate: - maxSurge: 3 - template: - metadata: - labels: - app: auth - spec: - containers: - - name: auth - image: nasi101/auth - ports: - - containerPort: 5000 - envFrom: - - configMapRef: - name: auth-configmap - - secretRef: - name: auth-secret +apiVersion: apps/v1 +kind: Deployment +metadata: + name: auth + labels: + app: auth +spec: + replicas: 2 + selector: + matchLabels: + app: auth + strategy: + type: RollingUpdate + rollingUpdate: + maxSurge: 3 + template: + metadata: + labels: + app: auth + spec: + containers: + - name: auth + image: nasi101/auth + ports: + - containerPort: 5000 + envFrom: + - configMapRef: + name: auth-configmap + - secretRef: + name: auth-secret diff --git a/src/auth-service/manifest/secret.yaml b/src/auth-service/manifest/secret.yaml index a662735..62e105d 100644 --- a/src/auth-service/manifest/secret.yaml +++ b/src/auth-service/manifest/secret.yaml @@ -1,9 +1,9 @@ -apiVersion: v1 -kind: Secret -metadata: - name: auth-secret -stringData: - PSQL_PASSWORD: nasi1234 - JWT_SECRET: sarcasm -type: Opaque - +apiVersion: v1 +kind: Secret +metadata: + name: auth-secret +stringData: + PSQL_PASSWORD: nasi1234 + JWT_SECRET: sarcasm +type: Opaque + diff --git a/src/auth-service/manifest/service.yaml b/src/auth-service/manifest/service.yaml index f069921..4888a53 100644 --- a/src/auth-service/manifest/service.yaml +++ b/src/auth-service/manifest/service.yaml @@ -1,12 +1,12 @@ -apiVersion: v1 -kind: Service -metadata: - name: auth -spec: - selector: - app: auth - type: ClusterIP - ports: - - port: 5000 - targetPort: 5000 - protocol: TCP +apiVersion: v1 +kind: Service +metadata: + name: auth +spec: + selector: + app: auth + type: ClusterIP + ports: + - port: 5000 + targetPort: 5000 + protocol: TCP diff --git a/src/auth-service/requirements.txt b/src/auth-service/requirements.txt index 15bf23b..c7a41b7 100644 --- a/src/auth-service/requirements.txt +++ b/src/auth-service/requirements.txt @@ -1,26 +1,26 @@ -astroid==2.12.13 -cffi==1.15.1 -click==8.1.3 -cryptography==38.0.3 -dill==0.3.6 -Flask==2.2.2 -importlib-metadata==5.0.0 -isort==5.10.1 -itsdangerous==2.1.2 -jedi==0.18.1 -Jinja2==3.1.2 -lazy-object-proxy==1.8.0 -MarkupSafe==2.1.1 -mccabe==0.7.0 -parso==0.8.3 -platformdirs==2.5.4 -psycopg2==2.9.5 -pycparser==2.21 -PyJWT==2.6.0 -pylint==2.15.6 -tomli==2.0.1 -tomlkit==0.11.6 -typing-extensions==4.4.0 -Werkzeug==2.2.2 -wrapt==1.14.1 -zipp==3.10.0 +astroid==2.12.13 +cffi==1.15.1 +click==8.1.3 +cryptography==38.0.3 +dill==0.3.6 +Flask==2.2.2 +importlib-metadata==5.0.0 +isort==5.10.1 +itsdangerous==2.1.2 +jedi==0.18.1 +Jinja2==3.1.2 +lazy-object-proxy==1.8.0 +MarkupSafe==2.1.1 +mccabe==0.7.0 +parso==0.8.3 +platformdirs==2.5.4 +psycopg2==2.9.5 +pycparser==2.21 +PyJWT==2.6.0 +pylint==2.15.6 +tomli==2.0.1 +tomlkit==0.11.6 +typing-extensions==4.4.0 +Werkzeug==2.2.2 +wrapt==1.14.1 +zipp==3.10.0 diff --git a/src/auth-service/server.py b/src/auth-service/server.py index 2355a90..9bfc375 100644 --- a/src/auth-service/server.py +++ b/src/auth-service/server.py @@ -1,68 +1,68 @@ -import jwt, datetime, os -import psycopg2 -from flask import Flask, request - -server = Flask(__name__) - -def get_db_connection(): - conn = psycopg2.connect(host=os.getenv('DATABASE_HOST'), - database=os.getenv('DATABASE_NAME'), - user=os.getenv('DATABASE_USER'), - password=os.getenv('DATABASE_PASSWORD'), - port=5432) - return conn - - -@server.route('/login', methods=['POST']) -def login(): - auth_table_name = os.getenv('AUTH_TABLE') - auth = request.authorization - if not auth or not auth.username or not auth.password: - return 'Could not verify', 401, {'WWW-Authenticate': 'Basic realm="Login required!"'} - - conn = get_db_connection() - cur = conn.cursor() - query = f"SELECT email, password FROM {auth_table_name} WHERE email = %s" - res = cur.execute(query, (auth.username,)) - - if res is None: - user_row = cur.fetchone() - email = user_row[0] - password = user_row[1] - - if auth.username != email or auth.password != password: - return 'Could not verify', 401, {'WWW-Authenticate': 'Basic realm="Login required!"'} - else: - return CreateJWT(auth.username, os.environ['JWT_SECRET'], True) - else: - return 'Could not verify', 401, {'WWW-Authenticate': 'Basic realm="Login required!"'} - -def CreateJWT(username, secret, authz): - return jwt.encode( - { - "username": username, - "exp": datetime.datetime.now(tz=datetime.timezone.utc) + datetime.timedelta(days=1), - "iat": datetime.datetime.now(tz=datetime.timezone.utc), - "admin": authz, - }, - secret, - algorithm="HS256", - ) - -@server.route('/validate', methods=['POST']) -def validate(): - encoded_jwt = request.headers['Authorization'] - - if not encoded_jwt: - return 'Unauthorized', 401, {'WWW-Authenticate': 'Basic realm="Login required!"'} - - encoded_jwt = encoded_jwt.split(' ')[1] - try: - decoded_jwt = jwt.decode(encoded_jwt, os.environ['JWT_SECRET'], algorithms=["HS256"]) - except: - return 'Unauthorized', 401, {'WWW-Authenticate': 'Basic realm="Login required!"'} - - return decoded_jwt, 200 - -if __name__ == '__main__': - server.run(host='0.0.0.0', port=5000) +import jwt, datetime, os +import psycopg2 +from flask import Flask, request + +server = Flask(__name__) + +def get_db_connection(): + conn = psycopg2.connect(host=os.getenv('DATABASE_HOST'), + database=os.getenv('DATABASE_NAME'), + user=os.getenv('DATABASE_USER'), + password=os.getenv('DATABASE_PASSWORD'), + port=5432) + return conn + + +@server.route('/login', methods=['POST']) +def login(): + auth_table_name = os.getenv('AUTH_TABLE') + auth = request.authorization + if not auth or not auth.username or not auth.password: + return 'Could not verify', 401, {'WWW-Authenticate': 'Basic realm="Login required!"'} + + conn = get_db_connection() + cur = conn.cursor() + query = f"SELECT email, password FROM {auth_table_name} WHERE email = %s" + res = cur.execute(query, (auth.username,)) + + if res is None: + user_row = cur.fetchone() + email = user_row[0] + password = user_row[1] + + if auth.username != email or auth.password != password: + return 'Could not verify', 401, {'WWW-Authenticate': 'Basic realm="Login required!"'} + else: + return CreateJWT(auth.username, os.environ['JWT_SECRET'], True) + else: + return 'Could not verify', 401, {'WWW-Authenticate': 'Basic realm="Login required!"'} + +def CreateJWT(username, secret, authz): + return jwt.encode( + { + "username": username, + "exp": datetime.datetime.now(tz=datetime.timezone.utc) + datetime.timedelta(days=1), + "iat": datetime.datetime.now(tz=datetime.timezone.utc), + "admin": authz, + }, + secret, + algorithm="HS256", + ) + +@server.route('/validate', methods=['POST']) +def validate(): + encoded_jwt = request.headers['Authorization'] + + if not encoded_jwt: + return 'Unauthorized', 401, {'WWW-Authenticate': 'Basic realm="Login required!"'} + + encoded_jwt = encoded_jwt.split(' ')[1] + try: + decoded_jwt = jwt.decode(encoded_jwt, os.environ['JWT_SECRET'], algorithms=["HS256"]) + except: + return 'Unauthorized', 401, {'WWW-Authenticate': 'Basic realm="Login required!"'} + + return decoded_jwt, 200 + +if __name__ == '__main__': + server.run(host='0.0.0.0', port=5000) diff --git a/src/converter-service/Dockerfile b/src/converter-service/Dockerfile index 6edab37..7a818ad 100644 --- a/src/converter-service/Dockerfile +++ b/src/converter-service/Dockerfile @@ -1,11 +1,11 @@ -FROM python:3.10-slim-bullseye - -RUN apt-get update && apt-get install -y --no-install-recommends --no-install-suggests build-essential libpq-dev python3-dev ffmpeg && pip install --no-cache-dir --upgrade pip - -WORKDIR /app -COPY ./requirements.txt /app - -RUN pip install --no-cache-dir --requirement /app/requirements.txt -COPY . /app - +FROM python:3.10-slim-bullseye + +RUN apt-get update && apt-get install -y --no-install-recommends --no-install-suggests build-essential libpq-dev python3-dev ffmpeg && pip install --no-cache-dir --upgrade pip + +WORKDIR /app +COPY ./requirements.txt /app + +RUN pip install --no-cache-dir --requirement /app/requirements.txt +COPY . /app + CMD ["python", "consumer.py"] \ No newline at end of file diff --git a/src/converter-service/consumer.py b/src/converter-service/consumer.py index b4fd31f..df498c2 100644 --- a/src/converter-service/consumer.py +++ b/src/converter-service/consumer.py @@ -1,43 +1,43 @@ -import pika, sys, os, time -from pymongo import MongoClient -import gridfs -from convert import to_mp3 - -def main(): - client = MongoClient(os.environ.get('MONGODB_URI')) - db_videos = client.videos - db_mp3s = client.mp3s - # gridfs - fs_videos = gridfs.GridFS(db_videos) - fs_mp3s = gridfs.GridFS(db_mp3s) - - # rabbitmq connection - connection = pika.BlockingConnection( - pika.ConnectionParameters(host='rabbitmq',heartbeat=0) - ) - channel = connection.channel() - - def callback(ch, method, properties, body): - err = to_mp3.start(body, fs_videos, fs_mp3s, ch) - if err: - ch.basic_nack(delivery_tag=method.delivery_tag) - else: - ch.basic_ack(delivery_tag=method.delivery_tag) - - channel.basic_consume( - queue=os.environ.get("VIDEO_QUEUE"), on_message_callback=callback - ) - - print("Waitting for messages, to exit press CTRL+C") - - channel.start_consuming() - -if __name__ == "__main__": - try: - main() - except KeyboardInterrupt: - print("Interrupted") - try: - sys.exit(0) - except SystemExit: - os._exit(0) +import pika, sys, os, time +from pymongo import MongoClient +import gridfs +from convert import to_mp3 + +def main(): + client = MongoClient(os.environ.get('MONGODB_URI')) + db_videos = client.videos + db_mp3s = client.mp3s + # gridfs + fs_videos = gridfs.GridFS(db_videos) + fs_mp3s = gridfs.GridFS(db_mp3s) + + # rabbitmq connection + connection = pika.BlockingConnection( + pika.ConnectionParameters(host='rabbitmq',heartbeat=0) + ) + channel = connection.channel() + + def callback(ch, method, properties, body): + err = to_mp3.start(body, fs_videos, fs_mp3s, ch) + if err: + ch.basic_nack(delivery_tag=method.delivery_tag) + else: + ch.basic_ack(delivery_tag=method.delivery_tag) + + channel.basic_consume( + queue=os.environ.get("VIDEO_QUEUE"), on_message_callback=callback + ) + + print("Waitting for messages, to exit press CTRL+C") + + channel.start_consuming() + +if __name__ == "__main__": + try: + main() + except KeyboardInterrupt: + print("Interrupted") + try: + sys.exit(0) + except SystemExit: + os._exit(0) diff --git a/src/converter-service/convert/to_mp3.py b/src/converter-service/convert/to_mp3.py index 8cbf121..8fe6d6c 100644 --- a/src/converter-service/convert/to_mp3.py +++ b/src/converter-service/convert/to_mp3.py @@ -1,42 +1,42 @@ -import pika, json, tempfile, os -from bson.objectid import ObjectId -import moviepy.editor - -def start(message, fs_videos, fs_mp3s, channel): - message = json.loads(message) - - # empty temp file - tf = tempfile.NamedTemporaryFile() - # video content - out = fs_videos.get(ObjectId(message["video_fid"])) - # add video content to temp file - tf.write(out.read()) - # create audio from temp video file - audio = moviepy.editor.VideoFileClip(tf.name).audio - tf.close() - - # write audio to the file - tf_path = tempfile.gettempdir() + f"/{message['video_fid']}.mp3" - audio.write_audiofile(tf_path) - - # save the file to the mongodb database - f = open(tf_path, "rb") - data = f.read() - fid = fs_mp3s.put(data) - f.close() - os.remove(tf_path) - - message["mp3_fid"] = str(fid) - - try: - channel.basic_publish( - exchange="", - routing_key=os.environ.get("MP3_QUEUE"), - body=json.dumps(message), - properties=pika.BasicProperties( - delivery_mode=pika.spec.PERSISTENT_DELIVERY_MODE - ), - ) - except Exception as err: - fs_mp3s.delete(fid) - return "failed to publish message" +import pika, json, tempfile, os +from bson.objectid import ObjectId +import moviepy.editor + +def start(message, fs_videos, fs_mp3s, channel): + message = json.loads(message) + + # empty temp file + tf = tempfile.NamedTemporaryFile() + # video content + out = fs_videos.get(ObjectId(message["video_fid"])) + # add video content to temp file + tf.write(out.read()) + # create audio from temp video file + audio = moviepy.editor.VideoFileClip(tf.name).audio + tf.close() + + # write audio to the file + tf_path = tempfile.gettempdir() + f"/{message['video_fid']}.mp3" + audio.write_audiofile(tf_path) + + # save the file to the mongodb database + f = open(tf_path, "rb") + data = f.read() + fid = fs_mp3s.put(data) + f.close() + os.remove(tf_path) + + message["mp3_fid"] = str(fid) + + try: + channel.basic_publish( + exchange="", + routing_key=os.environ.get("MP3_QUEUE"), + body=json.dumps(message), + properties=pika.BasicProperties( + delivery_mode=pika.spec.PERSISTENT_DELIVERY_MODE + ), + ) + except Exception as err: + fs_mp3s.delete(fid) + return "failed to publish message" diff --git a/src/converter-service/manifest/configmap.yaml b/src/converter-service/manifest/configmap.yaml index 9674f3e..07467d5 100644 --- a/src/converter-service/manifest/configmap.yaml +++ b/src/converter-service/manifest/configmap.yaml @@ -1,8 +1,8 @@ -apiVersion: v1 -kind: ConfigMap -metadata: - name: converter-configmap -data: - MP3_QUEUE: "mp3" - VIDEO_QUEUE: "video" - MONGODB_URI: "mongodb://nasi:nasi1234@mongodb:27017/mp3s?authSource=admin" #nodeip:nodeport +apiVersion: v1 +kind: ConfigMap +metadata: + name: converter-configmap +data: + MP3_QUEUE: "mp3" + VIDEO_QUEUE: "video" + MONGODB_URI: "mongodb://nasi:nasi1234@mongodb:27017/mp3s?authSource=admin" #nodeip:nodeport diff --git a/src/converter-service/manifest/converter-deploy.yaml b/src/converter-service/manifest/converter-deploy.yaml index b48b1ae..5a15d9a 100644 --- a/src/converter-service/manifest/converter-deploy.yaml +++ b/src/converter-service/manifest/converter-deploy.yaml @@ -1,30 +1,30 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: converter - labels: - app: converter -spec: - replicas: 4 - selector: - matchLabels: - app: converter - strategy: - type: RollingUpdate - rollingUpdate: - maxSurge: 8 - template: - metadata: - labels: - app: converter - spec: - containers: - - name: converter - image: nasi101/converter - envFrom: - - configMapRef: - name: converter-configmap - - secretRef: - name: converter-secret - - +apiVersion: apps/v1 +kind: Deployment +metadata: + name: converter + labels: + app: converter +spec: + replicas: 4 + selector: + matchLabels: + app: converter + strategy: + type: RollingUpdate + rollingUpdate: + maxSurge: 8 + template: + metadata: + labels: + app: converter + spec: + containers: + - name: converter + image: nasi101/converter + envFrom: + - configMapRef: + name: converter-configmap + - secretRef: + name: converter-secret + + diff --git a/src/converter-service/manifest/secret.yaml b/src/converter-service/manifest/secret.yaml index 18a8217..85b7900 100644 --- a/src/converter-service/manifest/secret.yaml +++ b/src/converter-service/manifest/secret.yaml @@ -1,7 +1,7 @@ -apiVersion: v1 -kind: Secret -metadata: - name: converter-secret -stringData: - PLACEHOLDER: "NONE" +apiVersion: v1 +kind: Secret +metadata: + name: converter-secret +stringData: + PLACEHOLDER: "NONE" type: Opaque \ No newline at end of file diff --git a/src/converter-service/requirements.txt b/src/converter-service/requirements.txt index 88832c6..a2d2cc8 100644 --- a/src/converter-service/requirements.txt +++ b/src/converter-service/requirements.txt @@ -1,29 +1,29 @@ -astroid==2.12.13 -certifi==2022.9.24 -charset-normalizer==2.1.1 -decorator==4.4.2 -dill==0.3.6 -dnspython==2.2.1 -idna==3.4 -imageio==2.22.4 -imageio-ffmpeg==0.4.7 -isort==5.10.1 -jedi==0.18.2 -lazy-object-proxy==1.8.0 -mccabe==0.7.0 -moviepy==1.0.3 -numpy==1.23.5 -parso==0.8.3 -pika==1.3.1 -Pillow==9.3.0 -platformdirs==2.5.4 -proglog==0.1.10 -pylint==2.15.6 -pymongo==4.3.3 -requests==2.28.1 -tomli==2.0.1 -tomlkit==0.11.6 -tqdm==4.64.1 -typing-extensions==4.4.0 -urllib3==1.26.12 -wrapt==1.14.1 +astroid==2.12.13 +certifi==2022.9.24 +charset-normalizer==2.1.1 +decorator==4.4.2 +dill==0.3.6 +dnspython==2.2.1 +idna==3.4 +imageio==2.22.4 +imageio-ffmpeg==0.4.7 +isort==5.10.1 +jedi==0.18.2 +lazy-object-proxy==1.8.0 +mccabe==0.7.0 +moviepy==1.0.3 +numpy==1.23.5 +parso==0.8.3 +pika==1.3.1 +Pillow==9.3.0 +platformdirs==2.5.4 +proglog==0.1.10 +pylint==2.15.6 +pymongo==4.3.3 +requests==2.28.1 +tomli==2.0.1 +tomlkit==0.11.6 +tqdm==4.64.1 +typing-extensions==4.4.0 +urllib3==1.26.12 +wrapt==1.14.1 diff --git a/src/gateway-service/Dockerfile b/src/gateway-service/Dockerfile index 0018d3b..b77d271 100644 --- a/src/gateway-service/Dockerfile +++ b/src/gateway-service/Dockerfile @@ -1,13 +1,13 @@ -FROM python:3.10-slim-bullseye - -RUN apt-get update && apt-get install -y --no-install-recommends --no-install-suggests build-essential libpq-dev python3-dev && pip install --no-cache-dir --upgrade pip - -WORKDIR /app -COPY ./requirements.txt /app - -RUN pip install --no-cache-dir --requirement /app/requirements.txt -COPY . /app - -EXPOSE 8080 - +FROM python:3.10-slim-bullseye + +RUN apt-get update && apt-get install -y --no-install-recommends --no-install-suggests build-essential libpq-dev python3-dev && pip install --no-cache-dir --upgrade pip + +WORKDIR /app +COPY ./requirements.txt /app + +RUN pip install --no-cache-dir --requirement /app/requirements.txt +COPY . /app + +EXPOSE 8080 + CMD ["python", "server.py"] \ No newline at end of file diff --git a/src/gateway-service/auth/validate.py b/src/gateway-service/auth/validate.py index 245a669..b9de461 100644 --- a/src/gateway-service/auth/validate.py +++ b/src/gateway-service/auth/validate.py @@ -1,21 +1,21 @@ -import os, requests - - -def token(request): - if not "Authorization" in request.headers: - return None, ("missing credentials", 401) - - token = request.headers["Authorization"] - - if not token: - return None, ("missing credentials", 401) - - response = requests.post( - f"http://{os.environ.get('AUTH_SVC_ADDRESS')}/validate", - headers={"Authorization": token}, - ) - - if response.status_code == 200: - return response.text, None - else: - return None, (response.text, response.status_code) +import os, requests + + +def token(request): + if not "Authorization" in request.headers: + return None, ("missing credentials", 401) + + token = request.headers["Authorization"] + + if not token: + return None, ("missing credentials", 401) + + response = requests.post( + f"http://{os.environ.get('AUTH_SVC_ADDRESS')}/validate", + headers={"Authorization": token}, + ) + + if response.status_code == 200: + return response.text, None + else: + return None, (response.text, response.status_code) diff --git a/src/gateway-service/auth_svc/access.py b/src/gateway-service/auth_svc/access.py index fd8b10f..62e7878 100644 --- a/src/gateway-service/auth_svc/access.py +++ b/src/gateway-service/auth_svc/access.py @@ -1,18 +1,18 @@ -import os, requests - - -def login(request): - auth = request.authorization - if not auth: - return None, ("missing credentials", 401) - - basicAuth = (auth.username, auth.password) - - response = requests.post( - f"http://{os.environ.get('AUTH_SVC_ADDRESS')}/login", auth=basicAuth - ) - - if response.status_code == 200: - return response.text, None - else: - return None, (response.text, response.status_code) +import os, requests + + +def login(request): + auth = request.authorization + if not auth: + return None, ("missing credentials", 401) + + basicAuth = (auth.username, auth.password) + + response = requests.post( + f"http://{os.environ.get('AUTH_SVC_ADDRESS')}/login", auth=basicAuth + ) + + if response.status_code == 200: + return response.text, None + else: + return None, (response.text, response.status_code) diff --git a/src/gateway-service/manifest/configmap.yaml b/src/gateway-service/manifest/configmap.yaml index 8bc592c..ad1c239 100644 --- a/src/gateway-service/manifest/configmap.yaml +++ b/src/gateway-service/manifest/configmap.yaml @@ -1,9 +1,9 @@ -apiVersion: v1 -kind: ConfigMap -metadata: - name: gateway-configmap -data: - AUTH_SVC_ADDRESS: "auth:5000" - MONGODB_VIDEOS_URI: "mongodb://nasi:nasi1234@mongodb:27017/videos?authSource=admin" - MONGODB_MP3S_URI: "mongodb://nasi:nasi1234@mongodb:27017/mp3s?authSource=admin" - +apiVersion: v1 +kind: ConfigMap +metadata: + name: gateway-configmap +data: + AUTH_SVC_ADDRESS: "auth:5000" + MONGODB_VIDEOS_URI: "mongodb://nasi:nasi1234@mongodb:27017/videos?authSource=admin" + MONGODB_MP3S_URI: "mongodb://nasi:nasi1234@mongodb:27017/mp3s?authSource=admin" + diff --git a/src/gateway-service/manifest/gateway-deploy.yaml b/src/gateway-service/manifest/gateway-deploy.yaml index a67dc56..cf06e52 100644 --- a/src/gateway-service/manifest/gateway-deploy.yaml +++ b/src/gateway-service/manifest/gateway-deploy.yaml @@ -1,27 +1,27 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: gateway - labels: - app: gateway -spec: - replicas: 2 - selector: - matchLabels: - app: gateway - strategy: - rollingUpdate: - maxSurge: 3 - template: - metadata: - labels: - app: gateway - spec: - containers: - - name: gateway - image: nasi101/gateway - envFrom: - - configMapRef: - name: gateway-configmap - - secretRef: - name: gateway-secret +apiVersion: apps/v1 +kind: Deployment +metadata: + name: gateway + labels: + app: gateway +spec: + replicas: 2 + selector: + matchLabels: + app: gateway + strategy: + rollingUpdate: + maxSurge: 3 + template: + metadata: + labels: + app: gateway + spec: + containers: + - name: gateway + image: nasi101/gateway + envFrom: + - configMapRef: + name: gateway-configmap + - secretRef: + name: gateway-secret diff --git a/src/gateway-service/manifest/secret.yaml b/src/gateway-service/manifest/secret.yaml index f9582f4..23d1d8b 100644 --- a/src/gateway-service/manifest/secret.yaml +++ b/src/gateway-service/manifest/secret.yaml @@ -1,7 +1,7 @@ -apiVersion: v1 -kind: Secret -metadata: - name: gateway-secret -stringData: - PLACEHOLDER: nothing +apiVersion: v1 +kind: Secret +metadata: + name: gateway-secret +stringData: + PLACEHOLDER: nothing type: Opaque \ No newline at end of file diff --git a/src/gateway-service/manifest/service.yaml b/src/gateway-service/manifest/service.yaml index 2c30fd4..4d48093 100644 --- a/src/gateway-service/manifest/service.yaml +++ b/src/gateway-service/manifest/service.yaml @@ -1,13 +1,13 @@ -apiVersion: v1 -kind: Service -metadata: - name: gateway -spec: - selector: - app: gateway - type: NodePort - ports: - - port: 8080 - targetPort: 8080 - nodePort: 30002 +apiVersion: v1 +kind: Service +metadata: + name: gateway +spec: + selector: + app: gateway + type: NodePort + ports: + - port: 8080 + targetPort: 8080 + nodePort: 30002 protocol: TCP \ No newline at end of file diff --git a/src/gateway-service/requirements.txt b/src/gateway-service/requirements.txt index 389b405..6bd7d35 100644 --- a/src/gateway-service/requirements.txt +++ b/src/gateway-service/requirements.txt @@ -1,31 +1,31 @@ -astroid==2.12.13 -certifi==2022.9.24 -charset-normalizer==2.1.1 -click==8.1.3 -dill==0.3.6 -dnspython==2.2.1 -Flask==2.2.2 -Flask-PyMongo==2.3.0 -idna==3.4 -importlib-metadata==5.0.0 -isort==5.10.1 -itsdangerous==2.1.2 -jedi==0.18.2 -Jinja2==3.1.2 -lazy-object-proxy==1.8.0 -prometheus-client==0.15.0 -MarkupSafe==2.1.1 -mccabe==0.7.0 -parso==0.8.3 -pika==1.3.1 -platformdirs==2.5.4 -pylint==2.15.6 -pymongo==4.3.3 -requests==2.28.1 -tomli==2.0.1 -tomlkit==0.11.6 -typing-extensions==4.4.0 -urllib3==1.26.12 -Werkzeug==2.2.2 -wrapt==1.14.1 -zipp==3.10.0 +astroid==2.12.13 +certifi==2022.9.24 +charset-normalizer==2.1.1 +click==8.1.3 +dill==0.3.6 +dnspython==2.2.1 +Flask==2.2.2 +Flask-PyMongo==2.3.0 +idna==3.4 +importlib-metadata==5.0.0 +isort==5.10.1 +itsdangerous==2.1.2 +jedi==0.18.2 +Jinja2==3.1.2 +lazy-object-proxy==1.8.0 +prometheus-client==0.15.0 +MarkupSafe==2.1.1 +mccabe==0.7.0 +parso==0.8.3 +pika==1.3.1 +platformdirs==2.5.4 +pylint==2.15.6 +pymongo==4.3.3 +requests==2.28.1 +tomli==2.0.1 +tomlkit==0.11.6 +typing-extensions==4.4.0 +urllib3==1.26.12 +Werkzeug==2.2.2 +wrapt==1.14.1 +zipp==3.10.0 diff --git a/src/gateway-service/server.py b/src/gateway-service/server.py index a78373a..413d959 100644 --- a/src/gateway-service/server.py +++ b/src/gateway-service/server.py @@ -1,82 +1,82 @@ -import os, gridfs, pika, json -from flask import Flask, request, send_file -from flask_pymongo import PyMongo -from auth import validate -from auth_svc import access -from storage import util -from bson.objectid import ObjectId -from werkzeug.middleware.dispatcher import DispatcherMiddleware - -server = Flask(__name__) - -mongo_video = PyMongo(server, uri=os.environ.get('MONGODB_VIDEOS_URI')) - -mongo_mp3 = PyMongo(server, uri=os.environ.get('MONGODB_MP3S_URI')) - -fs_videos = gridfs.GridFS(mongo_video.db) -fs_mp3s = gridfs.GridFS(mongo_mp3.db) - -connection = pika.BlockingConnection(pika.ConnectionParameters(host="rabbitmq", heartbeat=0)) -channel = connection.channel() - -@server.route("/login", methods=["POST"]) -def login(): - token, err = access.login(request) - - if not err: - return token - else: - return err - -@server.route("/upload", methods=["POST"]) -def upload(): - access, err = validate.token(request) - - if err: - unauth_count.inc() - return err - - access = json.loads(access) - - if access["admin"]: - if len(request.files) > 1 or len(request.files) < 1: - return "exactly 1 file required", 400 - - for _, f in request.files.items(): - err = util.upload(f, fs_videos, channel, access) - - if err: - return err - - return "success!", 200 - else: - return "not authorized", 401 - -@server.route("/download", methods=["GET"]) -def download(): - access, err = validate.token(request) - - if err: - unauth_count.inc() - return err - - access = json.loads(access) - - if access["admin"]: - fid_string = request.args.get("fid") - - if not fid_string: - return "fid is required", 400 - - try: - out = fs_mp3s.get(ObjectId(fid_string)) - return send_file(out, download_name=f"{fid_string}.mp3") - except Exception as err: - print(err) - return "internal server error", 500 - - return "not authorized", 401 - - -if __name__ == "__main__": - server.run(host="0.0.0.0", port=8080) +import os, gridfs, pika, json +from flask import Flask, request, send_file +from flask_pymongo import PyMongo +from auth import validate +from auth_svc import access +from storage import util +from bson.objectid import ObjectId +from werkzeug.middleware.dispatcher import DispatcherMiddleware + +server = Flask(__name__) + +mongo_video = PyMongo(server, uri=os.environ.get('MONGODB_VIDEOS_URI')) + +mongo_mp3 = PyMongo(server, uri=os.environ.get('MONGODB_MP3S_URI')) + +fs_videos = gridfs.GridFS(mongo_video.db) +fs_mp3s = gridfs.GridFS(mongo_mp3.db) + +connection = pika.BlockingConnection(pika.ConnectionParameters(host="rabbitmq", heartbeat=0)) +channel = connection.channel() + +@server.route("/login", methods=["POST"]) +def login(): + token, err = access.login(request) + + if not err: + return token + else: + return err + +@server.route("/upload", methods=["POST"]) +def upload(): + access, err = validate.token(request) + + if err: + unauth_count.inc() + return err + + access = json.loads(access) + + if access["admin"]: + if len(request.files) > 1 or len(request.files) < 1: + return "exactly 1 file required", 400 + + for _, f in request.files.items(): + err = util.upload(f, fs_videos, channel, access) + + if err: + return err + + return "success!", 200 + else: + return "not authorized", 401 + +@server.route("/download", methods=["GET"]) +def download(): + access, err = validate.token(request) + + if err: + unauth_count.inc() + return err + + access = json.loads(access) + + if access["admin"]: + fid_string = request.args.get("fid") + + if not fid_string: + return "fid is required", 400 + + try: + out = fs_mp3s.get(ObjectId(fid_string)) + return send_file(out, download_name=f"{fid_string}.mp3") + except Exception as err: + print(err) + return "internal server error", 500 + + return "not authorized", 401 + + +if __name__ == "__main__": + server.run(host="0.0.0.0", port=8080) diff --git a/src/gateway-service/storage/util.py b/src/gateway-service/storage/util.py index a9283fe..8109e39 100644 --- a/src/gateway-service/storage/util.py +++ b/src/gateway-service/storage/util.py @@ -1,29 +1,29 @@ -import pika, json - - -def upload(f, fs, channel, access): - try: - fid = fs.put(f) - except Exception as err: - print(err) - return "internal server error, fs level", 500 - - message = { - "video_fid": str(fid), - "mp3_fid": None, - "username": access["username"], - } - - try: - channel.basic_publish( - exchange="", - routing_key="video", - body=json.dumps(message), - properties=pika.BasicProperties( - delivery_mode=pika.spec.PERSISTENT_DELIVERY_MODE - ), - ) - except Exception as err: - print(err) - fs.delete(fid) - return f"internal server error rabbitmq issue, {err}", 500 +import pika, json + + +def upload(f, fs, channel, access): + try: + fid = fs.put(f) + except Exception as err: + print(err) + return "internal server error, fs level", 500 + + message = { + "video_fid": str(fid), + "mp3_fid": None, + "username": access["username"], + } + + try: + channel.basic_publish( + exchange="", + routing_key="video", + body=json.dumps(message), + properties=pika.BasicProperties( + delivery_mode=pika.spec.PERSISTENT_DELIVERY_MODE + ), + ) + except Exception as err: + print(err) + fs.delete(fid) + return f"internal server error rabbitmq issue, {err}", 500 diff --git a/src/notification-service/Dockerfile b/src/notification-service/Dockerfile index 6edab37..7a818ad 100644 --- a/src/notification-service/Dockerfile +++ b/src/notification-service/Dockerfile @@ -1,11 +1,11 @@ -FROM python:3.10-slim-bullseye - -RUN apt-get update && apt-get install -y --no-install-recommends --no-install-suggests build-essential libpq-dev python3-dev ffmpeg && pip install --no-cache-dir --upgrade pip - -WORKDIR /app -COPY ./requirements.txt /app - -RUN pip install --no-cache-dir --requirement /app/requirements.txt -COPY . /app - +FROM python:3.10-slim-bullseye + +RUN apt-get update && apt-get install -y --no-install-recommends --no-install-suggests build-essential libpq-dev python3-dev ffmpeg && pip install --no-cache-dir --upgrade pip + +WORKDIR /app +COPY ./requirements.txt /app + +RUN pip install --no-cache-dir --requirement /app/requirements.txt +COPY . /app + CMD ["python", "consumer.py"] \ No newline at end of file diff --git a/src/notification-service/consumer.py b/src/notification-service/consumer.py index 0762ba2..6d5da3b 100644 --- a/src/notification-service/consumer.py +++ b/src/notification-service/consumer.py @@ -1,32 +1,32 @@ -import pika, sys, os -from send import email - -def main(): - # rabbitmq connection - connection = pika.BlockingConnection(pika.ConnectionParameters(host="rabbitmq",heartbeat=0)) - channel = connection.channel() - - def callback(ch, method, properties, body): - err = email.notification(body) - if err: - ch.basic_nack(delivery_tag=method.delivery_tag) - else: - ch.basic_ack(delivery_tag=method.delivery_tag) - - channel.basic_consume( - queue=os.environ.get("MP3_QUEUE"), on_message_callback=callback - ) - - print("Waiting for messages. To exit press CTRL+C") - - channel.start_consuming() - -if __name__ == "__main__": - try: - main() - except KeyboardInterrupt: - print("Interrupted") - try: - sys.exit(0) - except SystemExit: +import pika, sys, os +from send import email + +def main(): + # rabbitmq connection + connection = pika.BlockingConnection(pika.ConnectionParameters(host="rabbitmq",heartbeat=0)) + channel = connection.channel() + + def callback(ch, method, properties, body): + err = email.notification(body) + if err: + ch.basic_nack(delivery_tag=method.delivery_tag) + else: + ch.basic_ack(delivery_tag=method.delivery_tag) + + channel.basic_consume( + queue=os.environ.get("MP3_QUEUE"), on_message_callback=callback + ) + + print("Waiting for messages. To exit press CTRL+C") + + channel.start_consuming() + +if __name__ == "__main__": + try: + main() + except KeyboardInterrupt: + print("Interrupted") + try: + sys.exit(0) + except SystemExit: os._exit(0) \ No newline at end of file diff --git a/src/notification-service/manifest/configmap.yaml b/src/notification-service/manifest/configmap.yaml index 51a93f9..dc4eaf9 100644 --- a/src/notification-service/manifest/configmap.yaml +++ b/src/notification-service/manifest/configmap.yaml @@ -1,7 +1,7 @@ -apiVersion: v1 -kind: ConfigMap -metadata: - name: notification-configmap -data: - MP3_QUEUE: "mp3" +apiVersion: v1 +kind: ConfigMap +metadata: + name: notification-configmap +data: + MP3_QUEUE: "mp3" VIDEO_QUEUE: "video" \ No newline at end of file diff --git a/src/notification-service/manifest/notification-deploy.yaml b/src/notification-service/manifest/notification-deploy.yaml index c739c73..a85b325 100644 --- a/src/notification-service/manifest/notification-deploy.yaml +++ b/src/notification-service/manifest/notification-deploy.yaml @@ -1,28 +1,28 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: notification - labels: - app: notification -spec: - replicas: 2 - selector: - matchLabels: - app: notification - strategy: - type: RollingUpdate - rollingUpdate: - maxSurge: 8 - template: - metadata: - labels: - app: notification - spec: - containers: - - name: notification - image: nasi101/notification - envFrom: - - configMapRef: - name: notification-configmap - - secretRef: - name: notification-secret +apiVersion: apps/v1 +kind: Deployment +metadata: + name: notification + labels: + app: notification +spec: + replicas: 2 + selector: + matchLabels: + app: notification + strategy: + type: RollingUpdate + rollingUpdate: + maxSurge: 8 + template: + metadata: + labels: + app: notification + spec: + containers: + - name: notification + image: nasi101/notification + envFrom: + - configMapRef: + name: notification-configmap + - secretRef: + name: notification-secret diff --git a/src/notification-service/manifest/secret.yaml b/src/notification-service/manifest/secret.yaml index 011b22b..a2c3aa6 100644 --- a/src/notification-service/manifest/secret.yaml +++ b/src/notification-service/manifest/secret.yaml @@ -1,10 +1,10 @@ -apiVersion: v1 -kind: Secret -metadata: - name: notification-secret -stringData: - GMAIL_ADDRESS: "iambatmanthegoat@gmail.com" #enter your email to get the id - GMAIL_PASSWORD: "gkxk acif rhgv erjr" -type: Opaque - +apiVersion: v1 +kind: Secret +metadata: + name: notification-secret +stringData: + GMAIL_ADDRESS: "dhuruv.18@gmail.com" #enter your email to get the id + GMAIL_PASSWORD: "xxyp ucsa vpou rfpm" +type: Opaque + # Passw0rd@1234 \ No newline at end of file diff --git a/src/notification-service/requirements.txt b/src/notification-service/requirements.txt index af32496..36236af 100644 --- a/src/notification-service/requirements.txt +++ b/src/notification-service/requirements.txt @@ -1,11 +1,11 @@ -astroid==2.9.3 -isort==5.10.1 -jedi==0.18.1 -lazy-object-proxy==1.7.1 -mccabe==0.6.1 -parso==0.8.3 -pika==1.2.0 -platformdirs==2.5.1 -pylint==2.12.2 -toml==0.10.2 +astroid==2.9.3 +isort==5.10.1 +jedi==0.18.1 +lazy-object-proxy==1.7.1 +mccabe==0.6.1 +parso==0.8.3 +pika==1.2.0 +platformdirs==2.5.1 +pylint==2.12.2 +toml==0.10.2 wrapt==1.13.3 \ No newline at end of file diff --git a/src/notification-service/send/email.py b/src/notification-service/send/email.py index 7e58435..30dbb3a 100644 --- a/src/notification-service/send/email.py +++ b/src/notification-service/send/email.py @@ -1,22 +1,22 @@ -import smtplib, os, json -from email.message import EmailMessage - -def notification(message): - message = json.loads(message) - mp3_fid = message["mp3_fid"] - sender_address = os.environ.get("GMAIL_ADDRESS") - sender_password = os.environ.get("GMAIL_PASSWORD") - receiver_address = message["username"] - - msg = EmailMessage() - msg.set_content(f"mp3 file_id: {mp3_fid} is now ready!") - msg["Subject"] = "MP3 Download" - msg["From"] = sender_address - msg["To"] = receiver_address - - session = smtplib.SMTP("smtp.gmail.com", 587) - session.starttls() - session.login(sender_address, sender_password) - session.send_message(msg, sender_address, receiver_address) - session.quit() +import smtplib, os, json +from email.message import EmailMessage + +def notification(message): + message = json.loads(message) + mp3_fid = message["mp3_fid"] + sender_address = os.environ.get("GMAIL_ADDRESS") + sender_password = os.environ.get("GMAIL_PASSWORD") + receiver_address = message["username"] + + msg = EmailMessage() + msg.set_content(f"mp3 file_id: {mp3_fid} is now ready!") + msg["Subject"] = "MP3 Download" + msg["From"] = sender_address + msg["To"] = receiver_address + + session = smtplib.SMTP("smtp.gmail.com", 587) + session.starttls() + session.login(sender_address, sender_password) + session.send_message(msg, sender_address, receiver_address) + session.quit() print("Mail Sent") \ No newline at end of file