From 2243b34545f2f6834fe12a31a8792aa44597fa8e Mon Sep 17 00:00:00 2001 From: kunal-511 Date: Sun, 7 Sep 2025 02:07:43 +0530 Subject: [PATCH 01/14] Update build dir Signed-off-by: kunal-511 --- backend/dockerfile | 4 ++-- frontend/dockerfile | 10 +++++----- frontend/src/components/SplashCursor.tsx | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/backend/dockerfile b/backend/dockerfile index 35ca82a..8b2a14a 100644 --- a/backend/dockerfile +++ b/backend/dockerfile @@ -5,13 +5,13 @@ FROM node:20-alpine WORKDIR /usr/src/app # Copy package.json and package-lock.json -COPY package*.json ./ +COPY backend/package*.json ./ # Install dependencies RUN yarn install --frozen-lockfile # Copy the rest of the application code -COPY . . +COPY backend/ . # Expose the port the app runs on EXPOSE 5000 diff --git a/frontend/dockerfile b/frontend/dockerfile index bbb34da..558a0d4 100644 --- a/frontend/dockerfile +++ b/frontend/dockerfile @@ -4,21 +4,21 @@ FROM node:20-alpine # Set working directory in the container WORKDIR /app -# Copy package.json and package-lock.json (or yarn.lock) -COPY package*.json ./ -COPY yarn.lock* ./ +# Copy package.json and package-lock.json +COPY frontend/package*.json ./ +COPY frontend/yarn.lock* ./ # Install dependencies RUN yarn install --frozen-lockfile # Copy the rest of the application code -COPY . . +COPY frontend/ . # Set the Clerk publishable key ARG VITE_CLERK_PUBLISHABLE_KEY ENV VITE_CLERK_PUBLISHABLE_KEY=$VITE_CLERK_PUBLISHABLE_KEY -# Expose port 5173 for Vite dev server +# Expose port EXPOSE 3000 # Start Vite dev server with host set to listen on all interfaces diff --git a/frontend/src/components/SplashCursor.tsx b/frontend/src/components/SplashCursor.tsx index 4b8e8c0..9406abb 100644 --- a/frontend/src/components/SplashCursor.tsx +++ b/frontend/src/components/SplashCursor.tsx @@ -631,8 +631,8 @@ function SplashCursor({ } function createDoubleFBO(w, h, internalFormat, format, type, param) { - const fbo1 = createFBO(w, h, internalFormat, format, type, param); - const fbo2 = createFBO(w, h, internalFormat, format, type, param); + let fbo1 = createFBO(w, h, internalFormat, format, type, param); + let fbo2 = createFBO(w, h, internalFormat, format, type, param); return { width: w, height: h, From d6f97aaaf87be457c29d428876a5c75c3aa2cb74 Mon Sep 17 00:00:00 2001 From: kunal-511 Date: Sun, 7 Sep 2025 02:28:17 +0530 Subject: [PATCH 02/14] Fix redis Signed-off-by: kunal-511 --- backend/src/lib/socket.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/src/lib/socket.js b/backend/src/lib/socket.js index 7f27bc1..9c6ca3e 100644 --- a/backend/src/lib/socket.js +++ b/backend/src/lib/socket.js @@ -75,9 +75,9 @@ export const initializeSocket = (server) => { // find disconnected user if (socketId === socket.id) { disconnectedUserId = userId; - await client.hdel('user:sockets', userId); - await client.srem('users:online', userId); - await client.hdel('user:activities', userId); + await client.hDel('user:sockets', userId); + await client.sRem('users:online', userId); + await client.hDel('user:activities', userId); break; } } From 33829bf3b7b918eb6f7abf57750352aa18c17c83 Mon Sep 17 00:00:00 2001 From: kunal-511 Date: Sun, 7 Sep 2025 02:37:09 +0530 Subject: [PATCH 03/14] Improve error handling Signed-off-by: kunal-511 --- backend/src/controller/analytics.controller.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/backend/src/controller/analytics.controller.js b/backend/src/controller/analytics.controller.js index 1703fc2..1698c95 100644 --- a/backend/src/controller/analytics.controller.js +++ b/backend/src/controller/analytics.controller.js @@ -5,20 +5,23 @@ export const trackSongPlay = async (req, res, next) => { const { songId } = req.params; const userId = req.auth?.userId; + if (!userId || !songId) { return res.status(400).json({ error: 'Missing required data' }); } + await client.zIncrBy('songs:plays:global', 1, songId); await client.zIncrBy(`songs:plays:user:${userId}`, 1, songId); const hour = new Date().toISOString().slice(0, 13); await client.zIncrBy(`analytics:hourly:${hour}`, 1, songId); - await client.lpush(`user:${userId}:recent`, songId); - await client.ltrim(`user:${userId}:recent`, 0, 49); + await client.lPush(`user:${userId}:recent`, songId); + await client.lTrim(`user:${userId}:recent`, 0, 49); res.json({ success: true }); } catch (error) { + console.error("Error in trackSongPlay:", error); next(error); } } From 7864d9c3fd1418f1cad963315f5cc1929aacc963 Mon Sep 17 00:00:00 2001 From: kunal-511 Date: Sun, 7 Sep 2025 03:13:38 +0530 Subject: [PATCH 04/14] add docker compose Signed-off-by: kunal-511 --- backend/src/lib/redis.js | 6 ++- docker-compose.yml | 102 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 docker-compose.yml diff --git a/backend/src/lib/redis.js b/backend/src/lib/redis.js index a811f88..ae2ad99 100644 --- a/backend/src/lib/redis.js +++ b/backend/src/lib/redis.js @@ -2,8 +2,10 @@ import { createClient } from 'redis'; const client = createClient({ - host: process.env.REDIS_HOST || 'localhost', - port: process.env.REDIS_PORT || 6379, + url: `redis://${process.env.REDIS_HOST || 'localhost'}:${process.env.REDIS_PORT || 6379}`, + socket: { + reconnectStrategy: (retries) => Math.min(retries * 50, 1000) + }, retryDelayOnFailover: 100, maxRetriesPerRequest: 3, lazyConnect: true, diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..d3d5970 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,102 @@ + +services: + # Redis Cache Service + redis: + image: redis:7.2-alpine + container_name: beatwave-redis + restart: unless-stopped + ports: + - "6379:6379" + volumes: + - redis_data:/data + networks: + - beatwave-network + command: redis-server --appendonly yes + healthcheck: + test: ["CMD", "redis-cli", "ping"] + interval: 10s + timeout: 5s + retries: 5 + + # Backend Service + backend: + build: + context: . + dockerfile: backend/dockerfile + container_name: beatwave-backend + restart: unless-stopped + ports: + - "5000:5000" + environment: + - NODE_ENV=production + - PORT=5000 + - REDIS_HOST=redis + - REDIS_PORT=6379 + - MONGODB_URI=${MONGODB_URI} + - ADMIN_EMAIL=${ADMIN_EMAIL} + - RAZORPAY_KEY_ID=${RAZORPAY_KEY_ID} + - RAZORPAY_KEY_SECRET=${RAZORPAY_KEY_SECRET} + - CLOUDINARY_CLOUD_NAME=${CLOUDINARY_CLOUD_NAME} + - CLOUDINARY_API_KEY=${CLOUDINARY_API_KEY} + - CLOUDINARY_API_SECRET=${CLOUDINARY_API_SECRET} + - CLERK_SECRET_KEY=${CLERK_SECRET_KEY} + volumes: + - ./backend/tmp:/usr/src/app/tmp + - backend_uploads:/usr/src/app/uploads + networks: + - beatwave-network + depends_on: + redis: + condition: service_healthy + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:5000/api/health || exit 1"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 40s + + # Frontend Service + frontend: + build: + context: . + dockerfile: frontend/dockerfile + args: + - VITE_CLERK_PUBLISHABLE_KEY=${VITE_CLERK_PUBLISHABLE_KEY} + - VITE_RAZORPAY_KEY_ID=${VITE_RAZORPAY_KEY_ID} + - VITE_API_URL=http://backend:5000/api + container_name: beatwave-frontend + restart: unless-stopped + ports: + - "3000:3000" + environment: + - VITE_CLERK_PUBLISHABLE_KEY=${VITE_CLERK_PUBLISHABLE_KEY} + - VITE_RAZORPAY_KEY_ID=${VITE_RAZORPAY_KEY_ID} + - VITE_API_URL=http://localhost:5000/api + networks: + - beatwave-network + depends_on: + - backend + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:3000 || exit 1"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 60s + + +# Volumes for Data Persistence +volumes: + redis_data: + driver: local + backend_uploads: + driver: local + + +# Custom Network for Service Communication +networks: + beatwave-network: + driver: bridge + ipam: + driver: default + config: + - subnet: 192.168.100.0/24 From 596bc97adb23b164b9c5d43de2fc1a004f5d5aa8 Mon Sep 17 00:00:00 2001 From: kunal-511 Date: Sun, 7 Sep 2025 17:46:18 +0530 Subject: [PATCH 05/14] add nginx for frontend --- docker-compose.yml | 4 ++-- frontend/dockerfile | 22 +++++++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index d3d5970..0dbe89e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -67,7 +67,7 @@ services: container_name: beatwave-frontend restart: unless-stopped ports: - - "3000:3000" + - "3000:80" environment: - VITE_CLERK_PUBLISHABLE_KEY=${VITE_CLERK_PUBLISHABLE_KEY} - VITE_RAZORPAY_KEY_ID=${VITE_RAZORPAY_KEY_ID} @@ -77,7 +77,7 @@ services: depends_on: - backend healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:3000 || exit 1"] + test: ["CMD", "curl", "-f", "http://localhost:80 || exit 1"] interval: 30s timeout: 10s retries: 3 diff --git a/frontend/dockerfile b/frontend/dockerfile index 558a0d4..46989f7 100644 --- a/frontend/dockerfile +++ b/frontend/dockerfile @@ -1,5 +1,5 @@ # Use an official Node runtime as the base image -FROM node:20-alpine +FROM node:20-alpine AS build # Set working directory in the container WORKDIR /app @@ -18,8 +18,20 @@ COPY frontend/ . ARG VITE_CLERK_PUBLISHABLE_KEY ENV VITE_CLERK_PUBLISHABLE_KEY=$VITE_CLERK_PUBLISHABLE_KEY -# Expose port -EXPOSE 3000 +# Build the application +RUN yarn build -# Start Vite dev server with host set to listen on all interfaces -CMD ["yarn", "dev", "--host", "0.0.0.0", "--port", "3000"] \ No newline at end of file +# Production stage +FROM nginx:alpine +COPY --from=build /app/dist /usr/share/nginx/html +EXPOSE 80 +CMD ["nginx", "-g", "daemon off;"] + + + +# Dev Mode +# # Expose port +# EXPOSE 3000 + +# # Start Vite dev server with host set to listen on all interfaces +# CMD ["yarn", "dev", "--host", "0.0.0.0", "--port", "3000"] \ No newline at end of file From 3de1f3b8c48750e979f4a782d2261e9401d58fd3 Mon Sep 17 00:00:00 2001 From: kunal-511 Date: Sun, 7 Sep 2025 17:53:08 +0530 Subject: [PATCH 06/14] add docker build images and after build update manifests --- .github/workflows/build-and-deploy.yml | 243 +++++++++++++++++++++++++ 1 file changed, 243 insertions(+) create mode 100644 .github/workflows/build-and-deploy.yml diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml new file mode 100644 index 0000000..e012eb0 --- /dev/null +++ b/.github/workflows/build-and-deploy.yml @@ -0,0 +1,243 @@ +name: Build and Deploy to Production + +on: + push: + branches: [production] + pull_request: + branches: [production] + +env: + REGISTRY: ghcr.io + FRONTEND_IMAGE_NAME: kunal-511/beatwave + BACKEND_IMAGE_NAME: kunal-511/beatwave-backend + +jobs: + # Generate semantic version based on commit + versioning: + runs-on: ubuntu-latest + outputs: + version: ${{ steps.version.outputs.version }} + major: ${{ steps.version.outputs.major }} + minor: ${{ steps.version.outputs.minor }} + patch: ${{ steps.version.outputs.patch }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Generate version + id: version + run: | + LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") + echo "Latest tag: $LATEST_TAG" + + VERSION_NUM=${LATEST_TAG#v} + + # Split version into components + IFS='.' read -ra VERSION_PARTS <<< "$VERSION_NUM" + MAJOR=${VERSION_PARTS[0]:-0} + MINOR=${VERSION_PARTS[1]:-0} + PATCH=${VERSION_PARTS[2]:-0} + + COMMIT_MSG=$(git log -1 --pretty=%B) + + if [[ $COMMIT_MSG == *"BREAKING CHANGE"* ]] || [[ $COMMIT_MSG == *"major:"* ]]; then + MAJOR=$((MAJOR + 1)) + MINOR=0 + PATCH=0 + elif [[ $COMMIT_MSG == *"feat:"* ]] || [[ $COMMIT_MSG == *"feature:"* ]] || [[ $COMMIT_MSG == *"minor:"* ]]; then + MINOR=$((MINOR + 1)) + PATCH=0 + else + PATCH=$((PATCH + 1)) + fi + + NEW_VERSION="v${MAJOR}.${MINOR}.${PATCH}" + echo "New version: $NEW_VERSION" + + echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT + echo "major=$MAJOR" >> $GITHUB_OUTPUT + echo "minor=$MINOR" >> $GITHUB_OUTPUT + echo "patch=$PATCH" >> $GITHUB_OUTPUT + + # Build and push backend image + build-backend: + runs-on: ubuntu-latest + needs: versioning + permissions: + contents: read + packages: write + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Log in to Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Extract metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.BACKEND_IMAGE_NAME }} + tags: | + type=raw,value=${{ needs.versioning.outputs.version }} + type=raw,value=latest,enable={{is_default_branch}} + type=raw,value=v${{ needs.versioning.outputs.major }} + type=raw,value=v${{ needs.versioning.outputs.major }}.${{ needs.versioning.outputs.minor }} + + - name: Build and push Backend Docker image + uses: docker/build-push-action@v5 + with: + context: . + file: ./backend/dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + platforms: linux/amd64,linux/arm64 + cache-from: type=gha + cache-to: type=gha,mode=max + build-args: | + BUILDTIME=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }} + VERSION=${{ needs.versioning.outputs.version }} + + # Build and push frontend image + build-frontend: + runs-on: ubuntu-latest + needs: versioning + permissions: + contents: read + packages: write + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Log in to Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Extract metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.FRONTEND_IMAGE_NAME }} + tags: | + type=raw,value=${{ needs.versioning.outputs.version }} + type=raw,value=latest,enable={{is_default_branch}} + type=raw,value=v${{ needs.versioning.outputs.major }} + type=raw,value=v${{ needs.versioning.outputs.major }}.${{ needs.versioning.outputs.minor }} + + - name: Build and push Frontend Docker image + uses: docker/build-push-action@v5 + with: + context: . + file: ./frontend/dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + platforms: linux/amd64,linux/arm64 + cache-from: type=gha + cache-to: type=gha,mode=max + build-args: | + BUILDTIME=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }} + VERSION=${{ needs.versioning.outputs.version }} + VITE_CLERK_PUBLISHABLE_KEY=${{ secrets.VITE_CLERK_PUBLISHABLE_KEY }} + + # Update Kubernetes deployment files + update-k8s-manifests: + runs-on: ubuntu-latest + needs: [versioning, build-backend, build-frontend] + if: github.event_name == 'push' && github.ref == 'refs/heads/production' + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Update Kubernetes manifests + run: | + VERSION=${{ needs.versioning.outputs.version }} + + # Update backend deployment + sed -i "s|image: ghcr.io/kunal-511/beatwave-backend:.*|image: ghcr.io/kunal-511/beatwave-backend:$VERSION|g" k8s/backend-deployment.yml + + # Update frontend deployment + sed -i "s|image: ghcr.io/kunal-511/beatwave:.*|image: ghcr.io/kunal-511/beatwave:$VERSION|g" k8s/frontend-deployment.yml + + echo "Updated manifests with version: $VERSION" + - name: Validate Kubernetes manifests + run: | + kubectl apply --dry-run=client -f k8s/backend-deployment.yml + kubectl apply --dry-run=client -f k8s/frontend-deployment.yml + + - name: Commit updated manifests + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git add k8s/ + git diff --staged --quiet || git commit -m "chore: update K8s manifests to ${{ needs.versioning.outputs.version }} [skip ci]" + git push + + # Security scanning + security-scan: + runs-on: ubuntu-latest + needs: [build-backend, build-frontend, versioning] + if: github.event_name == 'push' + permissions: + security-events: write + steps: + - name: Run Trivy vulnerability scanner - Backend + uses: aquasecurity/trivy-action@master + with: + image-ref: 'ghcr.io/kunal-511/beatwave-backend:${{ needs.versioning.outputs.version }}' + format: 'sarif' + output: 'backend-trivy-results.sarif' + + - name: Upload Trivy scan results - Backend + uses: github/codeql-action/upload-sarif@v2 + with: + sarif_file: 'backend-trivy-results.sarif' + category: 'backend-image' + + - name: Run Trivy vulnerability scanner - Frontend + uses: aquasecurity/trivy-action@master + with: + image-ref: 'ghcr.io/kunal-511/beatwave:${{ needs.versioning.outputs.version }}' + format: 'sarif' + output: 'frontend-trivy-results.sarif' + + - name: Upload Trivy scan results - Frontend + uses: github/codeql-action/upload-sarif@v2 + with: + sarif_file: 'frontend-trivy-results.sarif' + category: 'frontend-image' + + # Notification + notify: + runs-on: ubuntu-latest + needs: [versioning, build-backend, build-frontend] + if: always() && github.event_name == 'push' && github.ref == 'refs/heads/production' + steps: + - name: Notify deployment status + run: | + if [[ "${{ needs.build-backend.result }}" == "success" && "${{ needs.build-frontend.result }}" == "success" ]]; then + echo "Successfully built and pushed BeatWave ${{ needs.versioning.outputs.version }}" + echo "Frontend: ghcr.io/kunal-511/beatwave:${{ needs.versioning.outputs.version }}" + echo "Backend: ghcr.io/kunal-511/beatwave-backend:${{ needs.versioning.outputs.version }}" + else + echo "Build failed for BeatWave ${{ needs.versioning.outputs.version }}" + exit 1 + fi From 8beab45851af28e958e254ce1947e1d8338bf56a Mon Sep 17 00:00:00 2001 From: kunal-511 Date: Sun, 7 Sep 2025 18:02:28 +0530 Subject: [PATCH 07/14] update readme to include the redis --- README.md | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9def101..2361b07 100644 --- a/README.md +++ b/README.md @@ -70,13 +70,13 @@ BeatWave is a comprehensive music streaming application that provides seamless m - **Docker** for containerization and deployment -```` ## ⚙️ Getting Started ### Prerequisites - Node.js 18+ installed - MongoDB database (local or cloud) +- Redis server (local or cloud) - Cloudinary account for media storage - Clerk account for authentication @@ -87,7 +87,6 @@ BeatWave is a comprehensive music streaming application that provides seamless m git clone https://github.com/kunal-2004/beatwave.git cd beatwave ``` - 2. **Install dependencies** ```bash @@ -103,6 +102,8 @@ BeatWave is a comprehensive music streaming application that provides seamless m ```env PORT=5000 MONGODB_URI=your_mongodb_connection_string + REDIS_HOST=localhost + REDIS_PORT=6379 CLERK_SECRET_KEY=your_clerk_secret_key CLOUDINARY_CLOUD_NAME=your_cloudinary_cloud_name CLOUDINARY_API_KEY=your_cloudinary_api_key @@ -118,7 +119,17 @@ BeatWave is a comprehensive music streaming application that provides seamless m VITE_API_URL=http://localhost:5000 ``` -4. **Start the development servers** +4. **Start Redis server** + + ```bash + # Start Redis server locally + redis-server + + # Or using Docker + docker run -d -p 6379:6379 redis:7.2-alpine + ``` + +5. **Start the development servers** ```bash # Start backend server @@ -128,7 +139,7 @@ BeatWave is a comprehensive music streaming application that provides seamless m cd frontend && npm run dev ``` -5. **Access the application** +6. **Access the application** * Frontend: `http://localhost:5173` * Backend API: `http://localhost:5000` From 1faf8d72d7b2daf8abb1d7505f657cdfb71d9e2a Mon Sep 17 00:00:00 2001 From: kunal-511 Date: Sun, 7 Sep 2025 21:11:18 +0530 Subject: [PATCH 08/14] update env name --- .github/workflows/build-and-deploy.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml index e012eb0..dd039b8 100644 --- a/.github/workflows/build-and-deploy.yml +++ b/.github/workflows/build-and-deploy.yml @@ -77,7 +77,7 @@ jobs: with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} + password: ${{ secrets.GHCR_TOKEN }} - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -124,7 +124,7 @@ jobs: with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} + password: ${{ secrets.GHCR_TOKEN }} - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -165,7 +165,7 @@ jobs: - name: Checkout code uses: actions/checkout@v4 with: - token: ${{ secrets.GITHUB_TOKEN }} + token: ${{ secrets.GHCR_TOKEN }} - name: Update Kubernetes manifests run: | From ac2f41ba92fa0ae8a6fc761083a47f48d8214f83 Mon Sep 17 00:00:00 2001 From: kunal-511 Date: Sun, 7 Sep 2025 21:35:22 +0530 Subject: [PATCH 09/14] update permissions and env --- .github/workflows/build-and-deploy.yml | 8 +++++--- k8s/secrets.yml | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml index dd039b8..d7b0fa4 100644 --- a/.github/workflows/build-and-deploy.yml +++ b/.github/workflows/build-and-deploy.yml @@ -77,7 +77,7 @@ jobs: with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} - password: ${{ secrets.GHCR_TOKEN }} + password: ${{ secrets.GITHUB_TOKEN }} - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -124,7 +124,7 @@ jobs: with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} - password: ${{ secrets.GHCR_TOKEN }} + password: ${{ secrets.GITHUB_TOKEN }} - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -161,11 +161,13 @@ jobs: runs-on: ubuntu-latest needs: [versioning, build-backend, build-frontend] if: github.event_name == 'push' && github.ref == 'refs/heads/production' + permissions: + contents: write steps: - name: Checkout code uses: actions/checkout@v4 with: - token: ${{ secrets.GHCR_TOKEN }} + token: ${{ secrets.GITHUB_TOKEN }} - name: Update Kubernetes manifests run: | diff --git a/k8s/secrets.yml b/k8s/secrets.yml index 63a3542..d397465 100644 --- a/k8s/secrets.yml +++ b/k8s/secrets.yml @@ -11,3 +11,5 @@ stringData: CLOUDINARY_API_SECRET: I_390-QsdGBlVnJb0B30qz-ywY0 CLOUDINARY_CLOUD_NAME: dxevfrvvd MONGODB_URI: "mongodb+srv://yoyokvunal:SflISJ3jlvg5c0JQ@cluster0.nws3o.mongodb.net/beatwave_db?retryWrites=true&w=majority&appName=Cluster0" + RAZORPAY_KEY_ID: "rzp_test_zOhpl2KPINrq20" + RAZORPAY_KEY_SECRET: "05kRpC9bdgvFeZIqURA62jXz" \ No newline at end of file From 60436163c69ece6ae4fed022bfad5cb7cb10104e Mon Sep 17 00:00:00 2001 From: kunal-511 Date: Sun, 7 Sep 2025 21:41:09 +0530 Subject: [PATCH 10/14] update permissions --- .github/workflows/build-and-deploy.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml index d7b0fa4..bffcf9c 100644 --- a/.github/workflows/build-and-deploy.yml +++ b/.github/workflows/build-and-deploy.yml @@ -6,6 +6,10 @@ on: pull_request: branches: [production] +permissions: + contents: read + packages: write + env: REGISTRY: ghcr.io FRONTEND_IMAGE_NAME: kunal-511/beatwave @@ -78,6 +82,7 @@ jobs: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + logout: false - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -125,6 +130,7 @@ jobs: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + logout: false - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -163,6 +169,7 @@ jobs: if: github.event_name == 'push' && github.ref == 'refs/heads/production' permissions: contents: write + packages: read steps: - name: Checkout code uses: actions/checkout@v4 From 4ba2ec25a556f0c16a1015971e7c5205a52a7561 Mon Sep 17 00:00:00 2001 From: kunal-511 Date: Mon, 8 Sep 2025 23:34:31 +0530 Subject: [PATCH 11/14] update to latest version --- .github/workflows/build-and-deploy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml index bffcf9c..48d15c5 100644 --- a/.github/workflows/build-and-deploy.yml +++ b/.github/workflows/build-and-deploy.yml @@ -99,7 +99,7 @@ jobs: type=raw,value=v${{ needs.versioning.outputs.major }}.${{ needs.versioning.outputs.minor }} - name: Build and push Backend Docker image - uses: docker/build-push-action@v5 + uses: docker/build-push-action@v6 with: context: . file: ./backend/dockerfile @@ -147,7 +147,7 @@ jobs: type=raw,value=v${{ needs.versioning.outputs.major }}.${{ needs.versioning.outputs.minor }} - name: Build and push Frontend Docker image - uses: docker/build-push-action@v5 + uses: docker/build-push-action@v6 with: context: . file: ./frontend/dockerfile From aa78c5e16eb81ba392ea2b4a4dacac00f39e42f8 Mon Sep 17 00:00:00 2001 From: kunal-511 Date: Tue, 9 Sep 2025 02:00:32 +0530 Subject: [PATCH 12/14] remove validation --- .github/workflows/build-and-deploy.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml index 48d15c5..4d20d24 100644 --- a/.github/workflows/build-and-deploy.yml +++ b/.github/workflows/build-and-deploy.yml @@ -187,10 +187,6 @@ jobs: sed -i "s|image: ghcr.io/kunal-511/beatwave:.*|image: ghcr.io/kunal-511/beatwave:$VERSION|g" k8s/frontend-deployment.yml echo "Updated manifests with version: $VERSION" - - name: Validate Kubernetes manifests - run: | - kubectl apply --dry-run=client -f k8s/backend-deployment.yml - kubectl apply --dry-run=client -f k8s/frontend-deployment.yml - name: Commit updated manifests run: | From 6ca6db0d9d1563de53c3d9cd9bb531797019a5c4 Mon Sep 17 00:00:00 2001 From: Kunal Dugar Date: Tue, 9 Sep 2025 02:05:52 +0530 Subject: [PATCH 13/14] Production (#6) * remove validations (#5) * Update build dir Signed-off-by: kunal-511 * Fix redis Signed-off-by: kunal-511 * Improve error handling Signed-off-by: kunal-511 * add docker compose Signed-off-by: kunal-511 * add nginx for frontend * add docker build images and after build update manifests * update readme to include the redis * update env name * update permissions and env * update permissions * update to latest version * remove validation --------- Signed-off-by: kunal-511 * chore: update K8s manifests to v0.0.1 [skip ci] --------- Signed-off-by: kunal-511 Co-authored-by: GitHub Action --- k8s/backend-deployment.yml | 2 +- k8s/frontend-deployment.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/k8s/backend-deployment.yml b/k8s/backend-deployment.yml index 6d612c4..bfeb66c 100644 --- a/k8s/backend-deployment.yml +++ b/k8s/backend-deployment.yml @@ -19,7 +19,7 @@ spec: spec: containers: - name: beatwave-backend - image: ghcr.io/kunal-511/beatwave-backend:v2 + image: ghcr.io/kunal-511/beatwave-backend:v0.0.1 ports: - containerPort: 5000 env: diff --git a/k8s/frontend-deployment.yml b/k8s/frontend-deployment.yml index 5ceffae..11d4322 100644 --- a/k8s/frontend-deployment.yml +++ b/k8s/frontend-deployment.yml @@ -17,7 +17,7 @@ spec: spec: containers: - name: beatwave-frontend - image: ghcr.io/kunal-511/beatwave:v2 + image: ghcr.io/kunal-511/beatwave:v0.0.1 ports: - containerPort: 3000 env: From 0e2836ad98995dd6f1047e3c21a9092f20910f1d Mon Sep 17 00:00:00 2001 From: kunal-511 Date: Tue, 9 Sep 2025 02:29:37 +0530 Subject: [PATCH 14/14] fix manifests --- frontend/src/lib/axios.ts | 2 +- k8s/backend-deployment.yml | 10 ++++++++++ k8s/configmaps.yml | 2 ++ k8s/frontend-deployment.yml | 5 ++++- k8s/frontend-service.yml | 2 +- k8s/redis-deployment.yaml | 2 +- k8s/redis-service.yaml | 4 ++-- 7 files changed, 21 insertions(+), 6 deletions(-) diff --git a/frontend/src/lib/axios.ts b/frontend/src/lib/axios.ts index 60c45a5..ef220fe 100644 --- a/frontend/src/lib/axios.ts +++ b/frontend/src/lib/axios.ts @@ -1,5 +1,5 @@ import axios from "axios"; export const axiosInstance = axios.create({ - baseURL: import.meta.env.MODE === "development" ? "http://localhost:5000/api" : "/api", + baseURL: import.meta.env.VITE_API_URL || (import.meta.env.MODE === "development" ? "http://localhost:5000/api" : "/api"), }); diff --git a/k8s/backend-deployment.yml b/k8s/backend-deployment.yml index bfeb66c..2ffd936 100644 --- a/k8s/backend-deployment.yml +++ b/k8s/backend-deployment.yml @@ -40,6 +40,16 @@ spec: configMapKeyRef: name: backend-port key: NODE_ENV + - name: REDIS_HOST + valueFrom: + configMapKeyRef: + name: backend-port + key: REDIS_HOST + - name: REDIS_PORT + valueFrom: + configMapKeyRef: + name: backend-port + key: REDIS_PORT - name: MONGODB_URI valueFrom: diff --git a/k8s/configmaps.yml b/k8s/configmaps.yml index 8447e4d..cf0846e 100644 --- a/k8s/configmaps.yml +++ b/k8s/configmaps.yml @@ -7,3 +7,5 @@ data: PORT: "5000" ADMIN_EMAIL: "yoyokvunal@gmail.com" NODE_ENV: "development" + REDIS_HOST: "redis" + REDIS_PORT: "6379" diff --git a/k8s/frontend-deployment.yml b/k8s/frontend-deployment.yml index 11d4322..101f2d7 100644 --- a/k8s/frontend-deployment.yml +++ b/k8s/frontend-deployment.yml @@ -19,10 +19,13 @@ spec: - name: beatwave-frontend image: ghcr.io/kunal-511/beatwave:v0.0.1 ports: - - containerPort: 3000 + - containerPort: 80 env: - name: VITE_CLERK_PUBLISHABLE_KEY valueFrom: secretKeyRef: name: backend-secrets key: VITE_CLERK_PUBLISHABLE_KEY + + - name: VITE_API_URL + value: "http://backend:5000/api" diff --git a/k8s/frontend-service.yml b/k8s/frontend-service.yml index 737c8b5..c2a18ed 100644 --- a/k8s/frontend-service.yml +++ b/k8s/frontend-service.yml @@ -8,4 +8,4 @@ spec: app: frontend ports: - port: 3000 - targetPort: 3000 + targetPort: 80 diff --git a/k8s/redis-deployment.yaml b/k8s/redis-deployment.yaml index a652351..cba06d1 100644 --- a/k8s/redis-deployment.yaml +++ b/k8s/redis-deployment.yaml @@ -18,4 +18,4 @@ spec: image: redis:7.2-alpine ports: - containerPort: 6379 - commands: ["redis-server", "--appendonly", "yes"] + command: ["redis-server", "--appendonly", "yes"] diff --git a/k8s/redis-service.yaml b/k8s/redis-service.yaml index 8d2b9e9..2143048 100644 --- a/k8s/redis-service.yaml +++ b/k8s/redis-service.yaml @@ -1,5 +1,5 @@ -apiVersion: apps/v1 -kind:: Service +apiVersion: v1 +kind: Service metadata: name: redis namespace: beatwave