1010 - Agent.Name -equals ubuntu-self-hosted-mourouj
1111
1212variables :
13- - group : silkroad-mourouj # Contains Connection_String_Mourouj
13+ - group : silkroad-mourouj
14+ - name : connectionString
15+ value : $(Connection_String_Mourouj)
1416- name : kubeNamespace
1517 value : silkroad-prod
1618- name : deploymentApiName
@@ -24,122 +26,13 @@ stages:
2426- stage : Deploy
2527 displayName : Deploy to Mourouj Kubernetes
2628 jobs :
27- - job : DeployJob
28- displayName : K8s Deployment
29- steps :
30-
31- # --------------------------------------------------
32- # 0️⃣ Check Cluster Access
33- # --------------------------------------------------
34- - script : |
35- echo "🔍 Checking cluster access"
36- kubectl version --client
37- kubectl cluster-info
38- displayName: 'Check Kubernetes Cluster'
39-
40- # --------------------------------------------------
41- # 1️⃣ Ensure DB Connection Secret
42- # --------------------------------------------------
43- - script : |
44- echo "🔐 Ensuring DB secret exists for Mourouj"
45- kubectl create secret generic silkroad-connection-secret \
46- -n $(kubeNamespace) \
47- --from-literal=ConnectionStrings__DefaultConnection="$(Connection_String_Mourouj)" \
48- --dry-run=client -o yaml | kubectl apply -f -
49- displayName: 'Ensure DB Secret'
50- env:
51- Connection_String_Mourouj: $(Connection_String_Mourouj)
52-
53-
54- # --------------------------------------------------
55- # 2️⃣ Apply Kubernetes Manifests
56- # --------------------------------------------------
57- - script : |
58- echo "🚀 Applying Kubernetes manifests"
59- kubectl apply -f $(manifestPath)
60- echo "✅ Manifests applied"
61- displayName: 'Apply Manifests'
62-
63- # --------------------------------------------------
64- # 3️⃣ Update Deployment Images to Latest Tags
65- # --------------------------------------------------
66- - script : |
67- echo "🔄 Updating deployment images to latest tags..."
68-
69- echo "📝 Setting API image to: tunnetcom/silkroad:latest-api"
70- kubectl set image deployment/$(deploymentApiName) \
71- api=tunnetcom/silkroad:latest-api \
72- -n $(kubeNamespace)
73-
74- echo "📝 Setting WebApp image to: tunnetcom/silkroad:latest-webapp"
75- kubectl set image deployment/$(deploymentWebappName) \
76- webapp=tunnetcom/silkroad:latest-webapp \
77- -n $(kubeNamespace)
78-
79- echo "✅ Image tags updated"
80- displayName: 'Update Deployment Images'
81-
82- # --------------------------------------------------
83- # 4️⃣ Force Image Refresh (rollout)
84- # --------------------------------------------------
85- - script : |
86- echo "🔄 Forcing rollout to pull latest images"
87-
88- kubectl rollout restart deployment/$(deploymentApiName) -n $(kubeNamespace)
89- kubectl rollout restart deployment/$(deploymentWebappName) -n $(kubeNamespace)
90-
91- TIMESTAMP=$(date +%s)
92- kubectl patch deployment $(deploymentApiName) \
93- -n $(kubeNamespace) \
94- -p "{\"spec\":{\"template\":{\"metadata\":{\"annotations\":{\"ci-build\":\"$(Build.BuildId)\",\"force-image-pull\":\"$(Build.BuildId)-$TIMESTAMP\"}}}}}"
95-
96- kubectl patch deployment $(deploymentWebappName) \
97- -n $(kubeNamespace) \
98- -p "{\"spec\":{\"template\":{\"metadata\":{\"annotations\":{\"ci-build\":\"$(Build.BuildId)\",\"force-image-pull\":\"$(Build.BuildId)-$TIMESTAMP\"}}}}}"
99-
100- # Delete existing pods to ensure fresh image pull
101- kubectl delete pods -n $(kubeNamespace) -l app=$(deploymentApiName) --ignore-not-found=true || true
102- kubectl delete pods -n $(kubeNamespace) -l app=$(deploymentWebappName) --ignore-not-found=true || true
103-
104- sleep 10
105- displayName: 'Force Image Refresh'
106-
107- # --------------------------------------------------
108- # 5️⃣ Wait for Rollout Completion
109- # --------------------------------------------------
110- - script : |
111- echo "⏳ Waiting for API rollout to complete..."
112- kubectl rollout status deployment/$(deploymentApiName) -n $(kubeNamespace) --timeout=300s || exit 1
113-
114- echo "⏳ Waiting for WebApp rollout to complete..."
115- kubectl rollout status deployment/$(deploymentWebappName) -n $(kubeNamespace) --timeout=300s || exit 1
116-
117- sleep 10
118- displayName: 'Wait for Rollout'
119-
120- # --------------------------------------------------
121- # 6️⃣ Check for Image Pull Errors
122- # --------------------------------------------------
123- - script : |
124- echo "🔍 Checking for image pull errors..."
125- echo "=== Recent Events (last 20) ==="
126- kubectl get events -n $(kubeNamespace) --sort-by='.lastTimestamp' | tail -20
127- displayName: 'Check Image Pull Errors'
128- continueOnError: true
129-
130- # --------------------------------------------------
131- # 7️⃣ Verify Deployment
132- # --------------------------------------------------
133- - script : |
134- echo "🔍 Verifying deployed images and pod status"
135- kubectl get pods -n $(kubeNamespace) -o wide
136- echo "✅ Deployment verification complete"
137- displayName: 'Verify Deployment'
138-
139- # --------------------------------------------------
140- # 8️⃣ Final Status
141- # --------------------------------------------------
142- - script : |
143- echo "✅ Deployment finished successfully"
144- kubectl get all -n $(kubeNamespace)
145- displayName: 'Final Status'
29+ - template : templates/deploy-k8s-job.yml
30+ parameters :
31+ stageDisplayName : Deploy to Mourouj Kubernetes
32+ kubeNamespace : $(kubeNamespace)
33+ deploymentApiName : $(deploymentApiName)
34+ deploymentWebappName : $(deploymentWebappName)
35+ manifestPath : $(manifestPath)
36+ variableGroup : silkroad-mourouj
37+ forceImagePullPatch : true
38+ verboseVerify : true
0 commit comments