Skip to content

Commit a1e48e0

Browse files
Enhances deployment workflow with rollback
Improves the deployment process by adding rollback capabilities on failure, enhanced logging, and deployment summaries in GitHub. The changes also include updating the deployment strategy from rolling restarts to image updates. It adds timeout configurations for deployments. Also adds live URL information to success summary.
1 parent 1302887 commit a1e48e0

File tree

3 files changed

+77
-42
lines changed

3 files changed

+77
-42
lines changed

.github/workflows/deploy.yml

Lines changed: 66 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ on:
99
env:
1010
REGISTRY: crretoxmas2024.azurecr.io
1111
NAMESPACE: reto-xmas-2025-goland-ia-backend
12+
DEPLOY_TIMEOUT: 3m
1213

1314
jobs:
1415
build-and-deploy:
1516
runs-on: ubuntu-latest
17+
timeout-minutes: 15
1618
strategy:
1719
fail-fast: false
1820
matrix:
@@ -51,6 +53,7 @@ jobs:
5153
${{ env.REGISTRY }}/${{ matrix.service.image }}:${{ github.sha }}
5254
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ matrix.service.image }}:buildcache
5355
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ matrix.service.image }}:buildcache,mode=max
56+
provenance: false
5457

5558
- name: Set up kubectl
5659
uses: azure/setup-kubectl@v3
@@ -63,28 +66,66 @@ jobs:
6366
echo "${{ secrets.KUBECONFIG }}" | base64 -d > $HOME/.kube/config
6467
chmod 600 $HOME/.kube/config
6568
66-
- name: Restart deployment
69+
- name: Update deployment image
6770
run: |
68-
kubectl rollout restart deployment/${{ matrix.service.deployment }} -n ${{ env.NAMESPACE }}
69-
kubectl rollout status deployment/${{ matrix.service.deployment }} -n ${{ env.NAMESPACE }} --timeout=5m
71+
kubectl set image deployment/${{ matrix.service.deployment }} \
72+
api=${{ env.REGISTRY }}/${{ matrix.service.image }}:${{ github.sha }} \
73+
-n ${{ env.NAMESPACE }}
74+
75+
- name: Wait for rollout
76+
timeout-minutes: 5
77+
run: |
78+
kubectl rollout status deployment/${{ matrix.service.deployment }} \
79+
-n ${{ env.NAMESPACE }} \
80+
--timeout=${{ env.DEPLOY_TIMEOUT }} || {
81+
echo "Deployment failed or timed out"
82+
kubectl get pods -n ${{ env.NAMESPACE }} -l app=${{ matrix.service.deployment }}
83+
exit 1
84+
}
7085
7186
- name: Verify deployment
87+
if: success()
7288
run: |
73-
echo "Deployment successful for ${{ matrix.service.name }}"
89+
echo "Deployment successful for ${{ matrix.service.name }}"
7490
kubectl get pods -n ${{ env.NAMESPACE }} -l app=${{ matrix.service.deployment }}
7591
92+
- name: Get logs on failure
93+
if: failure()
94+
run: |
95+
echo "=== Pod Logs ==="
96+
kubectl logs -n ${{ env.NAMESPACE }} \
97+
-l app=${{ matrix.service.deployment }} \
98+
--tail=100 \
99+
--all-containers=true \
100+
--prefix=true || echo "Could not fetch logs"
101+
102+
- name: Rollback on failure
103+
if: failure()
104+
run: |
105+
echo "Rolling back deployment"
106+
kubectl rollout undo deployment/${{ matrix.service.deployment }} -n ${{ env.NAMESPACE }}
107+
76108
- name: Deployment Summary
77109
if: always()
78110
run: |
79-
echo "### 🚀 Deployment Summary" >> $GITHUB_STEP_SUMMARY
111+
STATUS="${{ job.status }}"
112+
113+
echo "### Deployment - ${{ matrix.service.name }}" >> $GITHUB_STEP_SUMMARY
80114
echo "" >> $GITHUB_STEP_SUMMARY
81-
echo "**Service:** ${{ matrix.service.name }}" >> $GITHUB_STEP_SUMMARY
82-
echo "**Image:** ${{ env.REGISTRY }}/${{ matrix.service.image }}:${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
83-
echo "**Status:** ${{ job.status }}" >> $GITHUB_STEP_SUMMARY
115+
echo "| Property | Value |" >> $GITHUB_STEP_SUMMARY
116+
echo "|----------|-------|" >> $GITHUB_STEP_SUMMARY
117+
echo "| Image | \`${{ env.REGISTRY }}/${{ matrix.service.image }}:${{ github.sha }}\` |" >> $GITHUB_STEP_SUMMARY
118+
119+
if [ "$STATUS" == "success" ]; then
120+
echo "| Status | Success |" >> $GITHUB_STEP_SUMMARY
121+
else
122+
echo "| Status | Failed |" >> $GITHUB_STEP_SUMMARY
123+
fi
124+
84125
echo "" >> $GITHUB_STEP_SUMMARY
85126
echo "#### Pods:" >> $GITHUB_STEP_SUMMARY
86127
echo '```' >> $GITHUB_STEP_SUMMARY
87-
kubectl get pods -n ${{ env.NAMESPACE }} -l app=${{ matrix.service.deployment }} >> $GITHUB_STEP_SUMMARY
128+
kubectl get pods -n ${{ env.NAMESPACE }} -l app=${{ matrix.service.deployment }} >> $GITHUB_STEP_SUMMARY || true
88129
echo '```' >> $GITHUB_STEP_SUMMARY
89130
90131
notify-success:
@@ -95,8 +136,20 @@ jobs:
95136
steps:
96137
- name: Success Summary
97138
run: |
98-
echo "### ✅ Deployment Successful!" >> $GITHUB_STEP_SUMMARY
139+
echo "### ll Services Deployed!" >> $GITHUB_STEP_SUMMARY
140+
echo "" >> $GITHUB_STEP_SUMMARY
141+
echo "**Live URLs:**" >> $GITHUB_STEP_SUMMARY
142+
echo "- [DocsManager](https://goland-ia-backend-docs-manager.reto-ucu.net/docs)" >> $GITHUB_STEP_SUMMARY
143+
echo "- [RAGManager](https://goland-ia-backend-rag-manager.reto-ucu.net/docs)" >> $GITHUB_STEP_SUMMARY
144+
145+
notify-failure:
146+
name: Deployment Failed
147+
runs-on: ubuntu-latest
148+
needs: [build-and-deploy]
149+
if: failure()
150+
steps:
151+
- name: Failure Summary
152+
run: |
153+
echo "### Deployment Failed" >> $GITHUB_STEP_SUMMARY
99154
echo "" >> $GITHUB_STEP_SUMMARY
100-
echo "All services deployed successfully:" >> $GITHUB_STEP_SUMMARY
101-
echo "- 🌐 DocsManager: https://goland-ia-backend-docs-manager.reto-ucu.net" >> $GITHUB_STEP_SUMMARY
102-
echo "- 🌐 RAGManager: https://goland-ia-backend-rag-manager.reto-ucu.net" >> $GITHUB_STEP_SUMMARY
155+
echo "Automatic rollback initiated" >> $GITHUB_STEP_SUMMARY

