Condense README.md #6
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: Build and Deploy to Kubernetes | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: # Allows manual trigger from GitHub UI | |
| env: | |
| DOCKER_IMAGE: dguailab/ailab-frontend | |
| DOCKER_TAG: latest | |
| K8S_NAMESPACE: ailab-frontend | |
| DEPLOYMENT_NAME: ailab-frontend | |
| jobs: | |
| build-and-deploy: | |
| runs-on: self-hosted | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| push: true | |
| tags: ${{ env.DOCKER_IMAGE }}:${{ env.DOCKER_TAG }},${{ env.DOCKER_IMAGE }}:${{ github.sha }} | |
| cache-from: type=registry,ref=${{ env.DOCKER_IMAGE }}:buildcache | |
| cache-to: type=registry,ref=${{ env.DOCKER_IMAGE }}:buildcache,mode=max | |
| - name: Set up kubectl | |
| uses: azure/setup-kubectl@v4 | |
| with: | |
| version: 'latest' | |
| - name: Verify kubectl connection | |
| run: | | |
| kubectl cluster-info | |
| kubectl get nodes | |
| - name: Deploy to Kubernetes | |
| run: | | |
| # Apply all Kubernetes manifests | |
| kubectl apply -f k8s/namespace.yaml | |
| kubectl apply -f k8s/deployment.yaml | |
| kubectl apply -f k8s/service.yaml | |
| kubectl apply -f k8s/ingress.yaml | |
| # Restart deployment to pull new image | |
| kubectl rollout restart deployment/${{ env.DEPLOYMENT_NAME }} -n ${{ env.K8S_NAMESPACE }} | |
| # Wait for rollout to complete | |
| kubectl rollout status deployment/${{ env.DEPLOYMENT_NAME }} -n ${{ env.K8S_NAMESPACE }} --timeout=5m | |
| - name: Verify deployment | |
| run: | | |
| echo "=== Pods Status ===" | |
| kubectl get pods -n ${{ env.K8S_NAMESPACE }} | |
| echo "=== Service Status ===" | |
| kubectl get svc -n ${{ env.K8S_NAMESPACE }} | |
| echo "=== Ingress Status ===" | |
| kubectl get ingress -n ${{ env.K8S_NAMESPACE }} | |
| - name: Get deployment logs (on failure) | |
| if: failure() | |
| run: | | |
| echo "=== Recent Pod Logs ===" | |
| kubectl logs -n ${{ env.K8S_NAMESPACE }} -l app=ailab-frontend --tail=100 | |
| echo "=== Pod Events ===" | |
| kubectl get events -n ${{ env.K8S_NAMESPACE }} --sort-by='.lastTimestamp' |