-
Notifications
You must be signed in to change notification settings - Fork 0
177 lines (146 loc) · 6.45 KB
/
deploy-document-service.yml
File metadata and controls
177 lines (146 loc) · 6.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
name: Deploy Document Service
on:
push:
branches: [main]
paths:
- 'server/document-service/**'
- 'infra/helm-charts/document-service/**'
- '.github/workflows/deploy-document-service.yml'
pull_request:
types: [opened, synchronize, reopened]
paths:
- 'server/document-service/**'
- 'infra/helm-charts/document-service/**'
- '.github/workflows/deploy-document-service.yml'
workflow_dispatch:
inputs:
image_tag:
description: 'Image tag to deploy'
required: true
default: 'latest'
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Java
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
with:
gradle-version: '8.5'
- name: Build Document Service
run: |
cd server/document-service
./gradlew build -x test
echo "✅ Document service built successfully"
- name: Build Docker Image
run: |
cd server/document-service
docker build -t ghcr.io/aet-devops25/team-3/document-service:${{ github.event.inputs.image_tag || github.sha }} .
docker build -t ghcr.io/aet-devops25/team-3/document-service:latest .
echo "✅ Docker image built successfully"
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push Docker Image
run: |
cd server/document-service
docker push ghcr.io/aet-devops25/team-3/document-service:${{ github.event.inputs.image_tag || github.sha }}
docker push ghcr.io/aet-devops25/team-3/document-service:latest
echo "✅ Docker image pushed successfully"
- name: Setup Kubernetes tools
run: |
echo "🔧 Setting up Kubernetes tools..."
# Install kubectl
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x kubectl
sudo mv kubectl /usr/local/bin/
# Install Helm
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
# Install jq for JSON parsing
sudo apt-get update && sudo apt-get install -y jq
echo "✅ Kubernetes tools installed"
kubectl version --client
helm version
- name: Configure kubectl
env:
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
run: |
echo "🔧 Configuring kubectl..."
# Set up kubectl configuration from secret
mkdir -p $HOME/.kube
echo "$KUBE_CONFIG" > $HOME/.kube/config
chmod 600 $HOME/.kube/config
echo "✅ Kubectl configured"
- name: Deploy Helm Chart
env:
HELM_RELEASE_NAME: document-service
CHART_PATH: ./infra/helm-charts/document-service
HELM_NAMESPACE: study-mate
IMAGE_TAG: ${{ github.event.inputs.image_tag || github.sha }}
run: |
echo "🚀 Deploying Document Service..."
helm upgrade --install ${{ env.HELM_RELEASE_NAME }} ${{ env.CHART_PATH }} \
--namespace ${{ env.HELM_NAMESPACE }} \
--set documentService.image.tag=${{ env.IMAGE_TAG }} \
--set secrets.jwt.data.jwtSecret="${{ secrets.JWT_SECRET }}" \
--wait --timeout=5m
echo "✅ Document service deployed successfully"
- name: Verify Deployment
run: |
echo "🔍 Verifying document service deployment..."
# Wait a bit for old pods to terminate after Helm upgrade
echo "⏳ Waiting for deployment to stabilize..."
sleep 30
# Wait for deployment to be ready (more reliable than waiting for specific pods)
echo "🔍 Waiting for deployment to be ready..."
kubectl rollout status deployment/study-mate-document-service -n study-mate --timeout=300s || {
echo "❌ Document service deployment failed to become ready"
echo "🔍 Deployment status:"
kubectl describe deployment study-mate-document-service -n study-mate
echo "🔍 Pod status:"
kubectl get pods -n study-mate -l app.kubernetes.io/component=document-service -o wide
echo "🔍 Pod logs:"
kubectl logs -l app.kubernetes.io/component=document-service -n study-mate --tail=50 || echo "⚠️ Could not get logs"
exit 1
}
echo "✅ Document service is ready"
# Check service
kubectl get service study-mate-document-service -n study-mate
# Health check
echo "🏥 Performing health check..."
kubectl port-forward svc/study-mate-document-service 8084:8084 -n study-mate &
PF_PID=$!
sleep 10
# Try health endpoint first, fallback to root endpoint
if curl -f http://localhost:8084/actuator/health > /dev/null 2>&1; then
echo "✅ Document service health check passed"
elif curl -f http://localhost:8084/ > /dev/null 2>&1; then
echo "✅ Document service is responding (root endpoint)"
else
echo "❌ Document service health check failed"
fi
kill $PF_PID 2>/dev/null || true
- name: Deployment Summary
run: |
echo "🌐 Document Service Deployment Complete!"
echo "📦 Namespace: study-mate"
echo "🔧 Release: document-service"
echo "🏷️ Image tag: ${{ github.event.inputs.image_tag || github.sha }}"
echo ""
echo "🔧 Useful commands:"
echo " kubectl get pods -n study-mate -l app.kubernetes.io/component=document-service"
echo " kubectl logs -f deployment/document-service -n study-mate"
echo " kubectl port-forward svc/study-mate-document-service 8084:8084 -n study-mate"
echo ""
echo "🔍 Troubleshooting:"
echo " kubectl get events -n study-mate --sort-by='.lastTimestamp'"
echo " helm status document-service -n study-mate"