From 53905cb9e2948aaee63ad567ba021c65c43486ce Mon Sep 17 00:00:00 2001 From: Alexis Bruneteau Date: Fri, 17 Oct 2025 00:59:18 +0200 Subject: [PATCH] ci(workflows): update Gitea CI/CD pipelines for Next.js 15 deployment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update both production and alpha deployment workflows: Changes: - Updated Node.js version from 22 to 20 (match project dependencies) - Changed build command from Angular 'npm run build --prod' to Next.js 'npm run build' - Added environment variables for API URLs (PROD_API_URL, ALPHA_API_URL) - Added NODE_ENV=production build argument for Docker - Improved Docker image tagging strategy (separate prod/alpha namespaces) - Enhanced kubeconfig validation with better error handling - Added deployment status messaging for better workflow visibility - Removed hardcoded config checking that exposed secrets - Added rollout status timeout (5m) for safer deployments - Improved step descriptions for clarity Benefits: - Workflow now properly builds Next.js standalone output - Better separation of prod and alpha deployments - Improved error reporting and troubleshooting - Safer kubeconfig handling (no secrets exposure) - More reliable deployment with timeout checks 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .gitea/workflows/deploy-alpha.yml | 51 +++++++++++++++++++------------ .gitea/workflows/deploy-prod.yml | 42 ++++++++++++++++--------- 2 files changed, 59 insertions(+), 34 deletions(-) diff --git a/.gitea/workflows/deploy-alpha.yml b/.gitea/workflows/deploy-alpha.yml index 67e10a8..45ff928 100644 --- a/.gitea/workflows/deploy-alpha.yml +++ b/.gitea/workflows/deploy-alpha.yml @@ -1,4 +1,4 @@ -name: Build and Deploy to k3s +name: Build and Deploy to k3s (Alpha) on: push: tags: @@ -16,27 +16,31 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v3 with: - node-version: '22' - + node-version: '20' - name: Install dependencies run: npm ci - - name: Build Angular app - run: npm run build --prod + - name: Build Next.js app + run: npm run build + env: + NEXT_PUBLIC_API_URL: ${{ secrets.ALPHA_API_URL }} - name: Build Docker image run: | - docker build -t ${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USER }}/hosting-frontend:${{ github.sha }} . - docker tag ${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USER }}/hosting-frontend:${{ github.sha }} ${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USER }}/hosting-frontend:latest + docker build \ + -t ${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USER }}/hosting-frontend-alpha:${{ github.sha }} \ + -t ${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USER }}/hosting-frontend-alpha:latest \ + --build-arg NODE_ENV=production \ + . - name: Login to Container Registry run: echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login ${{ secrets.REGISTRY_URL }} -u "${{ secrets.REGISTRY_USER }}" --password-stdin - - name: Push Docker image + - name: Push Docker images run: | - docker push ${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USER }}/hosting-frontend:${{ github.sha }} - docker push ${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USER }}/hosting-frontend:latest + docker push ${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USER }}/hosting-frontend-alpha:${{ github.sha }} + docker push ${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USER }}/hosting-frontend-alpha:latest - name: Setup kubectl uses: azure/setup-kubectl@v3 @@ -49,22 +53,29 @@ jobs: echo "${{ secrets.KUBE_CONFIG }}" | base64 -d > ~/.kube/config chmod 600 ~/.kube/config - - name: Check Config + - name: Validate kubeconfig and cluster connectivity run: | - cat ~/.kube/config - - - name: Validate kubeconfig - run: | - if ! kubectl version --client && kubectl cluster-info --kubeconfig ~/.kube/config; then + if ! kubectl version --client; then + echo "❌ Failed to get kubectl version" + exit 1 + fi + if ! kubectl cluster-info --kubeconfig ~/.kube/config > /dev/null 2>&1; then echo "❌ Failed to connect to cluster" exit 1 fi + echo "✅ Successfully connected to Kubernetes cluster" - - - name: Deploy to k3s + - name: Deploy to Alpha (k3s) run: | + echo "Applying Kubernetes manifests..." kubectl apply -k deploy/k3s/alpha --kubeconfig ~/.kube/config + + echo "Updating deployment image..." kubectl set image deployment/hosting-frontend \ - hosting-frontend=${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USER }}/hosting-frontend:${{ github.sha }} \ + hosting-frontend=${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USER }}/hosting-frontend-alpha:${{ github.sha }} \ -n hosting-alpha --kubeconfig ~/.kube/config - kubectl rollout status deployment/hosting-frontend -n hosting-alpha --kubeconfig ~/.kube/config + + echo "Waiting for rollout to complete..." + kubectl rollout status deployment/hosting-frontend -n hosting-alpha --kubeconfig ~/.kube/config --timeout=5m + + echo "✅ Alpha deployment complete!" diff --git a/.gitea/workflows/deploy-prod.yml b/.gitea/workflows/deploy-prod.yml index daa7090..a4680d2 100644 --- a/.gitea/workflows/deploy-prod.yml +++ b/.gitea/workflows/deploy-prod.yml @@ -1,4 +1,4 @@ -name: Build and Deploy to k3s +name: Build and Deploy to k3s (Production) on: push: tags: @@ -16,24 +16,28 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v3 with: - node-version: '22' - + node-version: '20' - name: Install dependencies run: npm ci - - name: Build Angular app - run: npm run build --prod + - name: Build Next.js app + run: npm run build + env: + NEXT_PUBLIC_API_URL: ${{ secrets.PROD_API_URL }} - name: Build Docker image run: | - docker build -t ${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USER }}/hosting-frontend-prod:${{ github.sha }} . - docker tag ${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USER }}/hosting-frontend-prod:${{ github.sha }} ${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USER }}/hosting-frontend-prod:latest + docker build \ + -t ${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USER }}/hosting-frontend-prod:${{ github.sha }} \ + -t ${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USER }}/hosting-frontend-prod:latest \ + --build-arg NODE_ENV=production \ + . - name: Login to Container Registry run: echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login ${{ secrets.REGISTRY_URL }} -u "${{ secrets.REGISTRY_USER }}" --password-stdin - - name: Push Docker image + - name: Push Docker images run: | docker push ${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USER }}/hosting-frontend-prod:${{ github.sha }} docker push ${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USER }}/hosting-frontend-prod:latest @@ -49,19 +53,29 @@ jobs: echo "${{ secrets.KUBE_CONFIG }}" | base64 -d > ~/.kube/config chmod 600 ~/.kube/config - - - name: Validate kubeconfig + - name: Validate kubeconfig and cluster connectivity run: | - if ! kubectl version --client && kubectl cluster-info --kubeconfig ~/.kube/config; then + if ! kubectl version --client; then + echo "❌ Failed to get kubectl version" + exit 1 + fi + if ! kubectl cluster-info --kubeconfig ~/.kube/config > /dev/null 2>&1; then echo "❌ Failed to connect to cluster" exit 1 fi + echo "✅ Successfully connected to Kubernetes cluster" - - - name: Deploy to k3s + - name: Deploy to Production (k3s) run: | + echo "Applying Kubernetes manifests..." kubectl apply -k deploy/k3s/prod --kubeconfig ~/.kube/config + + echo "Updating deployment image..." kubectl set image deployment/hosting-frontend \ hosting-frontend=${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USER }}/hosting-frontend-prod:${{ github.sha }} \ -n hosting --kubeconfig ~/.kube/config - kubectl rollout status deployment/hosting-frontend -n hosting --kubeconfig ~/.kube/config + + echo "Waiting for rollout to complete..." + kubectl rollout status deployment/hosting-frontend -n hosting --kubeconfig ~/.kube/config --timeout=5m + + echo "✅ Production deployment complete!"