fix: use build.env in vercel.json for proper Vite build-time var inje… #16
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI/CD Pipeline — Advanced Task Manager | |
| on: | |
| push: | |
| branches: [main, develop] | |
| pull_request: | |
| branches: [main] | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_BACKEND: ${{ github.repository }}/taskmanager-backend | |
| IMAGE_FRONTEND: ${{ github.repository }}/taskmanager-frontend | |
| jobs: | |
| # ══════════════════════════════════════════════════════════════════════════ | |
| # JOB 1 — Backend Tests + Build | |
| # ══════════════════════════════════════════════════════════════════════════ | |
| backend-test: | |
| name: 🧪 Backend — Test & Build | |
| runs-on: ubuntu-latest | |
| services: | |
| postgres: | |
| image: postgres:16-alpine | |
| env: | |
| POSTGRES_DB: taskmanager_test | |
| POSTGRES_USER: postgres | |
| POSTGRES_PASSWORD: test123 | |
| ports: | |
| - 5432:5432 | |
| options: >- | |
| --health-cmd pg_isready | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 5 | |
| steps: | |
| - name: 📥 Checkout code | |
| uses: actions/checkout@v4 | |
| - name: ☕ Set up JDK 17 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| cache: maven | |
| - name: 🧪 Run tests | |
| run: ./mvnw test -B | |
| env: | |
| SPRING_PROFILES_ACTIVE: test | |
| - name: 📦 Build JAR | |
| run: ./mvnw package -DskipTests -B | |
| - name: 📊 Upload test results | |
| uses: actions/upload-artifact@v4 | |
| if: always() | |
| with: | |
| name: backend-test-results | |
| path: target/surefire-reports/ | |
| # ══════════════════════════════════════════════════════════════════════════ | |
| # JOB 2 — Frontend Tests + Build | |
| # ══════════════════════════════════════════════════════════════════════════ | |
| frontend-build: | |
| name: ⚛️ Frontend — Lint & Build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: 📥 Checkout code | |
| uses: actions/checkout@v4 | |
| - name: 🟢 Set up Node.js 20 | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'npm' | |
| cache-dependency-path: frontend/package-lock.json | |
| - name: 📦 Install dependencies | |
| working-directory: frontend | |
| run: npm ci | |
| - name: 🔍 Lint | |
| working-directory: frontend | |
| run: npm run lint | |
| - name: 🏗️ Build | |
| working-directory: frontend | |
| run: npm run build | |
| # ══════════════════════════════════════════════════════════════════════════ | |
| # JOB 3 — Docker Build & Push (only on main branch push) | |
| # ══════════════════════════════════════════════════════════════════════════ | |
| docker-publish: | |
| name: 🐳 Docker Build & Push | |
| runs-on: ubuntu-latest | |
| needs: [backend-test, frontend-build] | |
| if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: 📥 Checkout code | |
| uses: actions/checkout@v4 | |
| - name: 🔐 Login to GitHub 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: 🐳 Build & Push Backend image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| push: true | |
| tags: | | |
| ${{ env.REGISTRY }}/${{ env.IMAGE_BACKEND }}:latest | |
| ${{ env.REGISTRY }}/${{ env.IMAGE_BACKEND }}:${{ github.sha }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: 🐳 Build & Push Frontend image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: ./frontend | |
| file: ./frontend/Dockerfile | |
| push: true | |
| tags: | | |
| ${{ env.REGISTRY }}/${{ env.IMAGE_FRONTEND }}:latest | |
| ${{ env.REGISTRY }}/${{ env.IMAGE_FRONTEND }}:${{ github.sha }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| # ══════════════════════════════════════════════════════════════════════════ | |
| # JOB 4 — Deploy to K8s (optional — needs KUBECONFIG secret) | |
| # ══════════════════════════════════════════════════════════════════════════ | |
| deploy: | |
| name: 🚀 Deploy to Kubernetes | |
| runs-on: ubuntu-latest | |
| needs: [docker-publish] | |
| if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
| environment: production # requires manual approval in GitHub | |
| steps: | |
| - name: 📥 Checkout code | |
| uses: actions/checkout@v4 | |
| - name: ⚙️ Set up kubectl | |
| uses: azure/setup-kubectl@v3 | |
| - name: 🔐 Configure kubeconfig | |
| run: | | |
| mkdir -p ~/.kube | |
| echo "${{ secrets.KUBECONFIG }}" > ~/.kube/config | |
| - name: 🔄 Update image tags in manifests | |
| run: | | |
| sed -i "s|YOUR_REGISTRY/taskmanager-backend:latest|${{ env.REGISTRY }}/${{ env.IMAGE_BACKEND }}:${{ github.sha }}|g" k8s/04-backend.yaml | |
| sed -i "s|YOUR_REGISTRY/taskmanager-frontend:latest|${{ env.REGISTRY }}/${{ env.IMAGE_FRONTEND }}:${{ github.sha }}|g" k8s/05-frontend.yaml | |
| - name: 🚀 Apply K8s manifests | |
| run: kubectl apply -f k8s/ --namespace=taskmanager | |
| - name: ⏳ Wait for rollout | |
| run: | | |
| kubectl rollout status deployment/backend --namespace=taskmanager --timeout=300s | |
| kubectl rollout status deployment/frontend --namespace=taskmanager --timeout=120s | |