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