ci(workflows): update Gitea CI/CD pipelines for Next.js 15 deployment
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 <noreply@anthropic.com>
This commit is contained in:
parent
2d07eeba10
commit
53905cb9e2
@ -1,4 +1,4 @@
|
|||||||
name: Build and Deploy to k3s
|
name: Build and Deploy to k3s (Alpha)
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
tags:
|
tags:
|
||||||
@ -16,27 +16,31 @@ jobs:
|
|||||||
- name: Setup Node.js
|
- name: Setup Node.js
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: '22'
|
node-version: '20'
|
||||||
|
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: npm ci
|
run: npm ci
|
||||||
|
|
||||||
- name: Build Angular app
|
- name: Build Next.js app
|
||||||
run: npm run build --prod
|
run: npm run build
|
||||||
|
env:
|
||||||
|
NEXT_PUBLIC_API_URL: ${{ secrets.ALPHA_API_URL }}
|
||||||
|
|
||||||
- name: Build Docker image
|
- name: Build Docker image
|
||||||
run: |
|
run: |
|
||||||
docker build -t ${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USER }}/hosting-frontend:${{ github.sha }} .
|
docker build \
|
||||||
docker tag ${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USER }}/hosting-frontend:${{ github.sha }} ${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USER }}/hosting-frontend:latest
|
-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
|
- name: Login to Container Registry
|
||||||
run: echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login ${{ secrets.REGISTRY_URL }} -u "${{ secrets.REGISTRY_USER }}" --password-stdin
|
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: |
|
run: |
|
||||||
docker push ${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USER }}/hosting-frontend:${{ github.sha }}
|
docker push ${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USER }}/hosting-frontend-alpha:${{ github.sha }}
|
||||||
docker push ${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USER }}/hosting-frontend:latest
|
docker push ${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USER }}/hosting-frontend-alpha:latest
|
||||||
|
|
||||||
- name: Setup kubectl
|
- name: Setup kubectl
|
||||||
uses: azure/setup-kubectl@v3
|
uses: azure/setup-kubectl@v3
|
||||||
@ -49,22 +53,29 @@ jobs:
|
|||||||
echo "${{ secrets.KUBE_CONFIG }}" | base64 -d > ~/.kube/config
|
echo "${{ secrets.KUBE_CONFIG }}" | base64 -d > ~/.kube/config
|
||||||
chmod 600 ~/.kube/config
|
chmod 600 ~/.kube/config
|
||||||
|
|
||||||
- name: Check Config
|
- name: Validate kubeconfig and cluster connectivity
|
||||||
run: |
|
run: |
|
||||||
cat ~/.kube/config
|
if ! kubectl version --client; then
|
||||||
|
echo "❌ Failed to get kubectl version"
|
||||||
- name: Validate kubeconfig
|
exit 1
|
||||||
run: |
|
fi
|
||||||
if ! kubectl version --client && kubectl cluster-info --kubeconfig ~/.kube/config; then
|
if ! kubectl cluster-info --kubeconfig ~/.kube/config > /dev/null 2>&1; then
|
||||||
echo "❌ Failed to connect to cluster"
|
echo "❌ Failed to connect to cluster"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
echo "✅ Successfully connected to Kubernetes cluster"
|
||||||
|
|
||||||
|
- name: Deploy to Alpha (k3s)
|
||||||
- name: Deploy to k3s
|
|
||||||
run: |
|
run: |
|
||||||
|
echo "Applying Kubernetes manifests..."
|
||||||
kubectl apply -k deploy/k3s/alpha --kubeconfig ~/.kube/config
|
kubectl apply -k deploy/k3s/alpha --kubeconfig ~/.kube/config
|
||||||
|
|
||||||
|
echo "Updating deployment image..."
|
||||||
kubectl set image deployment/hosting-frontend \
|
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
|
-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!"
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
name: Build and Deploy to k3s
|
name: Build and Deploy to k3s (Production)
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
tags:
|
tags:
|
||||||
@ -16,24 +16,28 @@ jobs:
|
|||||||
- name: Setup Node.js
|
- name: Setup Node.js
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: '22'
|
node-version: '20'
|
||||||
|
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: npm ci
|
run: npm ci
|
||||||
|
|
||||||
- name: Build Angular app
|
- name: Build Next.js app
|
||||||
run: npm run build --prod
|
run: npm run build
|
||||||
|
env:
|
||||||
|
NEXT_PUBLIC_API_URL: ${{ secrets.PROD_API_URL }}
|
||||||
|
|
||||||
- name: Build Docker image
|
- name: Build Docker image
|
||||||
run: |
|
run: |
|
||||||
docker build -t ${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USER }}/hosting-frontend-prod:${{ github.sha }} .
|
docker build \
|
||||||
docker tag ${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USER }}/hosting-frontend-prod:${{ github.sha }} ${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USER }}/hosting-frontend-prod:latest
|
-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
|
- name: Login to Container Registry
|
||||||
run: echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login ${{ secrets.REGISTRY_URL }} -u "${{ secrets.REGISTRY_USER }}" --password-stdin
|
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: |
|
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:${{ github.sha }}
|
||||||
docker push ${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USER }}/hosting-frontend-prod:latest
|
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
|
echo "${{ secrets.KUBE_CONFIG }}" | base64 -d > ~/.kube/config
|
||||||
chmod 600 ~/.kube/config
|
chmod 600 ~/.kube/config
|
||||||
|
|
||||||
|
- name: Validate kubeconfig and cluster connectivity
|
||||||
- name: Validate kubeconfig
|
|
||||||
run: |
|
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"
|
echo "❌ Failed to connect to cluster"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
echo "✅ Successfully connected to Kubernetes cluster"
|
||||||
|
|
||||||
|
- name: Deploy to Production (k3s)
|
||||||
- name: Deploy to k3s
|
|
||||||
run: |
|
run: |
|
||||||
|
echo "Applying Kubernetes manifests..."
|
||||||
kubectl apply -k deploy/k3s/prod --kubeconfig ~/.kube/config
|
kubectl apply -k deploy/k3s/prod --kubeconfig ~/.kube/config
|
||||||
|
|
||||||
|
echo "Updating deployment image..."
|
||||||
kubectl set image deployment/hosting-frontend \
|
kubectl set image deployment/hosting-frontend \
|
||||||
hosting-frontend=${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USER }}/hosting-frontend-prod:${{ github.sha }} \
|
hosting-frontend=${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USER }}/hosting-frontend-prod:${{ github.sha }} \
|
||||||
-n hosting --kubeconfig ~/.kube/config
|
-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!"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user