99env :
1010 REGISTRY : crretoxmas2024.azurecr.io
1111 NAMESPACE : reto-xmas-2025-goland-ia-backend
12- ROLLOUT_TIMEOUT : 300
13- READY_CHECK_INTERVAL : 10
12+ ROLLOUT_TIMEOUT : 60s
13+ READY_CHECK_RETRIES : 20
14+ READY_CHECK_SLEEP : 15
1415
1516jobs :
1617 build-and-deploy :
1718 runs-on : ubuntu-latest
18- timeout-minutes : 20
19+ timeout-minutes : 15
1920 strategy :
2021 fail-fast : false
2122 matrix :
@@ -30,130 +31,153 @@ jobs:
3031 deployment : rag-manager
3132
3233 steps :
33- - name : Checkout code
34- uses : actions/checkout@v4
35-
36- - name : Set up Docker Buildx
37- uses : docker/setup-buildx-action@v3
38-
39- - name : Login to ACR
40- uses : docker/login-action@v3
41- with :
42- registry : ${{ env.REGISTRY }}
43- username : ${{ secrets.ACR_USERNAME }}
44- password : ${{ secrets.ACR_PASSWORD }}
45-
46- - name : Build and push Docker image
47- uses : docker/build-push-action@v5
48- with :
49- context : ${{ matrix.service.path }}
50- platforms : linux/amd64
51- push : true
52- tags : |
53- ${{ env.REGISTRY }}/${{ matrix.service.image }}:latest
54- ${{ env.REGISTRY }}/${{ matrix.service.image }}:${{ github.sha }}
55- cache-from : type=registry,ref=${{ env.REGISTRY }}/${{ matrix.service.image }}:buildcache
56- cache-to : type=registry,ref=${{ env.REGISTRY }}/${{ matrix.service.image }}:buildcache,mode=max
57- provenance : false
58-
59- - name : Set up kubectl
60- uses : azure/setup-kubectl@v3
61- with :
62- version : ' latest'
63-
64- - name : Configure kubectl
65- run : |
66- mkdir -p $HOME/.kube
67- echo "${{ secrets.KUBECONFIG }}" | base64 -d > $HOME/.kube/config
68- chmod 600 $HOME/.kube/config
69-
70- - name : Update deployment image
71- run : |
72- kubectl set image deployment/${{ matrix.service.deployment }} \
73- api=${{ env.REGISTRY }}/${{ matrix.service.image }}:${{ github.sha }} \
74- -n ${{ env.NAMESPACE }}
75-
76- - name : Wait for deployment to be ready (robust)
77- run : |
78- echo "Waiting for deployment ${matrix.service.deployment} to be ready..."
79- END=$((SECONDS+ROLLOUT_TIMEOUT))
80-
81- while [ $SECONDS -lt $END ]; do
82- DESIRED=$(kubectl get deployment/${{ matrix.service.deployment }} -n ${{ env.NAMESPACE }} -o jsonpath='{.spec.replicas}')
83- AVAILABLE=$(kubectl get deployment/${{ matrix.service.deployment }} -n ${{ env.NAMESPACE }} -o jsonpath='{.status.availableReplicas}')
84- AVAILABLE=${AVAILABLE:-0}
85-
86- echo "Available replicas: $AVAILABLE / $DESIRED"
87-
88- if [ "$AVAILABLE" = "$DESIRED" ]; then
89- echo "Deployment is ready!"
90- exit 0
91- fi
92-
93- sleep $READY_CHECK_INTERVAL
94- done
95-
96- echo "Deployment did not become ready in time"
97- kubectl describe deployment/${{ matrix.service.deployment }} -n ${{ env.NAMESPACE }}
98- kubectl get pods -n ${{ env.NAMESPACE }} -o wide
99- exit 1
100-
101- - name : Get logs on failure
102- if : failure()
103- run : |
104- echo "=== Deployment ==="
105- kubectl describe deployment/${{ matrix.service.deployment }} -n ${{ env.NAMESPACE }}
106-
107- echo "=== Pods ==="
108- kubectl get pods -n ${{ env.NAMESPACE }} -l app=${{ matrix.service.deployment }} -o wide
109-
110- echo "=== Pod Logs ==="
111- kubectl logs -n ${{ env.NAMESPACE }} \
112- -l app=${{ matrix.service.deployment }} \
113- --tail=100 \
114- --all-containers=true \
115- --prefix=true || true
116-
117- - name : Deployment Summary
118- if : always()
119- run : |
120- STATUS="${{ job.status }}"
121-
122- echo "### Deployment - ${{ matrix.service.name }}" >> $GITHUB_STEP_SUMMARY
123- echo "" >> $GITHUB_STEP_SUMMARY
124- echo "| Property | Value |" >> $GITHUB_STEP_SUMMARY
125- echo "|----------|-------|" >> $GITHUB_STEP_SUMMARY
126- echo "| Image | \`${{ env.REGISTRY }}/${{ matrix.service.image }}:${{ github.sha }}\` |" >> $GITHUB_STEP_SUMMARY
127- echo "| Status | $STATUS |" >> $GITHUB_STEP_SUMMARY
128- echo "" >> $GITHUB_STEP_SUMMARY
129-
130- echo "#### Pods:" >> $GITHUB_STEP_SUMMARY
131- echo '```' >> $GITHUB_STEP_SUMMARY
132- kubectl get pods -n ${{ env.NAMESPACE }} -l app=${{ matrix.service.deployment }} >> $GITHUB_STEP_SUMMARY || true
133- echo '```' >> $GITHUB_STEP_SUMMARY
34+ - name : Checkout code
35+ uses : actions/checkout@v4
36+
37+ - name : Set up Docker Buildx
38+ uses : docker/setup-buildx-action@v3
39+
40+ - name : Login to ACR
41+ uses : docker/login-action@v3
42+ with :
43+ registry : ${{ env.REGISTRY }}
44+ username : ${{ secrets.ACR_USERNAME }}
45+ password : ${{ secrets.ACR_PASSWORD }}
46+
47+ - name : Build and push Docker image
48+ uses : docker/build-push-action@v5
49+ with :
50+ context : ${{ matrix.service.path }}
51+ platforms : linux/amd64
52+ push : true
53+ tags : |
54+ ${{ env.REGISTRY }}/${{ matrix.service.image }}:latest
55+ ${{ env.REGISTRY }}/${{ matrix.service.image }}:${{ github.sha }}
56+ cache-from : type=registry,ref=${{ env.REGISTRY }}/${{ matrix.service.image }}:buildcache
57+ cache-to : type=registry,ref=${{ env.REGISTRY }}/${{ matrix.service.image }}:buildcache,mode=max
58+ provenance : false
59+
60+ - name : Set up kubectl
61+ uses : azure/setup-kubectl@v3
62+ with :
63+ version : ' latest'
64+
65+ - name : Configure kubectl
66+ run : |
67+ mkdir -p $HOME/.kube
68+ echo "${{ secrets.KUBECONFIG }}" | base64 -d > $HOME/.kube/config
69+ chmod 600 $HOME/.kube/config
70+
71+ - name : Update deployment image
72+ run : |
73+ kubectl set image deployment/${{ matrix.service.deployment }} \
74+ api=${{ env.REGISTRY }}/${{ matrix.service.image }}:${{ github.sha }} \
75+ -n ${{ env.NAMESPACE }}
76+
77+ - name : Wait for deployment to be ready (robust)
78+ run : |
79+ set -e
80+
81+ echo "Checking rollout status (non-blocking)..."
82+ kubectl rollout status deployment/${{ matrix.service.deployment }} \
83+ -n ${{ env.NAMESPACE }} \
84+ --timeout=${{ env.ROLLOUT_TIMEOUT }} || true
85+
86+ echo "Waiting for available replicas..."
87+
88+ for i in $(seq 1 $READY_CHECK_RETRIES); do
89+ DESIRED=$(kubectl get deployment/${{ matrix.service.deployment }} -n ${{ env.NAMESPACE }} -o jsonpath='{.spec.replicas}')
90+ AVAILABLE=$(kubectl get deployment/${{ matrix.service.deployment }} -n ${{ env.NAMESPACE }} -o jsonpath='{.status.availableReplicas}')
91+
92+ echo "Attempt $i: $AVAILABLE / $DESIRED replicas available"
93+
94+ if [ "$AVAILABLE" = "$DESIRED" ]; then
95+ echo "Deployment is ready"
96+ exit 0
97+ fi
98+
99+ sleep $READY_CHECK_SLEEP
100+ done
101+
102+ echo "Deployment did not become ready in time"
103+ kubectl describe deployment/${{ matrix.service.deployment }} -n ${{ env.NAMESPACE }}
104+ exit 1
105+
106+ - name : Verify pods
107+ if : success()
108+ run : |
109+ kubectl get pods -n ${{ env.NAMESPACE }} -l app=${{ matrix.service.deployment }} -o wide
110+
111+ - name : Get logs on failure
112+ if : failure()
113+ run : |
114+ echo "=== Deployment ==="
115+ kubectl describe deployment/${{ matrix.service.deployment }} -n ${{ env.NAMESPACE }}
116+
117+ echo "=== Pods ==="
118+ kubectl get pods -n ${{ env.NAMESPACE }} -l app=${{ matrix.service.deployment }} -o wide
119+
120+ echo "=== Pod Logs ==="
121+ kubectl logs -n ${{ env.NAMESPACE }} \
122+ -l app=${{ matrix.service.deployment }} \
123+ --tail=100 \
124+ --all-containers=true \
125+ --prefix=true || true
126+
127+ - name : Deployment Summary
128+ if : always()
129+ run : |
130+ STATUS="${{ job.status }}"
131+
132+ echo "### Deployment - ${{ matrix.service.name }}" >> $GITHUB_STEP_SUMMARY
133+ echo "" >> $GITHUB_STEP_SUMMARY
134+ echo "| Property | Value |" >> $GITHUB_STEP_SUMMARY
135+ echo "|----------|-------|" >> $GITHUB_STEP_SUMMARY
136+ echo "| Image | \`${{ env.REGISTRY }}/${{ matrix.service.image }}:${{ github.sha }}\` |" >> $GITHUB_STEP_SUMMARY
137+ echo "| Status | $STATUS |" >> $GITHUB_STEP_SUMMARY
138+ echo "" >> $GITHUB_STEP_SUMMARY
139+
140+ echo "#### Pods:" >> $GITHUB_STEP_SUMMARY
141+ echo '```' >> $GITHUB_STEP_SUMMARY
142+ kubectl get pods -n ${{ env.NAMESPACE }} -l app=${{ matrix.service.deployment }} >> $GITHUB_STEP_SUMMARY || true
143+ echo '```' >> $GITHUB_STEP_SUMMARY
134144
135145 notify-success :
136146 name : Deployment Success
137147 runs-on : ubuntu-latest
138148 needs : [build-and-deploy]
139149 if : success()
140150 steps :
141- - name : Notify Discord
142- run : |
143- curl -H "Content-Type: application/json" \
144- -X POST \
145- -d "{\"content\": \"✅ **Deploy exitoso**\\n\\n**Repositorio:** ${{ github.repository }}\\n**Commit:** [${{ github.sha }}](${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }})\\n**Autor:** ${{ github.actor }}\\n\\n[Ver ejecución en GitHub Actions](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})\\n\\n🚀 Todos los servicios quedaron desplegados correctamente.\"}" \
146- ${{ secrets.DISCORD_WEBHOOK }}
151+ - name : Success Summary
152+ run : |
153+ echo "### All Services Deployed" >> $GITHUB_STEP_SUMMARY
154+ echo "" >> $GITHUB_STEP_SUMMARY
155+ echo "**Live URLs:**" >> $GITHUB_STEP_SUMMARY
156+ echo "- [DocsManager](https://goland-ia-backend-docs-manager.reto-ucu.net/docs)" >> $GITHUB_STEP_SUMMARY
157+ echo "- [RAGManager](https://goland-ia-backend-rag-manager.reto-ucu.net/docs)" >> $GITHUB_STEP_SUMMARY
158+
159+ - name : Notificar a Discord (deploy exitoso)
160+ run : |
161+ curl -H "Content-Type: application/json" \
162+ -X POST \
163+ -d "{\"content\": \"✅ **Deploy exitoso**\\n\\n**Servicio:** \\\\`${{ matrix.service.name }}\\\\`\\n**Imagen:** \\\\`${{ env.REGISTRY }}/${{ matrix.service.image }}:${{ github.sha }}\\\\`\\n**Namespace:** \\\\`${{ env.NAMESPACE }}\\\\`\\n**Autor:** ${{ github.actor }}\\n**Commit:** [${{ github.sha }}](${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }})\\n\\n[Ver ejecución en GitHub Actions](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})\\n\\n:rocket: ¡Todo salió bien!\"}" \
164+ https://discord.com/api/webhooks/1449147972330852463/sMs3QYOvQ6oiaPHR4PlBluwNrhWSsVmfm3_Miz6UAFrPxj1SsbqNnHXc5eK9h8ZSaumk
147165
148166 notify-failure :
149167 name : Deployment Failed
150168 runs-on : ubuntu-latest
151169 needs : [build-and-deploy]
152170 if : failure()
153171 steps :
154- - name : Notify Discord
155- run : |
156- curl -H "Content-Type: application/json" \
157- -X POST \
158- -d "{\"content\": \"❌ **Falló el deploy**\\n\\n**Repositorio:** ${{ github.repository }}\\n**Commit:** [${{ github.sha }}](${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }})\\n**Autor:** ${{ github.actor }}\\n\\n[Ver ejecución en GitHub Actions](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})\\n\\n⚠️ Al menos un servicio no pudo desplegarse. Revisar logs.\"}" \
159- ${{ secrets.DISCORD_WEBHOOK }}
172+ - name : Failure Summary
173+ run : |
174+ echo "### Deployment Failed" >> $GITHUB_STEP_SUMMARY
175+ echo "" >> $GITHUB_STEP_SUMMARY
176+ echo "Please check deployment logs above." >> $GITHUB_STEP_SUMMARY
177+
178+ - name : Notificar a Discord (deploy fallido)
179+ run : |
180+ curl -H "Content-Type: application/json" \
181+ -X POST \
182+ -d "{\"content\": \"❌ **Falló el deploy**\\n\\n**Servicio:** \\\\`${{ matrix.service.name }}\\\\`\\n**Imagen:** \\\\`${{ env.REGISTRY }}/${{ matrix.service.image }}:${{ github.sha }}\\\\`\\n**Namespace:** \\\\`${{ env.NAMESPACE }}\\\\`\\n**Autor:** ${{ github.actor }}\\n**Commit:** [${{ github.sha }}](${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }})\\n\\n[Ver ejecución en GitHub Actions](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})\\n\\n:warning: Revisa los logs para más detalles.\"}" \
183+ https://discord.com/api/webhooks/1449147972330852463/sMs3QYOvQ6oiaPHR4PlBluwNrhWSsVmfm3_Miz6UAFrPxj1SsbqNnHXc5eK9h8ZSaumk
0 commit comments