DocsManager/pyproject.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ name = "goland-ia"
33
version = "0.1.0"
44
description = "Add your description here"
55
readme = "README.md"
6-
requires-python = ">=3.14"
6+
requires-python = ">=3.13"
77
dependencies = [
88
"fastapi>=0.124.2",
9-
"ipython>=9.8.0",
9+
"sqlalchemy>=2.0.35",
10+
"asyncpg>=0.29.0",
11+
"psycopg2-binary>=2.9.9",
1012
"langgraph>=1.0.4",
1113
"typing-extensions>=4.15.0",
1214
"uvicorn>=0.38.0",
@@ -23,7 +25,7 @@ dev = [
2325

2426
[tool.ruff]
2527
# Enable pyproject.toml support
26-
target-version = "py314"
28+
target-version = "py313"
2729
line-length = 120
2830

2931
# Enable auto-fix

RAGManager/pyproject.toml

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
[project]
2-
name = "goland-ia"
2+
name = "rag-manager"
33
version = "0.1.0"
4-
description = "Add your description here"
4+
description = "RAG Manager for document processing"
55
readme = "README.md"
6-
requires-python = ">=3.14"
6+
requires-python = ">=3.12,<3.14"
77
dependencies = [
8-
"fastapi>=0.124.2",
8+
"fastapi>=0.124.2",
99
"ipython>=9.8.0",
1010
"langgraph>=1.0.4",
1111
"langchain-core>=0.3.0",
@@ -15,8 +15,6 @@ dependencies = [
1515
"psycopg2-binary>=2.9.0",
1616
"pgvector>=0.3.0",
1717
"pydantic-settings>=2.0.0",
18-
"typing-extensions>=4.15.0",
19-
"uvicorn>=0.38.0",
2018
"guardrails-ai>=0.5.10",
2119
]
2220

@@ -26,14 +24,9 @@ dev = [
2624
]
2725

2826
[tool.ruff]
29-
# Enable pyproject.toml support
30-
target-version = "py314"
27+
target-version = "py312"
3128
line-length = 120
32-
33-
# Enable auto-fix
3429
fix = true
35-
36-
# Exclude directories
3730
exclude = [
3831
".git",
3932
".venv",
@@ -45,7 +38,6 @@ exclude = [
4538
]
4639

4740
[tool.ruff.lint]
48-
# Enable a comprehensive set of rules
4941
select = [
5042
"E", # pycodestyle errors
5143
"W", # pycodestyle warnings
@@ -57,27 +49,15 @@ select = [
5749
"C4", # flake8-comprehensions
5850
"SIM", # flake8-simplify
5951
]
60-
6152
ignore = [
62-
"E501", # Line too long (handled by formatter)
53+
"E501", # Line too long
6354
]
64-
65-
# Allow autofix for all enabled rules
6655
fixable = ["ALL"]
6756
unfixable = []
68-
69-
# Allow unused variables when underscore-prefixed
7057
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
7158

7259
[tool.ruff.format]
73-
# Use double quotes for strings (like Black)
7460
quote-style = "double"
75-
76-
# Indent with spaces
7761
indent-style = "space"
78-
79-
# Respect magic trailing commas
8062
skip-magic-trailing-comma = false
81-
82-
# Automatically detect line ending
8363
line-ending = "auto"

0 commit comments

Comments
 (0)