From 98fac258c80b0de42f97e20d78fd18f2676e0ae4 Mon Sep 17 00:00:00 2001 From: Henry <> Date: Wed, 6 Nov 2024 23:15:35 +0800 Subject: [PATCH 1/3] Create .yaml files for kubernetes --- kubernetes/frontend-deployment.yaml | 22 ++++++ kubernetes/frontend-service.yaml | 12 +++ kubernetes/kafka-deployment.yaml | 42 +++++++++++ kubernetes/kafka-service.yaml | 11 +++ kubernetes/matching-service-deployment.yaml | 25 +++++++ kubernetes/matching-service-service.yaml | 11 +++ kubernetes/question-deployment.yaml | 22 ++++++ kubernetes/question-service.yaml | 11 +++ kubernetes/signaling-service-deployment.yaml | 22 ++++++ kubernetes/signaling-service-service.yaml | 11 +++ kubernetes/user-deployment.yaml | 78 ++++++++++++++++++++ kubernetes/user-env-configmap.yaml | 16 ++++ kubernetes/user-service.yaml | 12 +++ kubernetes/zookeeper-deployment.yaml | 39 ++++++++++ kubernetes/zookeeper-service.yaml | 11 +++ 15 files changed, 345 insertions(+) create mode 100644 kubernetes/frontend-deployment.yaml create mode 100644 kubernetes/frontend-service.yaml create mode 100644 kubernetes/kafka-deployment.yaml create mode 100644 kubernetes/kafka-service.yaml create mode 100644 kubernetes/matching-service-deployment.yaml create mode 100644 kubernetes/matching-service-service.yaml create mode 100644 kubernetes/question-deployment.yaml create mode 100644 kubernetes/question-service.yaml create mode 100644 kubernetes/signaling-service-deployment.yaml create mode 100644 kubernetes/signaling-service-service.yaml create mode 100644 kubernetes/user-deployment.yaml create mode 100644 kubernetes/user-env-configmap.yaml create mode 100644 kubernetes/user-service.yaml create mode 100644 kubernetes/zookeeper-deployment.yaml create mode 100644 kubernetes/zookeeper-service.yaml diff --git a/kubernetes/frontend-deployment.yaml b/kubernetes/frontend-deployment.yaml new file mode 100644 index 0000000000..75b9eb400e --- /dev/null +++ b/kubernetes/frontend-deployment.yaml @@ -0,0 +1,22 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: frontend +spec: + replicas: 1 + selector: + matchLabels: + app: frontend + template: + metadata: + labels: + app: frontend + spec: + containers: + - image: asia-southeast1-docker.pkg.dev/tokyo-crossbar-440806-u9/peerprep/frontend:latest + name: frontend + ports: + - containerPort: 3000 + protocol: TCP + imagePullPolicy: Always + restartPolicy: Always diff --git a/kubernetes/frontend-service.yaml b/kubernetes/frontend-service.yaml new file mode 100644 index 0000000000..02343dc96f --- /dev/null +++ b/kubernetes/frontend-service.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: frontend +spec: + type: LoadBalancer + ports: + - name: "3000" + port: 3000 + targetPort: 3000 + selector: + app: frontend diff --git a/kubernetes/kafka-deployment.yaml b/kubernetes/kafka-deployment.yaml new file mode 100644 index 0000000000..5ee83f42bd --- /dev/null +++ b/kubernetes/kafka-deployment.yaml @@ -0,0 +1,42 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: kafka-container +spec: + replicas: 1 + selector: + matchLabels: + app: kafka-container + template: + metadata: + labels: + app: kafka-container + spec: + containers: + - env: + - name: KAFKA_ADVERTISED_LISTENERS + value: PLAINTEXT://kafka:9092 + - name: KAFKA_BROKER_ID + value: "1" + - name: KAFKA_LISTENERS + value: PLAINTEXT://0.0.0.0:9092 + - name: KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR + value: "1" + - name: KAFKA_ZOOKEEPER_CONNECT + value: zookeeper:2181 + image: confluentinc/cp-kafka:7.7.1 + livenessProbe: + exec: + command: + - nc + - -z + - localhost + - "9092" + failureThreshold: 10 + periodSeconds: 10 + timeoutSeconds: 5 + name: kafka-containter + ports: + - containerPort: 9092 + protocol: TCP + restartPolicy: Always diff --git a/kubernetes/kafka-service.yaml b/kubernetes/kafka-service.yaml new file mode 100644 index 0000000000..2447f024b9 --- /dev/null +++ b/kubernetes/kafka-service.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: kafka-container +spec: + ports: + - name: "9092" + port: 9092 + targetPort: 9092 + selector: + app: kafka-container diff --git a/kubernetes/matching-service-deployment.yaml b/kubernetes/matching-service-deployment.yaml new file mode 100644 index 0000000000..fac4466f00 --- /dev/null +++ b/kubernetes/matching-service-deployment.yaml @@ -0,0 +1,25 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: matching-service +spec: + replicas: 1 + selector: + matchLabels: + app: matching-service + template: + metadata: + labels: + app: matching-service + spec: + containers: + - env: + - name: KAFKA_BROKER + value: kafka:9092 + image: asia-southeast1-docker.pkg.dev/tokyo-crossbar-440806-u9/peerprep/matching-service:latest + name: matching-service + ports: + - containerPort: 3002 + protocol: TCP + imagePullPolicy: Always + restartPolicy: Always diff --git a/kubernetes/matching-service-service.yaml b/kubernetes/matching-service-service.yaml new file mode 100644 index 0000000000..e6f03f3b27 --- /dev/null +++ b/kubernetes/matching-service-service.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: matching-service +spec: + ports: + - name: "3002" + port: 3002 + targetPort: 3002 + selector: + app: matching-service diff --git a/kubernetes/question-deployment.yaml b/kubernetes/question-deployment.yaml new file mode 100644 index 0000000000..7924071829 --- /dev/null +++ b/kubernetes/question-deployment.yaml @@ -0,0 +1,22 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: question +spec: + replicas: 1 + selector: + matchLabels: + app: question + template: + metadata: + labels: + app: question + spec: + containers: + - image: asia-southeast1-docker.pkg.dev/tokyo-crossbar-440806-u9/peerprep/question:latest + name: question + ports: + - containerPort: 2000 + protocol: TCP + imagePullPolicy: Always + restartPolicy: Always diff --git a/kubernetes/question-service.yaml b/kubernetes/question-service.yaml new file mode 100644 index 0000000000..22357febdf --- /dev/null +++ b/kubernetes/question-service.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: question +spec: + ports: + - name: "2000" + port: 2000 + targetPort: 2000 + selector: + app: question diff --git a/kubernetes/signaling-service-deployment.yaml b/kubernetes/signaling-service-deployment.yaml new file mode 100644 index 0000000000..f85defbb96 --- /dev/null +++ b/kubernetes/signaling-service-deployment.yaml @@ -0,0 +1,22 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: signaling-service +spec: + replicas: 1 + selector: + matchLabels: + app: signaling-service + template: + metadata: + labels: + app: signaling-service + spec: + containers: + - image: asia-southeast1-docker.pkg.dev/tokyo-crossbar-440806-u9/peerprep/signaling-service:latest + name: signaling-service + ports: + - containerPort: 3003 + protocol: TCP + imagePullPolicy: Always + restartPolicy: Always diff --git a/kubernetes/signaling-service-service.yaml b/kubernetes/signaling-service-service.yaml new file mode 100644 index 0000000000..29d1355c97 --- /dev/null +++ b/kubernetes/signaling-service-service.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: signaling-service +spec: + ports: + - name: "3003" + port: 3003 + targetPort: 3003 + selector: + app: signaling-service diff --git a/kubernetes/user-deployment.yaml b/kubernetes/user-deployment.yaml new file mode 100644 index 0000000000..f5fb0bbb64 --- /dev/null +++ b/kubernetes/user-deployment.yaml @@ -0,0 +1,78 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: user +spec: + replicas: 1 + selector: + matchLabels: + app: user + template: + metadata: + labels: + app: user + spec: + containers: + - env: + - name: BACKUP_EMAIL_PASS + valueFrom: + configMapKeyRef: + key: BACKUP_EMAIL_PASS + name: user-env + - name: BACKUP_EMAIL_USER + valueFrom: + configMapKeyRef: + key: BACKUP_EMAIL_USER + name: user-env + - name: DB_CLOUD_URI + valueFrom: + configMapKeyRef: + key: DB_CLOUD_URI + name: user-env + - name: DB_LOCAL_URI + valueFrom: + configMapKeyRef: + key: DB_LOCAL_URI + name: user-env + - name: EMAIL_PASS + valueFrom: + configMapKeyRef: + key: EMAIL_PASS + name: user-env + - name: EMAIL_USER + valueFrom: + configMapKeyRef: + key: EMAIL_USER + name: user-env + - name: ENV + valueFrom: + configMapKeyRef: + key: ENV + name: user-env + - name: FRONTEND_HOST + valueFrom: + configMapKeyRef: + key: FRONTEND_HOST + name: user-env + - name: FRONTEND_PORT + valueFrom: + configMapKeyRef: + key: FRONTEND_PORT + name: user-env + - name: JWT_SECRET + valueFrom: + configMapKeyRef: + key: JWT_SECRET + name: user-env + - name: PORT + valueFrom: + configMapKeyRef: + key: PORT + name: user-env + image: asia-southeast1-docker.pkg.dev/tokyo-crossbar-440806-u9/peerprep/user:latest + name: user + ports: + - containerPort: 3001 + protocol: TCP + imagePullPolicy: Always + restartPolicy: Always diff --git a/kubernetes/user-env-configmap.yaml b/kubernetes/user-env-configmap.yaml new file mode 100644 index 0000000000..fa8d675d3f --- /dev/null +++ b/kubernetes/user-env-configmap.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +data: + BACKUP_EMAIL_PASS: vvkj xhtv twsf roeh + BACKUP_EMAIL_USER: peerprep.no.reply@gmail.com + DB_CLOUD_URI: mongodb+srv://pewggls:osGEKKXddhYyew10@cluster0.vccw4.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0 + DB_LOCAL_URI: mongodb://127.0.0.1:27017/peerprepUserServiceDB + EMAIL_PASS: vhgj idnk fhme ooim + EMAIL_USER: peerprep9@gmail.com + ENV: PROD + FRONTEND_HOST: http://localhost + FRONTEND_PORT: "3000" + JWT_SECRET: you-can-replace-this-with-your-own-secret + PORT: "3001" +kind: ConfigMap +metadata: + name: user-env diff --git a/kubernetes/user-service.yaml b/kubernetes/user-service.yaml new file mode 100644 index 0000000000..ccb190d42a --- /dev/null +++ b/kubernetes/user-service.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: user +spec: + type: ClusterIP + ports: + - name: "3001" + port: 3001 + targetPort: 3001 + selector: + app: user diff --git a/kubernetes/zookeeper-deployment.yaml b/kubernetes/zookeeper-deployment.yaml new file mode 100644 index 0000000000..a99d842efd --- /dev/null +++ b/kubernetes/zookeeper-deployment.yaml @@ -0,0 +1,39 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: zookeeper +spec: + replicas: 1 + selector: + matchLabels: + app: zookeeper + template: + metadata: + labels: + app: zookeeper + spec: + containers: + - env: + - name: ZOOKEEPER_CLIENT_PORT + value: "2181" + image: confluentinc/cp-zookeeper:7.7.1 + livenessProbe: + exec: + command: + - echo + - ruok + - '|' + - nc + - localhost + - "2181" + - '|' + - grep + - imok + failureThreshold: 5 + periodSeconds: 10 + timeoutSeconds: 5 + name: zookeeper + ports: + - containerPort: 2181 + protocol: TCP + restartPolicy: Always diff --git a/kubernetes/zookeeper-service.yaml b/kubernetes/zookeeper-service.yaml new file mode 100644 index 0000000000..a456d0841e --- /dev/null +++ b/kubernetes/zookeeper-service.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: zookeeper +spec: + ports: + - name: "2181" + port: 2181 + targetPort: 2181 + selector: + app: zookeeper From 1e50d5cf241fe8265ba424026befc52bf0ac8702 Mon Sep 17 00:00:00 2001 From: Henry <> Date: Wed, 6 Nov 2024 23:25:27 +0800 Subject: [PATCH 2/3] add deployment of docker images to google artifact registry --- .github/workflows/ci.yml | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index caf62cbd04..ece672c3de 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,4 +29,25 @@ jobs: - name: Run Tests working-directory: backend/question-service - run: npm run test-ci \ No newline at end of file + run: npm run test-ci + + - name: Set up Google Cloud SDK + uses: google-github-actions/setup-gcloud@v1 + with: + project_id: tokyo-crossbar-440806-u9 + service_account_key: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }} + export_defauly_credentials: true + + - name: Configure Docker for Google Artifact Registry + run: | + gcloud auth configure-docker asia-southeast1-docker.pkg.dev + + - name: Build and push Docker images + run: | + docker compose build + services=("frontend" "matching-service" "question" "signaling-service" "user") + for service in "${services[@]}"; do + image="asia-southeast1-docker.pkg.dev/tokyo-crossbar-440806-u9/peerprep/$service:latest" + docker tag "cs3219-ay2425s1-project-g44-$service" "$image" + docker push "$image" + done \ No newline at end of file From 4c8161d4c32a90740d3b5ecd0211682f2714af79 Mon Sep 17 00:00:00 2001 From: pewggls <97406702+pewggls@users.noreply.github.com> Date: Wed, 6 Nov 2024 23:38:59 +0800 Subject: [PATCH 3/3] Update ci.yml --- .github/workflows/ci.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ece672c3de..6093f0070f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,6 +31,11 @@ jobs: working-directory: backend/question-service run: npm run test-ci + - name: Google Cloud Authentication + uses: "google-github-actions/auth@v1" + with: + credentials_json: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }} + - name: Set up Google Cloud SDK uses: google-github-actions/setup-gcloud@v1 with: @@ -50,4 +55,4 @@ jobs: image="asia-southeast1-docker.pkg.dev/tokyo-crossbar-440806-u9/peerprep/$service:latest" docker tag "cs3219-ay2425s1-project-g44-$service" "$image" docker push "$image" - done \ No newline at end of file + done