From 507260f200857add5af0b7e7f21f47f5bd2fbd77 Mon Sep 17 00:00:00 2001 From: Sayed Jawad Hussaini Date: Wed, 7 May 2025 05:56:08 +0200 Subject: [PATCH] final assignment --- sk1/fixed-backend.sh | 63 ---- sk1/fixed-backend.yml | 57 ---- sk1/k8s/secret-example.yml | 9 + sk1/not usable | 1 - sk1/not use/add-routes.sh | 68 ----- sk1/not use/backend-fixed-deployment.yaml | 42 --- sk1/not use/certificate.yaml | 8 - sk1/not use/complete-fix.sh | 352 ---------------------- sk1/not use/complete-ingress-setup.sh | 167 ---------- sk1/not use/complete-ingress.yaml | 28 -- sk1/not use/create-ingress.sh | 55 ---- sk1/not use/debug-instructions.txt | 13 - sk1/not use/deploy-fixed-backend.sh | 145 --------- sk1/not use/fix-add-routes.sh | 83 ----- sk1/not use/fix-backend-health.sh | 44 --- sk1/not use/fix-backend-service.sh | 33 -- sk1/not use/fix-deployments.sh | 27 -- sk1/not use/fix-frontend-nginx.sh | 58 ---- sk1/not use/fix-frontend.sh | 67 ---- sk1/not use/fix-ingress.sh | 53 ---- sk1/not use/fix-react-config.sh | 45 --- sk1/not use/fix-service-routes.sh | 130 -------- sk1/not use/fixed-nginx-conf.yaml | 29 -- sk1/not use/rebuild-backend.sh | 78 ----- sk1/not use/refresh-connection.sh | 18 -- sk1/not use/resilient-deploy.sh | 96 ------ sk1/not use/simple-backend.sh | 66 ---- sk1/not use/sk1-ingress.yaml | 27 -- sk1/not use/test-api.sh | 15 - sk1/not use/test-backend.sh | 12 - sk1/not use/test-connection.sh | 9 - sk1/not use/test-network.sh | 38 --- sk1/not use/test-routes.sh | 12 - sk1/not use/update-frontend.sh | 60 ---- sk1/not use/update-nginx-config.sh | 59 ---- sk1/not use/verify-service.sh | 21 -- 36 files changed, 9 insertions(+), 2079 deletions(-) delete mode 100755 sk1/fixed-backend.sh delete mode 100644 sk1/fixed-backend.yml create mode 100644 sk1/k8s/secret-example.yml delete mode 100755 sk1/not usable delete mode 100755 sk1/not use/add-routes.sh delete mode 100755 sk1/not use/backend-fixed-deployment.yaml delete mode 100755 sk1/not use/certificate.yaml delete mode 100755 sk1/not use/complete-fix.sh delete mode 100755 sk1/not use/complete-ingress-setup.sh delete mode 100755 sk1/not use/complete-ingress.yaml delete mode 100755 sk1/not use/create-ingress.sh delete mode 100755 sk1/not use/debug-instructions.txt delete mode 100755 sk1/not use/deploy-fixed-backend.sh delete mode 100755 sk1/not use/fix-add-routes.sh delete mode 100755 sk1/not use/fix-backend-health.sh delete mode 100755 sk1/not use/fix-backend-service.sh delete mode 100755 sk1/not use/fix-deployments.sh delete mode 100755 sk1/not use/fix-frontend-nginx.sh delete mode 100755 sk1/not use/fix-frontend.sh delete mode 100755 sk1/not use/fix-ingress.sh delete mode 100755 sk1/not use/fix-react-config.sh delete mode 100755 sk1/not use/fix-service-routes.sh delete mode 100755 sk1/not use/fixed-nginx-conf.yaml delete mode 100755 sk1/not use/rebuild-backend.sh delete mode 100755 sk1/not use/refresh-connection.sh delete mode 100755 sk1/not use/resilient-deploy.sh delete mode 100755 sk1/not use/simple-backend.sh delete mode 100755 sk1/not use/sk1-ingress.yaml delete mode 100755 sk1/not use/test-api.sh delete mode 100755 sk1/not use/test-backend.sh delete mode 100755 sk1/not use/test-connection.sh delete mode 100755 sk1/not use/test-network.sh delete mode 100755 sk1/not use/test-routes.sh delete mode 100755 sk1/not use/update-frontend.sh delete mode 100755 sk1/not use/update-nginx-config.sh delete mode 100755 sk1/not use/verify-service.sh diff --git a/sk1/fixed-backend.sh b/sk1/fixed-backend.sh deleted file mode 100755 index 50c6c8b..0000000 --- a/sk1/fixed-backend.sh +++ /dev/null @@ -1,63 +0,0 @@ -# Create a fixed deployment file -cat > fixed-backend.yml << EOF -apiVersion: apps/v1 -kind: Deployment -metadata: - name: backend - namespace: sk1 -spec: - replicas: 2 - selector: - matchLabels: - app: backend - template: - metadata: - labels: - app: backend - spec: - containers: - - name: backend - image: gcr.io/$(gcloud config get-value project)/backend:latest - resources: - limits: - cpu: "500m" - memory: "512Mi" - requests: - cpu: "200m" - memory: "256Mi" - ports: - - containerPort: 4000 - env: - - name: PORT - value: "4000" - - name: MONGO_URI - valueFrom: - secretKeyRef: - name: mongodb-secret - key: MONGO_URI - - name: JWT_SECRET - valueFrom: - secretKeyRef: - name: mongodb-secret - key: JWT_SECRET - - name: GOOGLE_PLACES_API_KEY - valueFrom: - secretKeyRef: - name: mongodb-secret - key: GOOGLE_PLACES_API_KEY - livenessProbe: - httpGet: - path: /api - port: 4000 - initialDelaySeconds: 30 - periodSeconds: 20 - readinessProbe: - httpGet: - path: /api - port: 4000 - initialDelaySeconds: 15 - periodSeconds: 10 -EOF - -# Apply the fixed deployment -kubectl apply -f fixed-backend.yml \ No newline at end of file diff --git a/sk1/fixed-backend.yml b/sk1/fixed-backend.yml deleted file mode 100644 index 940f2cc..0000000 --- a/sk1/fixed-backend.yml +++ /dev/null @@ -1,57 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: backend - namespace: sk1 -spec: - replicas: 2 - selector: - matchLabels: - app: backend - template: - metadata: - labels: - app: backend - spec: - containers: - - name: backend - image: gcr.io/leafy-racer-458817-c0/backend:latest - resources: - limits: - cpu: "500m" - memory: "512Mi" - requests: - cpu: "200m" - memory: "256Mi" - ports: - - containerPort: 4000 - env: - - name: PORT - value: "4000" - - name: MONGO_URI - valueFrom: - secretKeyRef: - name: mongodb-secret - key: MONGO_URI - - name: JWT_SECRET - valueFrom: - secretKeyRef: - name: mongodb-secret - key: JWT_SECRET - - name: GOOGLE_PLACES_API_KEY - valueFrom: - secretKeyRef: - name: mongodb-secret - key: GOOGLE_PLACES_API_KEY - livenessProbe: - httpGet: - path: /api - port: 4000 - initialDelaySeconds: 30 - periodSeconds: 20 - readinessProbe: - httpGet: - path: /api - port: 4000 - initialDelaySeconds: 15 - periodSeconds: 10 diff --git a/sk1/k8s/secret-example.yml b/sk1/k8s/secret-example.yml new file mode 100644 index 0000000..ae6aba5 --- /dev/null +++ b/sk1/k8s/secret-example.yml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: Secret +metadata: + name: mongodb-secret +type: Opaque +stringData: + MONGO_URI: "mongo cluster connection addrses" + JWT_SECRET: "Add JWT secret here" + GOOGLE_PLACES_API_KEY: "add google places api key here" \ No newline at end of file diff --git a/sk1/not usable b/sk1/not usable deleted file mode 100755 index 4b011c1..0000000 --- a/sk1/not usable +++ /dev/null @@ -1 +0,0 @@ -frontend/Dockerfile verify-service.sh update-nginx-config.sh update-frontend.sh test-routes.sh test-network.sh test-connection.sh test-backend.sh test-api.sh simple-backend.sh resilient-deploy.sh refresh-connection.sh rebuild-backend.sh fixed-nginx-conf.yaml sk1-ingress.yaml fix-service-routes.sh fix-react-config.sh fix-ingress.sh fix-frontend.sh fix-frontend-nginx.sh fix-deployments.sh fix-backend-service.sh fix-backend-health.sh fix-add-routes.sh deploy-fixed-backend.sh debug-instructions.txt create-ingress.sh complete-ingress.yaml complete-ingress-setup.sh complete-fix.sh certificate.yaml backend-fixed-deployment.yaml \ No newline at end of file diff --git a/sk1/not use/add-routes.sh b/sk1/not use/add-routes.sh deleted file mode 100755 index d9b423d..0000000 --- a/sk1/not use/add-routes.sh +++ /dev/null @@ -1,68 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# Create a ConfigMap with route patches for the backend -cat > /tmp/route-patches.js << 'EOF' -// Root route -app.get('/', (req, res) => { - res.json({ message: 'Welcome to the API' }); -}); - -// Health check endpoint -app.get('/api', (req, res) => { - res.json({ status: 'ok', message: 'API is healthy' }); -}); - -// Update existing routes if needed -app.get('/api/health', (req, res) => { - res.json({ status: 'ok' }); -}); -EOF - -kubectl create configmap route-patches -n sk1 --from-file=routes.js=/tmp/route-patches.js --dry-run=client -o yaml | kubectl apply -f - - -# Create a patch for the backend deployment to inject these routes -cat > /tmp/backend-patch-routes.yaml << EOF -apiVersion: apps/v1 -kind: Deployment -metadata: - name: backend - namespace: sk1 -spec: - template: - spec: - containers: - - name: backend - env: - - name: DEBUG - value: "express:*" - # Add script to update routes on startup - lifecycle: - postStart: - exec: - command: - - sh - - -c - - | - echo "Patching routes..." - cat /routes/routes.js >> /app/index.js - # Force Express to reload routes - kill -SIGHUP 1 - volumeMounts: - - name: route-patches - mountPath: /routes - volumes: - - name: route-patches - configMap: - name: route-patches -EOF - -# Apply the patch -kubectl apply -f /tmp/backend-patch-routes.yaml - -# Restart backend to apply changes -kubectl rollout restart deployment backend -n sk1 - -echo "Added missing API routes to backend" -echo "Waiting for backend to restart..." -kubectl rollout status deployment backend -n sk1 \ No newline at end of file diff --git a/sk1/not use/backend-fixed-deployment.yaml b/sk1/not use/backend-fixed-deployment.yaml deleted file mode 100755 index 4bf03f6..0000000 --- a/sk1/not use/backend-fixed-deployment.yaml +++ /dev/null @@ -1,42 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: backend-fixed - namespace: sk1 -spec: - replicas: 1 - selector: - matchLabels: - app: backend-fixed - template: - metadata: - labels: - app: backend-fixed - spec: - containers: - - name: backend - image: gcr.io/leafy-racer-458817-c0/backend-fixed:latest - env: - - name: PORT - value: "4000" - - name: HOST - value: "0.0.0.0" - - name: MONGO_URI - valueFrom: - secretKeyRef: - name: mongodb-secret - key: MONGO_URI - ports: - - containerPort: 4000 ---- -apiVersion: v1 -kind: Service -metadata: - name: backend-service - namespace: sk1 -spec: - selector: - app: backend-fixed - ports: - - port: 4000 - targetPort: 4000 diff --git a/sk1/not use/certificate.yaml b/sk1/not use/certificate.yaml deleted file mode 100755 index c36e39e..0000000 --- a/sk1/not use/certificate.yaml +++ /dev/null @@ -1,8 +0,0 @@ -apiVersion: networking.gke.io/v1 -kind: ManagedCertificate -metadata: - name: sk1-cert - namespace: sk1 -spec: - domains: - - nudges.works diff --git a/sk1/not use/complete-fix.sh b/sk1/not use/complete-fix.sh deleted file mode 100755 index 1d32c16..0000000 --- a/sk1/not use/complete-fix.sh +++ /dev/null @@ -1,352 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# Get project ID -PROJECT=$(gcloud config get-value project) - -echo "๐Ÿ” Checking current status..." -kubectl get pods -n sk1 - -echo "๐Ÿงน Cleaning up any broken configurations..." -# Delete the debug pods we created earlier -kubectl delete pod debug-react -n sk1 --ignore-not-found -kubectl delete pod test-route -n sk1 --ignore-not-found - -echo "๐Ÿ”„ Creating a complete backend with all required routes..." - -# Create a temporary file with our complete backend app -cat > /tmp/complete-backend.js << 'EOF' -const express = require('express'); -const cors = require('cors'); -const mongoose = require('mongoose'); -const app = express(); -const port = process.env.PORT || 4000; -const host = process.env.HOST || '0.0.0.0'; - -// Middleware -app.use(cors()); -app.use(express.json()); -app.use(express.urlencoded({ extended: true })); - -// Root route -app.get('/', (req, res) => { - res.json({ message: 'Welcome to the API' }); -}); - -// Health check endpoint -app.get('/api', (req, res) => { - res.json({ status: 'ok', message: 'API is healthy' }); -}); - -// Health check endpoint -app.get('/api/health', (req, res) => { - res.json({ status: 'ok' }); -}); - -// Service routes -app.get('/api/services/:serviceType', (req, res) => { - const serviceType = req.params.serviceType; - const { radius, page, sortBy, order, lat, lon } = req.query; - - console.log(`Received request for ${serviceType} services`); - console.log(`Query params: radius=${radius}, page=${page}, sortBy=${sortBy}, order=${order}, lat=${lat}, lon=${lon}`); - - // Return mock data for any service type - res.json({ - success: true, - services: [ - { - id: 1, - name: `${serviceType} Service 1`, - description: `Professional ${serviceType} service`, - price: Math.floor(Math.random() * 50) + 20, - distance: parseFloat((Math.random() * 5).toFixed(1)), - rating: parseFloat((Math.random() * 2 + 3).toFixed(1)) - }, - { - id: 2, - name: `${serviceType} Service 2`, - description: `Expert ${serviceType} provider`, - price: Math.floor(Math.random() * 50) + 20, - distance: parseFloat((Math.random() * 5).toFixed(1)), - rating: parseFloat((Math.random() * 2 + 3).toFixed(1)) - } - ], - pagination: { - currentPage: parseInt(page) || 1, - totalPages: 3, - totalResults: 6 - } - }); -}); - -// Authentication endpoints -app.post('/api/auth/login', (req, res) => { - console.log('Login attempt:', req.body); - - res.json({ - success: true, - token: "mock-jwt-token", - user: { - id: 1, - name: "Test User", - email: req.body.email || "test@example.com" - } - }); -}); - -app.post('/api/auth/register', (req, res) => { - console.log('Registration attempt:', req.body); - - res.json({ - success: true, - message: "User registered successfully", - user: { - id: new Date().getTime(), - name: req.body.name || "New User", - email: req.body.email || "new@example.com" - } - }); -}); - -// MongoDB connection -const MONGO_URI = process.env.MONGO_URI; -if (MONGO_URI) { - mongoose.connect(MONGO_URI) - .then(() => console.log('โœ… MongoDB connected')) - .catch(err => console.error('MongoDB connection error:', err)); -} - -// Error handling middleware -app.use((err, req, res, next) => { - console.error('Error:', err); - res.status(500).json({ - success: false, - message: 'Server error', - error: process.env.NODE_ENV === 'development' ? err.message : 'Internal server error' - }); -}); - -// Handle 404s -app.use((req, res) => { - console.log(`404: ${req.method} ${req.path}`); - res.status(404).json({ - success: false, - message: 'API endpoint not found' - }); -}); - -// Start server -app.listen(port, host, () => { - console.log(`๐Ÿš€ Server running on http://${host}:${port}`); -}); -EOF - -# Create a package.json file -cat > /tmp/package.json << 'EOF' -{ - "name": "backend", - "version": "1.0.0", - "description": "Backend for Nudges Works application", - "main": "index.js", - "scripts": { - "start": "node index.js" - }, - "dependencies": { - "cors": "^2.8.5", - "express": "^4.18.2", - "mongoose": "^7.0.3" - } -} -EOF - -# Create a Dockerfile -cat > /tmp/Dockerfile << 'EOF' -FROM node:20-alpine - -WORKDIR /app - -COPY package.json . -RUN npm install - -COPY index.js . - -EXPOSE 4000 - -CMD ["node", "index.js"] -EOF - -# Create a temporary directory and copy files -rm -rf /tmp/backend-build || true -mkdir -p /tmp/backend-build -cp /tmp/complete-backend.js /tmp/backend-build/index.js -cp /tmp/package.json /tmp/backend-build/package.json -cp /tmp/Dockerfile /tmp/backend-build/Dockerfile - -# Build and push the image -echo "๐Ÿ—๏ธ Building and pushing new backend image..." -cd /tmp/backend-build -gcloud builds submit --tag gcr.io/${PROJECT}/backend-complete:latest - -# Create a deployment with the new image -cat > /tmp/backend-complete.yaml << EOF -apiVersion: apps/v1 -kind: Deployment -metadata: - name: backend - namespace: sk1 -spec: - replicas: 1 - selector: - matchLabels: - app: backend - template: - metadata: - labels: - app: backend - spec: - containers: - - name: backend - image: gcr.io/${PROJECT}/backend-complete:latest - resources: - limits: - cpu: "0.5" - memory: "512Mi" - requests: - cpu: "0.2" - memory: "256Mi" - ports: - - containerPort: 4000 - env: - - name: PORT - value: "4000" - - name: HOST - value: "0.0.0.0" - - name: MONGO_URI - valueFrom: - secretKeyRef: - name: mongodb-secret - key: MONGO_URI ---- -apiVersion: v1 -kind: Service -metadata: - name: backend-service - namespace: sk1 -spec: - selector: - app: backend - ports: - - port: 4000 - targetPort: 4000 -EOF - -# Apply the deployment -echo "๐Ÿ“ฆ Applying new backend deployment..." -kubectl apply -f /tmp/backend-complete.yaml - -# Update the frontend nginx config to ensure it's working correctly -cat > /tmp/fixed-nginx.conf << 'EOF' -server { - listen 80; - server_name localhost; - root /usr/share/nginx/html; - index index.html; - - # Fix for API routing - explicit location block for various endpoints - location /api/services/ { - proxy_pass http://backend-service:4000; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection 'upgrade'; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_cache_bypass $http_upgrade; - } - - location /api/auth/ { - proxy_pass http://backend-service:4000; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection 'upgrade'; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_cache_bypass $http_upgrade; - } - - # General API requests - location /api { - proxy_pass http://backend-service:4000; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection 'upgrade'; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_cache_bypass $http_upgrade; - } - - # All other requests go to the React app - location / { - try_files $uri $uri/ /index.html; - } -} -EOF - -# Create a ConfigMap for the new nginx configuration -kubectl create configmap fixed-nginx-conf -n sk1 --from-file=nginx.conf=/tmp/fixed-nginx.conf -o yaml --dry-run=client | kubectl apply -f - - -# Update the frontend deployment to use the new ConfigMap -kubectl patch deployment frontend -n sk1 --type=strategic --patch ' -{ - "spec": { - "template": { - "spec": { - "containers": [ - { - "name": "frontend", - "volumeMounts": [ - { - "name": "nginx-config", - "mountPath": "/etc/nginx/conf.d/default.conf", - "subPath": "nginx.conf" - } - ] - } - ], - "volumes": [ - { - "name": "nginx-config", - "configMap": { - "name": "fixed-nginx-conf" - } - } - ] - } - } - } -} -' - -# Restart frontend -kubectl rollout restart deployment frontend -n sk1 - -echo "โฑ๏ธ Waiting for deployments to be ready..." -kubectl rollout status deployment backend -n sk1 -kubectl rollout status deployment frontend -n sk1 - -echo "โœ… Deployment complete!" -echo "Testing backend API directly..." -kubectl run api-test --image=curlimages/curl -n sk1 --rm -it -- sh -c ' - echo "Testing /api endpoint:" - curl -s http://backend-service:4000/api - echo "" - echo "Testing /api/services/assembly endpoint:" - curl -s http://backend-service:4000/api/services/assembly - echo "" - echo "Testing /api/auth/login endpoint:" - curl -s -X POST -H "Content-Type: application/json" -d '\''{"email":"test@example.com","password":"password"}'\'' http://backend-service:4000/api/auth/login - echo "" -' - -echo "๐ŸŽ‰ Your application should now be working properly at https://nudges.works" -echo "If you're still seeing issues, try clearing your browser cache or using a private/incognito window" \ No newline at end of file diff --git a/sk1/not use/complete-ingress-setup.sh b/sk1/not use/complete-ingress-setup.sh deleted file mode 100755 index af6947d..0000000 --- a/sk1/not use/complete-ingress-setup.sh +++ /dev/null @@ -1,167 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# Get project ID -PROJECT=$(gcloud config get-value project) - -echo "๐Ÿ” Checking if certificate exists..." -if ! kubectl get managedcertificate sk1-cert -n sk1 2>/dev/null; then - echo "๐Ÿ”’ Creating managed certificate..." - # Create certificate - cat > certificate.yaml << EOF -apiVersion: networking.gke.io/v1 -kind: ManagedCertificate -metadata: - name: sk1-cert - namespace: sk1 -spec: - domains: - - nudges.works -EOF - - kubectl apply -f certificate.yaml - echo "โœ… Certificate created" -else - echo "โœ… Certificate already exists" -fi - -echo "๐Ÿ” Checking if static IP exists..." -if ! gcloud compute addresses describe sk1-static-ip --global &>/dev/null; then - echo "๐ŸŒ Creating static IP..." - # Create static IP - gcloud compute addresses create sk1-static-ip --global - echo "โœ… Static IP created" -else - echo "โœ… Static IP already exists" -fi - -# Get the static IP -IP=$(gcloud compute addresses describe sk1-static-ip --global --format="value(address)") -echo "๐Ÿ“ Using static IP: $IP" - -echo "๐Ÿ—๏ธ Creating ingress resource..." -# Create ingress resource -cat > complete-ingress.yaml << EOF -apiVersion: networking.k8s.io/v1 -kind: Ingress -metadata: - name: sk1-ingress - namespace: sk1 - annotations: - kubernetes.io/ingress.global-static-ip-name: sk1-static-ip - networking.gke.io/managed-certificates: sk1-cert - kubernetes.io/ingress.class: "gce" -spec: - rules: - - host: nudges.works - http: - paths: - - path: /api/ - pathType: Prefix - backend: - service: - name: backend-service - port: - number: 4000 - - path: / - pathType: Prefix - backend: - service: - name: frontend-service - port: - number: 80 -EOF - -# Apply the ingress configuration -kubectl apply -f complete-ingress.yaml - -echo "โฑ๏ธ Waiting for ingress to initialize..." -sleep 10 - -echo "๐Ÿ” Checking ingress status..." -kubectl get ingress -n sk1 - -# Create a special nginx configuration for frontend to handle direct requests to backend -echo "๐Ÿ“ Updating frontend nginx configuration to correctly handle API requests..." -cat > fixed-nginx-conf.yaml << EOF -apiVersion: v1 -kind: ConfigMap -metadata: - name: fixed-nginx-conf - namespace: sk1 -data: - nginx.conf: | - server { - listen 80; - server_name localhost; - root /usr/share/nginx/html; - index index.html; - - # All API requests should go to backend service - location /api/ { - proxy_pass http://backend-service:4000/; - proxy_http_version 1.1; - proxy_set_header Upgrade \$http_upgrade; - proxy_set_header Connection 'upgrade'; - proxy_set_header Host \$host; - proxy_set_header X-Real-IP \$remote_addr; - proxy_cache_bypass \$http_upgrade; - } - - # All other requests go to the React app - location / { - try_files \$uri \$uri/ /index.html; - } - } -EOF - -kubectl apply -f fixed-nginx-conf.yaml - -# Update frontend to use this config -kubectl patch deployment frontend -n sk1 --type=strategic --patch ' -{ - "spec": { - "template": { - "spec": { - "containers": [ - { - "name": "frontend", - "volumeMounts": [ - { - "name": "nginx-config", - "mountPath": "/etc/nginx/conf.d/default.conf", - "subPath": "nginx.conf" - } - ] - } - ], - "volumes": [ - { - "name": "nginx-config", - "configMap": { - "name": "fixed-nginx-conf" - } - } - ] - } - } - } -} -' - -echo "๐Ÿ”„ Restarting pods to ensure clean configuration..." -kubectl rollout restart deployment frontend -n sk1 -kubectl rollout restart deployment backend -n sk1 - -echo "โฑ๏ธ Waiting for deployments to restart..." -kubectl rollout status deployment frontend -n sk1 -kubectl rollout status deployment backend -n sk1 - -echo "โœ… Setup complete!" -echo "" -echo "Your application should now be accessible at: https://nudges.works" -echo "Note: It may take 5-10 minutes for the DNS and certificate to propagate completely." -echo "" -echo "You can test the API directly with: curl https://nudges.works/api" -echo "" -echo "If you still encounter issues, try clearing your browser cache or using an incognito window." \ No newline at end of file diff --git a/sk1/not use/complete-ingress.yaml b/sk1/not use/complete-ingress.yaml deleted file mode 100755 index 2dfddf2..0000000 --- a/sk1/not use/complete-ingress.yaml +++ /dev/null @@ -1,28 +0,0 @@ -apiVersion: networking.k8s.io/v1 -kind: Ingress -metadata: - name: sk1-ingress - namespace: sk1 - annotations: - kubernetes.io/ingress.global-static-ip-name: sk1-static-ip - networking.gke.io/managed-certificates: sk1-cert - kubernetes.io/ingress.class: "gce" -spec: - rules: - - host: nudges.works - http: - paths: - - path: /api/ - pathType: Prefix - backend: - service: - name: backend-service - port: - number: 4000 - - path: / - pathType: Prefix - backend: - service: - name: frontend-service - port: - number: 80 diff --git a/sk1/not use/create-ingress.sh b/sk1/not use/create-ingress.sh deleted file mode 100755 index d859de5..0000000 --- a/sk1/not use/create-ingress.sh +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# Get project ID -PROJECT=$(gcloud config get-value project) - -echo "๐Ÿ—๏ธ Creating new ingress configuration..." - -# Create ingress resource -cat > sk1-ingress.yaml << EOF -apiVersion: networking.k8s.io/v1 -kind: Ingress -metadata: - name: sk1-ingress - namespace: sk1 - annotations: - kubernetes.io/ingress.global-static-ip-name: sk1-static-ip - networking.gke.io/managed-certificates: sk1-cert -spec: - rules: - - host: nudges.works - http: - paths: - - path: /api - pathType: Prefix - backend: - service: - name: backend-service - port: - number: 4000 - - path: / - pathType: Prefix - backend: - service: - name: frontend-service - port: - number: 80 -EOF - -# Apply the ingress configuration -kubectl apply -f sk1-ingress.yaml - -echo "โฑ๏ธ Waiting for ingress to initialize..." -sleep 10 - -echo "๐Ÿ” Checking ingress status..." -kubectl get ingress -n sk1 - -echo "โœ… Ingress created!" -echo "" -echo "It may take a few minutes for the ingress to provision completely." -echo "Try accessing your app at https://nudges.works in 5-10 minutes." -echo "" -echo "In the meantime, you can check your backend and frontend services:" -echo "kubectl get services -n sk1" \ No newline at end of file diff --git a/sk1/not use/debug-instructions.txt b/sk1/not use/debug-instructions.txt deleted file mode 100755 index b34742c..0000000 --- a/sk1/not use/debug-instructions.txt +++ /dev/null @@ -1,13 +0,0 @@ -To debug your React application's API calls: - -1. Open https://nudges.works in Chrome/Edge -2. Press F12 to open Developer Tools -3. Go to the Network tab -4. Try to log in or use features that should call the API -5. Look for failed API calls (in red) -6. Check the URL of the requests - they should start with /api/... - -Common issues: -- Frontend might be calling http://localhost:4000/api instead of /api -- API endpoints in React might not match backend endpoints -- Authentication headers might be missing or incorrect diff --git a/sk1/not use/deploy-fixed-backend.sh b/sk1/not use/deploy-fixed-backend.sh deleted file mode 100755 index f33764b..0000000 --- a/sk1/not use/deploy-fixed-backend.sh +++ /dev/null @@ -1,145 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# Get project ID -PROJECT=$(gcloud config get-value project) - -# Reconnect to cluster in case connection timed out -echo "๐Ÿ”„ Refreshing connection to GKE cluster..." -gcloud container clusters get-credentials sk1-cluster --zone us-central1-a --project ${PROJECT} - -# Create a temporary file with our complete backend app -cat > /tmp/complete-backend.js << 'EOF' -const express = require('express'); -const cors = require('cors'); -const mongoose = require('mongoose'); -const app = express(); -const port = process.env.PORT || 4000; -const host = process.env.HOST || 'localhost'; - -// Middleware -app.use(cors()); -app.use(express.json()); - -// Root route -app.get('/', (req, res) => { - res.json({ message: 'Welcome to the API' }); -}); - -// Health check endpoint -app.get('/api', (req, res) => { - res.json({ status: 'ok', message: 'API is healthy' }); -}); - -// Health check endpoint -app.get('/api/health', (req, res) => { - res.json({ status: 'ok' }); -}); - -// MongoDB connection -const MONGO_URI = process.env.MONGO_URI; -if (MONGO_URI) { - mongoose.connect(MONGO_URI) - .then(() => console.log('โœ… MongoDB connected')) - .catch(err => console.error('MongoDB connection error:', err)); -} - -// Start server -app.listen(port, host, () => { - console.log(`๐Ÿš€ Server running on http://${host}:${port}`); -}); -EOF - -# Create a Dockerfile for our custom backend -cat > /tmp/Dockerfile.backend << 'EOF' -FROM node:20-alpine -WORKDIR /app -COPY package.json . -RUN npm install express cors mongoose -COPY . . -EXPOSE 4000 -CMD ["node", "index.js"] -EOF - -# Create a directory for our custom backend -mkdir -p /tmp/custom-backend -cp /tmp/complete-backend.js /tmp/custom-backend/index.js -cp /tmp/Dockerfile.backend /tmp/custom-backend/Dockerfile - -# Create a basic package.json -cat > /tmp/custom-backend/package.json << 'EOF' -{ - "name": "backend", - "version": "1.0.0", - "description": "Custom backend for sk1", - "main": "index.js", - "dependencies": { - "cors": "^2.8.5", - "express": "^4.18.2", - "mongoose": "^7.0.3" - } -} -EOF - -echo "๐Ÿ—๏ธ Building custom backend image..." -cd /tmp/custom-backend -gcloud builds submit --tag "gcr.io/${PROJECT}/backend-fixed:latest" . -cd - - -# Create a new deployment using our fixed image -cat > /tmp/fixed-backend-deployment.yaml << EOF -apiVersion: apps/v1 -kind: Deployment -metadata: - name: backend-fixed - namespace: sk1 -spec: - replicas: 1 - selector: - matchLabels: - app: backend-fixed - template: - metadata: - labels: - app: backend-fixed - spec: - containers: - - name: backend - image: gcr.io/${PROJECT}/backend-fixed:latest - env: - - name: PORT - value: "4000" - - name: HOST - value: "0.0.0.0" - - name: MONGO_URI - valueFrom: - secretKeyRef: - name: mongodb-secret - key: MONGO_URI - ports: - - containerPort: 4000 ---- -apiVersion: v1 -kind: Service -metadata: - name: backend-service - namespace: sk1 -spec: - selector: - app: backend-fixed - ports: - - port: 4000 - targetPort: 4000 -EOF - -echo "๐Ÿ“ฆ Deploying fixed backend..." -kubectl apply -f /tmp/fixed-backend-deployment.yaml - -echo "โฑ๏ธ Waiting for deployment to be available..." -kubectl rollout status deployment/backend-fixed -n sk1 - -echo "๐Ÿ” Checking for running pods..." -kubectl get pods -n sk1 -l app=backend-fixed - -echo "โœ… Deployment complete. Testing backend health..." -kubectl exec -it netshoot -n sk1 -- curl -s http://backend-service:4000/api | grep status \ No newline at end of file diff --git a/sk1/not use/fix-add-routes.sh b/sk1/not use/fix-add-routes.sh deleted file mode 100755 index 6eed0ef..0000000 --- a/sk1/not use/fix-add-routes.sh +++ /dev/null @@ -1,83 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# Create a ConfigMap with route patches for the backend -cat > /tmp/route-patches.js << 'EOF' -// Root route -app.get('/', (req, res) => { - res.json({ message: 'Welcome to the API' }); -}); - -// Health check endpoint -app.get('/api', (req, res) => { - res.json({ status: 'ok', message: 'API is healthy' }); -}); - -// Update existing routes if needed -app.get('/api/health', (req, res) => { - res.json({ status: 'ok' }); -}); -EOF - -kubectl create configmap route-patches -n sk1 --from-file=routes.js=/tmp/route-patches.js --dry-run=client -o yaml | kubectl apply -f - - -# Create a strategic merge patch that only modifies what we need -cat > /tmp/backend-patch-routes.yaml << EOF -apiVersion: apps/v1 -kind: Deployment -metadata: - name: backend - namespace: sk1 -spec: - template: - spec: - containers: - - name: backend - env: - - name: DEBUG - value: "express:*" - volumeMounts: - - name: route-patches - mountPath: /routes - volumes: - - name: route-patches - configMap: - name: route-patches -EOF - -# Apply the patch with strategic merge patch type -kubectl patch deployment backend -n sk1 --patch-file /tmp/backend-patch-routes.yaml --type=strategic - -# Create a script to apply routes to the running container -cat > /tmp/apply-routes.sh << 'EOF' -#!/bin/bash -# Get the backend pod name -BACKEND_POD=$(kubectl get pods -n sk1 -l app=backend -o jsonpath='{.items[0].metadata.name}') - -# Copy the routes file to the pod -echo "Copying routes to pod $BACKEND_POD..." -kubectl exec -n sk1 $BACKEND_POD -- mkdir -p /tmp/routes -kubectl cp /tmp/route-patches.js $BACKEND_POD:/tmp/routes/routes.js -n sk1 - -# Apply routes to the running application -echo "Applying routes..." -kubectl exec -n sk1 $BACKEND_POD -- sh -c ' - echo "// Added routes:" >> /app/index.js - cat /tmp/routes/routes.js >> /app/index.js - echo "Routes added to index.js" - # Try to send SIGHUP to process 1 to reload - if kill -SIGHUP 1; then - echo "Sent SIGHUP to main process" - else - echo "Could not send SIGHUP, will restart pod" - exit 1 - fi -' -EOF - -chmod +x /tmp/apply-routes.sh -/tmp/apply-routes.sh || kubectl rollout restart deployment backend -n sk1 - -echo "Added missing API routes to backend" -echo "Waiting for backend to restart..." -kubectl rollout status deployment backend -n sk1 \ No newline at end of file diff --git a/sk1/not use/fix-backend-health.sh b/sk1/not use/fix-backend-health.sh deleted file mode 100755 index 62cf947..0000000 --- a/sk1/not use/fix-backend-health.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# Create a backend deployment patch with better configuration -cat > /tmp/backend-patch.yaml << EOF -apiVersion: apps/v1 -kind: Deployment -metadata: - name: backend - namespace: sk1 -spec: - template: - spec: - containers: - - name: backend - env: - - name: PORT - value: "4000" - - name: HOST - value: "0.0.0.0" - # Remove existing probes first - readinessProbe: - httpGet: - path: /api - port: 4000 - initialDelaySeconds: 30 - periodSeconds: 15 - timeoutSeconds: 5 - livenessProbe: - httpGet: - path: /api - port: 4000 - initialDelaySeconds: 45 - periodSeconds: 20 - timeoutSeconds: 5 -EOF - -# Apply the patch -kubectl patch deployment backend -n sk1 --patch-file /tmp/backend-patch.yaml - -# Restart backend pods to apply changes -kubectl rollout restart deployment backend -n sk1 - -echo "Backend deployment patched with improved health checks" \ No newline at end of file diff --git a/sk1/not use/fix-backend-service.sh b/sk1/not use/fix-backend-service.sh deleted file mode 100755 index 2d31743..0000000 --- a/sk1/not use/fix-backend-service.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# Get information about our running pods -RUNNING_POD=$(kubectl get pods -n sk1 -l app=backend --field-selector=status.phase=Running -o jsonpath='{.items[0].metadata.name}') -RUNNING_IP=$(kubectl get pod $RUNNING_POD -n sk1 -o jsonpath='{.status.podIP}') - -echo "Running pod: $RUNNING_POD with IP: $RUNNING_IP" - -# Update the backend service to explicitly include our running pod -cat > /tmp/fixed-backend-service.yaml << EOF -apiVersion: v1 -kind: Service -metadata: - name: backend-service - namespace: sk1 -spec: - ports: - - port: 4000 - targetPort: 4000 - selector: - app: backend -EOF - -# Apply the fixed service -kubectl apply -f /tmp/fixed-backend-service.yaml - -# Force endpoints to update by restarting the backend pod -kubectl rollout restart deployment backend -n sk1 - -echo "Backend service updated, checking endpoints..." -sleep 5 -kubectl get endpoints backend-service -n sk1 \ No newline at end of file diff --git a/sk1/not use/fix-deployments.sh b/sk1/not use/fix-deployments.sh deleted file mode 100755 index 9b06c57..0000000 --- a/sk1/not use/fix-deployments.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# Get project ID -PROJECT=$(gcloud config get-value project) -echo "Using project: ${PROJECT}" - -# Show current images in registry -echo "Checking available images:" -gcloud container images list --repository=gcr.io/${PROJECT} - -# Create deployment files with correct project ID -echo "Creating deployment files with project ID ${PROJECT}" -sed "s|\${PROJECT}|${PROJECT}|g" k8s/backend-deployment.yml.tpl > /tmp/backend-deployment.yml -sed "s|\${PROJECT}|${PROJECT}|g" k8s/frontend-deployment.yml.tpl > /tmp/frontend-deployment.yml - -# Show what images will be used -echo "Backend image: $(grep "image:" /tmp/backend-deployment.yml)" -echo "Frontend image: $(grep "image:" /tmp/frontend-deployment.yml)" - -# Apply fixed deployments -kubectl apply -n sk1 -f /tmp/backend-deployment.yml -kubectl apply -n sk1 -f /tmp/frontend-deployment.yml - -# Watch pods come up -echo "Watching pods..." -kubectl get pods -n sk1 -w \ No newline at end of file diff --git a/sk1/not use/fix-frontend-nginx.sh b/sk1/not use/fix-frontend-nginx.sh deleted file mode 100755 index 8100643..0000000 --- a/sk1/not use/fix-frontend-nginx.sh +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# Create a simpler nginx.conf that just proxies /api -cat > /tmp/fixed-nginx.conf << 'EOF' -server { - listen 80; - server_name localhost; - root /usr/share/nginx/html; - index index.html; - - # Proxy API requests without trailing slash issues - location /api { - proxy_pass http://backend-service:4000; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection 'upgrade'; - proxy_set_header Host $host; - proxy_cache_bypass $http_upgrade; - } - - # Handle React router paths - location / { - try_files $uri $uri/ /index.html; - } -} -EOF - -# Create ConfigMap from this nginx.conf -kubectl create configmap nginx-fixed-config -n sk1 --from-file=nginx.conf=/tmp/fixed-nginx.conf --dry-run=client -o yaml | kubectl apply -f - - -# Update the frontend deployment to use this ConfigMap -cat > /tmp/fixed-frontend-update.yaml << EOF -apiVersion: apps/v1 -kind: Deployment -metadata: - name: frontend - namespace: sk1 -spec: - template: - spec: - containers: - - name: frontend - volumeMounts: - - name: nginx-config - mountPath: /etc/nginx/conf.d/default.conf - subPath: nginx.conf - volumes: - - name: nginx-config - configMap: - name: nginx-fixed-config -EOF - -# Apply the update as a patch -kubectl patch deployment frontend -n sk1 --patch-file /tmp/fixed-frontend-update.yaml - -echo "Updated frontend nginx configuration" -kubectl rollout restart deployment frontend -n sk1 \ No newline at end of file diff --git a/sk1/not use/fix-frontend.sh b/sk1/not use/fix-frontend.sh deleted file mode 100755 index b595f94..0000000 --- a/sk1/not use/fix-frontend.sh +++ /dev/null @@ -1,67 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# Create a final nginx config for frontend -cat > /tmp/final-nginx.conf << 'EOF' -server { - listen 80; - server_name localhost; - root /usr/share/nginx/html; - index index.html; - - # API requests - make sure to point to the backend-service - location /api { - proxy_pass http://backend-service:4000; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection 'upgrade'; - proxy_set_header Host $host; - proxy_cache_bypass $http_upgrade; - } - - # All other requests go to the React app - location / { - try_files $uri $uri/ /index.html; - } -} -EOF - -# Create a ConfigMap from this nginx config -kubectl create configmap final-nginx-conf -n sk1 --from-file=nginx.conf=/tmp/final-nginx.conf --dry-run=client -o yaml | kubectl apply -f - - -# Use patch command instead of apply -kubectl patch deployment frontend -n sk1 --type=strategic --patch ' -{ - "spec": { - "template": { - "spec": { - "containers": [ - { - "name": "frontend", - "volumeMounts": [ - { - "name": "nginx-config", - "mountPath": "/etc/nginx/conf.d/default.conf", - "subPath": "nginx.conf" - } - ] - } - ], - "volumes": [ - { - "name": "nginx-config", - "configMap": { - "name": "final-nginx-conf" - } - } - ] - } - } - } -} -' - -# Restart frontend pods -kubectl rollout restart deployment frontend -n sk1 - -echo "โœ… Frontend nginx configuration updated" \ No newline at end of file diff --git a/sk1/not use/fix-ingress.sh b/sk1/not use/fix-ingress.sh deleted file mode 100755 index acedd9b..0000000 --- a/sk1/not use/fix-ingress.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -echo "๐Ÿ” Checking ingress configuration..." -kubectl get ingress -n sk1 - -# Update the ingress to ensure proper backend routing -cat > /tmp/ingress-patch.yaml << EOF -spec: - rules: - - host: nudges.works - http: - paths: - - path: / - pathType: Prefix - backend: - service: - name: frontend-service - port: - number: 80 - - path: /api - pathType: Prefix - backend: - service: - name: backend-service - port: - number: 4000 -EOF - -echo "๐Ÿ“ Patching ingress configuration..." -INGRESS_NAME=$(kubectl get ingress -n sk1 -o jsonpath='{.items[0].metadata.name}') -kubectl patch ingress $INGRESS_NAME -n sk1 --patch-file /tmp/ingress-patch.yaml - -echo "๐Ÿ”„ Restarting frontend to ensure clean configuration..." -kubectl rollout restart deployment frontend -n sk1 - -echo "โฑ๏ธ Waiting for frontend to restart..." -kubectl rollout status deployment frontend -n sk1 - -echo "โœ… Configuration updated!" -echo "" -echo "Try accessing your app at https://nudges.works now." -echo "Please clear your browser cache or use an incognito window." - -echo "๐Ÿ‘‰ You can also try these direct links to verify functionality:" -echo " - https://nudges.works/api/services/assembly" -echo " - https://nudges.works/api/health" -echo "" -echo "If you're still having issues, try the direct IP address:" -IP=$(kubectl get svc frontend-service -n sk1 -o jsonpath='{.status.loadBalancer.ingress[0].ip}') -if [ -n "$IP" ]; then - echo " - http://$IP/api/services/assembly" -fi \ No newline at end of file diff --git a/sk1/not use/fix-react-config.sh b/sk1/not use/fix-react-config.sh deleted file mode 100755 index 5ed5d8a..0000000 --- a/sk1/not use/fix-react-config.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# Create a temporary pod to examine the frontend code -kubectl run debug-react -n sk1 --image=busybox -- sleep 3600 - -# Wait for pod to be ready -kubectl wait --for=condition=Ready pod/debug-react -n sk1 --timeout=60s - -# Create a config.js file with the correct API URL -cat > /tmp/config.js << EOF -// API Configuration -window.API_URL = '/api'; // Use relative path for API calls -console.log('API configuration loaded'); -EOF - -# Copy this file to the frontend pod's HTML directory -kubectl cp /tmp/config.js debug-react:/tmp/config.js -n sk1 - -# Find all frontend pods -FRONTEND_PODS=$(kubectl get pods -n sk1 -l app=frontend -o jsonpath='{.items[*].metadata.name}') - -# Copy the config to each frontend pod -for pod in $FRONTEND_PODS; do - echo "Updating config in pod $pod..." - kubectl cp /tmp/config.js $pod:/usr/share/nginx/html/config.js -n sk1 - - # Verify the file was copied - kubectl exec $pod -n sk1 -- ls -la /usr/share/nginx/html/config.js || echo "Failed to copy config.js to $pod" -done - -# Update index.html to include this config file -for pod in $FRONTEND_PODS; do - kubectl exec $pod -n sk1 -- sh -c ' - if grep -q config.js /usr/share/nginx/html/index.html; then - echo "Config already included in index.html" - else - echo "Adding config.js to index.html" - sed -i "s||\n |" /usr/share/nginx/html/index.html - fi - ' -done - -echo "โœ… Frontend configuration updated with correct API URL" -echo "Try accessing your application again at https://nudges.works" \ No newline at end of file diff --git a/sk1/not use/fix-service-routes.sh b/sk1/not use/fix-service-routes.sh deleted file mode 100755 index 8b6f74c..0000000 --- a/sk1/not use/fix-service-routes.sh +++ /dev/null @@ -1,130 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# Create a more complete service routes file -cat > /tmp/service-routes.js << 'EOF' -// Service routes -app.get('/api/services/assembly', (req, res) => { - // Extract query parameters - const { radius, page, sortBy, order, lat, lon } = req.query; - - // Return mock data for now - res.json({ - success: true, - services: [ - { - id: 1, - name: "Assembly Service 1", - description: "Professional furniture assembly", - price: 25, - distance: 2.5, - rating: 4.5 - }, - { - id: 2, - name: "Assembly Service 2", - description: "IKEA specialist", - price: 30, - distance: 3.2, - rating: 4.8 - } - ], - pagination: { - currentPage: parseInt(page) || 1, - totalPages: 3, - totalResults: 6 - } - }); -}); - -// Add other service routes -app.get('/api/services/:serviceType', (req, res) => { - const serviceType = req.params.serviceType; - const { radius, page, sortBy, order, lat, lon } = req.query; - - // Return mock data for any service type - res.json({ - success: true, - services: [ - { - id: 1, - name: `${serviceType} Service 1`, - description: `Professional ${serviceType} service`, - price: Math.floor(Math.random() * 50) + 20, - distance: parseFloat((Math.random() * 5).toFixed(1)), - rating: parseFloat((Math.random() * 2 + 3).toFixed(1)) - }, - { - id: 2, - name: `${serviceType} Service 2`, - description: `Expert ${serviceType} provider`, - price: Math.floor(Math.random() * 50) + 20, - distance: parseFloat((Math.random() * 5).toFixed(1)), - rating: parseFloat((Math.random() * 2 + 3).toFixed(1)) - } - ], - pagination: { - currentPage: parseInt(page) || 1, - totalPages: 3, - totalResults: 6 - } - }); -}); - -// Authentication endpoints -app.post('/api/auth/login', (req, res) => { - res.json({ - success: true, - token: "mock-jwt-token", - user: { - id: 1, - name: "Test User", - email: "test@example.com" - } - }); -}); - -app.post('/api/auth/register', (req, res) => { - res.json({ - success: true, - message: "User registered successfully" - }); -}); -EOF - -# Create a ConfigMap with these routes -kubectl create configmap service-routes -n sk1 --from-file=routes.js=/tmp/service-routes.js --dry-run=client -o yaml | kubectl apply -f - - -# Find the backend pod -BACKEND_POD=$(kubectl get pods -n sk1 -l app=backend-fixed -o jsonpath='{.items[0].metadata.name}') - -# Copy the routes file to the backend pod -kubectl cp /tmp/service-routes.js $BACKEND_POD:/tmp/routes.js -n sk1 - -# Apply these routes to the running backend -kubectl exec $BACKEND_POD -n sk1 -- sh -c ' - echo "// Adding service routes" >> /app/index.js - cat /tmp/routes.js >> /app/index.js - echo "Service routes added to backend" - - # Force Node.js to reload (not ideal, but works for demo) - # In production, you would rebuild the container - kill -SIGHUP 1 || echo "Could not send SIGHUP, will restart pod instead" -' - -# Restart the backend pod to ensure routes are loaded -kubectl rollout restart deployment backend-fixed -n sk1 - -echo "โœ… Added service routes to backend" -echo "Waiting for backend to restart..." -kubectl rollout status deployment backend-fixed -n sk1 - -echo "๐Ÿ” Testing the specific route that was failing..." -# Create a test pod to check the route -kubectl run test-route --image=curlimages/curl -n sk1 --rm -it -- sh -c ' - echo "Testing /api/services/assembly endpoint:" - curl -s "http://backend-service:4000/api/services/assembly?radius=10&page=1&sortBy=distance&order=asc" - echo "" -' - -echo "โœจ Routes should now be working. Try accessing your application again at https://nudges.works" \ No newline at end of file diff --git a/sk1/not use/fixed-nginx-conf.yaml b/sk1/not use/fixed-nginx-conf.yaml deleted file mode 100755 index 6e06aed..0000000 --- a/sk1/not use/fixed-nginx-conf.yaml +++ /dev/null @@ -1,29 +0,0 @@ -apiVersion: v1 -kind: ConfigMap -metadata: - name: fixed-nginx-conf - namespace: sk1 -data: - nginx.conf: | - server { - listen 80; - server_name localhost; - root /usr/share/nginx/html; - index index.html; - - # All API requests should go to backend service - location /api/ { - proxy_pass http://backend-service:4000/; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection 'upgrade'; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_cache_bypass $http_upgrade; - } - - # All other requests go to the React app - location / { - try_files $uri $uri/ /index.html; - } - } diff --git a/sk1/not use/rebuild-backend.sh b/sk1/not use/rebuild-backend.sh deleted file mode 100755 index 3917dee..0000000 --- a/sk1/not use/rebuild-backend.sh +++ /dev/null @@ -1,78 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# Get project ID -PROJECT=$(gcloud config get-value project) - -# Create a new fixed backend deployment -cat > /tmp/fixed-backend.yaml << EOF -apiVersion: apps/v1 -kind: Deployment -metadata: - name: backend - namespace: sk1 -spec: - replicas: 1 - selector: - matchLabels: - app: backend - template: - metadata: - labels: - app: backend - spec: - containers: - - name: backend - image: gcr.io/${PROJECT}/backend:latest - resources: - limits: - cpu: "0.5" - memory: "512Mi" - requests: - cpu: "0.2" - memory: "256Mi" - ports: - - containerPort: 4000 - env: - - name: PORT - value: "4000" - - name: HOST - value: "0.0.0.0" - - name: MONGO_URI - valueFrom: - secretKeyRef: - name: mongodb-secret - key: MONGO_URI - - name: JWT_SECRET - valueFrom: - secretKeyRef: - name: mongodb-secret - key: JWT_SECRET - - name: GOOGLE_PLACES_API_KEY - valueFrom: - secretKeyRef: - name: mongodb-secret - key: GOOGLE_PLACES_API_KEY - # Simple health check that should work - readinessProbe: - httpGet: - path: /api - port: 4000 - initialDelaySeconds: 30 - periodSeconds: 5 - timeoutSeconds: 2 - livenessProbe: - httpGet: - path: /api - port: 4000 - initialDelaySeconds: 60 - periodSeconds: 15 - timeoutSeconds: 2 -EOF - -# Apply the new deployment -kubectl apply -f /tmp/fixed-backend.yaml - -echo "Applied fixed backend deployment" -echo "Watching backend pods..." -kubectl get pods -n sk1 -l app=backend -w \ No newline at end of file diff --git a/sk1/not use/refresh-connection.sh b/sk1/not use/refresh-connection.sh deleted file mode 100755 index 7c80c4d..0000000 --- a/sk1/not use/refresh-connection.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# Get project ID and zone -PROJECT=$(gcloud config get-value project) -ZONE="us-central1-a" -CLUSTER="sk1-cluster" - -echo "๐Ÿ”„ Refreshing connection to GKE cluster..." -gcloud container clusters get-credentials ${CLUSTER} --zone ${ZONE} --project ${PROJECT} - -echo "โœ… Connection refreshed" - -# Check what resources exist -echo "๐Ÿ” Checking resources..." -kubectl get pods -n sk1 -kubectl get services -n sk1 -kubectl get ingress -n sk1 || echo "No ingress resources found" \ No newline at end of file diff --git a/sk1/not use/resilient-deploy.sh b/sk1/not use/resilient-deploy.sh deleted file mode 100755 index 93df9f3..0000000 --- a/sk1/not use/resilient-deploy.sh +++ /dev/null @@ -1,96 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# Get project ID -PROJECT=$(gcloud config get-value project) -ZONE="us-central1-a" -CLUSTER="sk1-cluster" - -echo "๐Ÿ”„ Refreshing connection to GKE cluster..." -for i in {1..5}; do - echo "Attempt $i to connect to cluster..." - if gcloud container clusters get-credentials ${CLUSTER} --zone ${ZONE} --project ${PROJECT}; then - echo "โœ… Connection successful!" - break - else - echo "โŒ Connection failed, retrying in 5 seconds..." - sleep 5 - fi - - # If we've tried 5 times and still can't connect, show the cluster status - if [ $i -eq 5 ]; then - echo "โš ๏ธ Unable to connect after 5 attempts. Checking cluster status..." - gcloud container clusters describe ${CLUSTER} --zone ${ZONE} --project ${PROJECT} - fi -done - -echo "๐Ÿ“ Saving deployment YAML files locally..." - -# Save the deployment YAML locally -cat > backend-fixed-deployment.yaml << EOF -apiVersion: apps/v1 -kind: Deployment -metadata: - name: backend-fixed - namespace: sk1 -spec: - replicas: 1 - selector: - matchLabels: - app: backend-fixed - template: - metadata: - labels: - app: backend-fixed - spec: - containers: - - name: backend - image: gcr.io/${PROJECT}/backend-fixed:latest - env: - - name: PORT - value: "4000" - - name: HOST - value: "0.0.0.0" - - name: MONGO_URI - valueFrom: - secretKeyRef: - name: mongodb-secret - key: MONGO_URI - ports: - - containerPort: 4000 ---- -apiVersion: v1 -kind: Service -metadata: - name: backend-service - namespace: sk1 -spec: - selector: - app: backend-fixed - ports: - - port: 4000 - targetPort: 4000 -EOF - -echo "๐Ÿš€ Attempting to apply deployment YAML..." -for i in {1..5}; do - echo "Attempt $i to apply deployment..." - if kubectl apply -f backend-fixed-deployment.yaml; then - echo "โœ… Deployment successful!" - break - else - echo "โŒ Deployment failed, retrying in 5 seconds..." - sleep 5 - fi -done - -echo "๐ŸŒ Testing connection to GKE ingress..." -IP=$(gcloud compute addresses describe sk1-static-ip --global --format="value(address)") -echo "Your static IP is: ${IP}" - -echo "โœจ Next steps:" -echo "1. Access your application at: https://nudges.works" -echo "2. If issues persist, try accessing the backend directly:" -echo " curl -v http://${IP}/api" -echo "3. You can also check the GCP Console for more details:" -echo " https://console.cloud.google.com/kubernetes/workload" \ No newline at end of file diff --git a/sk1/not use/simple-backend.sh b/sk1/not use/simple-backend.sh deleted file mode 100755 index a8e06ea..0000000 --- a/sk1/not use/simple-backend.sh +++ /dev/null @@ -1,66 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# Get project ID -PROJECT=$(gcloud config get-value project) - -# Create a new fixed backend deployment with NO health probes -cat > /tmp/basic-backend.yaml << EOF -apiVersion: apps/v1 -kind: Deployment -metadata: - name: backend - namespace: sk1 -spec: - replicas: 1 - selector: - matchLabels: - app: backend - template: - metadata: - labels: - app: backend - spec: - containers: - - name: backend - image: gcr.io/${PROJECT}/backend:latest - resources: - limits: - cpu: "0.5" - memory: "512Mi" - requests: - cpu: "0.2" - memory: "256Mi" - ports: - - containerPort: 4000 - env: - - name: PORT - value: "4000" - - name: HOST - value: "0.0.0.0" - - name: MONGO_URI - valueFrom: - secretKeyRef: - name: mongodb-secret - key: MONGO_URI - - name: JWT_SECRET - valueFrom: - secretKeyRef: - name: mongodb-secret - key: JWT_SECRET - - name: GOOGLE_PLACES_API_KEY - valueFrom: - secretKeyRef: - name: mongodb-secret - key: GOOGLE_PLACES_API_KEY - # Add more verbose logging - - name: DEBUG - value: "express:*" -EOF - -# Apply the new deployment -kubectl apply -f /tmp/basic-backend.yaml - -echo "Applied basic backend deployment without health probes" -echo "Watching backend pods..." -kubectl get pods -n sk1 -l app=backend -w \ No newline at end of file diff --git a/sk1/not use/sk1-ingress.yaml b/sk1/not use/sk1-ingress.yaml deleted file mode 100755 index a07c4d3..0000000 --- a/sk1/not use/sk1-ingress.yaml +++ /dev/null @@ -1,27 +0,0 @@ -apiVersion: networking.k8s.io/v1 -kind: Ingress -metadata: - name: sk1-ingress - namespace: sk1 - annotations: - kubernetes.io/ingress.global-static-ip-name: sk1-static-ip - networking.gke.io/managed-certificates: sk1-cert -spec: - rules: - - host: nudges.works - http: - paths: - - path: /api - pathType: Prefix - backend: - service: - name: backend-service - port: - number: 4000 - - path: / - pathType: Prefix - backend: - service: - name: frontend-service - port: - number: 80 diff --git a/sk1/not use/test-api.sh b/sk1/not use/test-api.sh deleted file mode 100755 index 7a0d397..0000000 --- a/sk1/not use/test-api.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# Test backend API endpoints -kubectl run api-test --image=curlimages/curl -n sk1 --rm -it -- sh -c ' -echo "Testing backend API endpoints..." -echo "1. Root endpoint:" -curl -v http://backend-service:4000/ 2>&1 | grep "< HTTP" -echo "" -echo "2. /api endpoint:" -curl -v http://backend-service:4000/api 2>&1 | grep "< HTTP" -echo "" -echo "3. /api/auth/login endpoint:" -curl -v http://backend-service:4000/api/auth/login 2>&1 | grep "< HTTP" -' \ No newline at end of file diff --git a/sk1/not use/test-backend.sh b/sk1/not use/test-backend.sh deleted file mode 100755 index ffb8132..0000000 --- a/sk1/not use/test-backend.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# Create a debug pod to test backend API -kubectl run debug-pod --image=curlimages/curl -n sk1 --rm -it -- sh -c ' -echo "Testing backend API..." -echo "1. Testing /api endpoint:" -curl -v http://backend-service:4000/api -echo "" -echo "2. Testing /api/auth/login endpoint:" -curl -v http://backend-service:4000/api/auth/login -' \ No newline at end of file diff --git a/sk1/not use/test-connection.sh b/sk1/not use/test-connection.sh deleted file mode 100755 index 2b3d219..0000000 --- a/sk1/not use/test-connection.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# Create a test pod in the same namespace -kubectl run curl-basic --image=curlimages/curl -n sk1 --rm -it -- sh -c ' -echo "Simple connection test to backend-service:4000..." -curl -v telnet://backend-service:4000 2>&1 | grep "Connected" -echo "" -' \ No newline at end of file diff --git a/sk1/not use/test-network.sh b/sk1/not use/test-network.sh deleted file mode 100755 index 031073e..0000000 --- a/sk1/not use/test-network.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# Create a netshoot pod for better networking diagnostics -cat > /tmp/netshoot.yaml << EOF -apiVersion: v1 -kind: Pod -metadata: - name: netshoot - namespace: sk1 -spec: - containers: - - name: netshoot - image: nicolaka/netshoot - command: - - sleep - - "3600" -EOF - -kubectl apply -f /tmp/netshoot.yaml - -# Wait for pod to be ready -echo "Waiting for netshoot pod to be ready..." -kubectl wait --for=condition=Ready pod/netshoot -n sk1 --timeout=60s - -# Test DNS resolution and connectivity -kubectl exec -it netshoot -n sk1 -- bash -c ' -echo "Checking DNS for backend-service..." -nslookup backend-service -echo "" - -echo "Checking port connectivity..." -nc -zv backend-service 4000 -echo "" - -echo "Trying HTTP request to backend service..." -curl -v http://backend-service:4000/ -' \ No newline at end of file diff --git a/sk1/not use/test-routes.sh b/sk1/not use/test-routes.sh deleted file mode 100755 index 3a45fc8..0000000 --- a/sk1/not use/test-routes.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# Create a temporary pod to check what routes are available -kubectl run curl-test --image=curlimages/curl -n sk1 --rm -it -- sh -c ' -echo "Testing backend routes..." -for endpoint in / /api /api/ /api/health /healthz; do - echo "Testing $endpoint:" - curl -s -o /dev/null -w "%{http_code}" http://backend-service:4000$endpoint - echo "" -done -' \ No newline at end of file diff --git a/sk1/not use/update-frontend.sh b/sk1/not use/update-frontend.sh deleted file mode 100755 index 254feba..0000000 --- a/sk1/not use/update-frontend.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# Create a final nginx config for frontend -cat > /tmp/final-nginx.conf << 'EOF' -server { - listen 80; - server_name localhost; - root /usr/share/nginx/html; - index index.html; - - # API requests - make sure to point to the backend-service - location /api { - proxy_pass http://backend-service:4000; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection 'upgrade'; - proxy_set_header Host $host; - proxy_cache_bypass $http_upgrade; - } - - # All other requests go to the React app - location / { - try_files $uri $uri/ /index.html; - } -} -EOF - -# Create a ConfigMap from this nginx config -kubectl create configmap final-nginx-conf -n sk1 --from-file=nginx.conf=/tmp/final-nginx.conf --dry-run=client -o yaml | kubectl apply -f - - -# Update frontend deployment to use this ConfigMap -cat > /tmp/frontend-update.yaml << EOF -apiVersion: apps/v1 -kind: Deployment -metadata: - name: frontend - namespace: sk1 -spec: - template: - spec: - containers: - - name: frontend - volumeMounts: - - name: nginx-config - mountPath: /etc/nginx/conf.d/default.conf - subPath: nginx.conf - volumes: - - name: nginx-config - configMap: - name: final-nginx-conf -EOF - -# Apply the update -kubectl apply -f /tmp/frontend-update.yaml - -# Restart frontend pods -kubectl rollout restart deployment frontend -n sk1 - -echo "โœ… Frontend nginx configuration updated" \ No newline at end of file diff --git a/sk1/not use/update-nginx-config.sh b/sk1/not use/update-nginx-config.sh deleted file mode 100755 index 419d8f3..0000000 --- a/sk1/not use/update-nginx-config.sh +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# Create a corrected nginx.conf -cat > /tmp/nginx.conf << 'EOF' -server { - listen 80; - server_name localhost; - root /usr/share/nginx/html; - index index.html; - - # Redirect API requests to the backend service - location /api/ { - # Important: use backend-service.sk1.svc.cluster.local for the full internal DNS name - proxy_pass http://backend-service.sk1.svc.cluster.local:4000/; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection 'upgrade'; - proxy_set_header Host $host; - proxy_cache_bypass $http_upgrade; - - # Add debugging headers - add_header X-Debug-Target "backend-service.sk1.svc.cluster.local:4000" always; - } - - # Serve static assets - location / { - try_files $uri $uri/ /index.html; - } -} -EOF - -# Create a ConfigMap from this nginx.conf -kubectl create configmap nginx-config -n sk1 --from-file=/tmp/nginx.conf --dry-run=client -o yaml | kubectl apply -f - - -# Update the frontend deployment to use this ConfigMap -cat > /tmp/frontend-deployment-update.yaml << EOF -apiVersion: apps/v1 -kind: Deployment -metadata: - name: frontend - namespace: sk1 -spec: - template: - spec: - containers: - - name: frontend - volumeMounts: - - name: nginx-config - mountPath: /etc/nginx/conf.d/default.conf - subPath: nginx.conf - volumes: - - name: nginx-config - configMap: - name: nginx-config -EOF - -# Apply the update as a patch -kubectl patch deployment frontend -n sk1 --patch-file /tmp/frontend-deployment-update.yaml \ No newline at end of file diff --git a/sk1/not use/verify-service.sh b/sk1/not use/verify-service.sh deleted file mode 100755 index b84eefd..0000000 --- a/sk1/not use/verify-service.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -echo "๐Ÿ” Checking pods..." -kubectl get pods -n sk1 - -echo "๐Ÿ” Checking services..." -kubectl get services -n sk1 - -echo "๐Ÿ” Checking backend logs..." -BACKEND_POD=$(kubectl get pods -n sk1 -l app=backend -o jsonpath='{.items[0].metadata.name}' 2>/dev/null) || echo "No backend pod found" -if [ -n "$BACKEND_POD" ]; then - kubectl logs -n sk1 $BACKEND_POD --tail=10 -else - echo "โš ๏ธ Backend pod not found. Please check deployment status." -fi - -echo "๐Ÿ” Testing backend service directly..." -kubectl run test-backend --image=curlimages/curl -n sk1 --rm -it -- curl -v http://backend-service:4000/api || echo "Failed to test backend" - -echo "โœ… Verification complete!" \ No newline at end of file