Skip to content

Commit 7a7b5dc

Browse files
committed
Make deployment job only run after build images works
1 parent 25ae14d commit 7a7b5dc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+3715
-472
lines changed
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
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+
# Test connection
120+
echo "🔍 Testing cluster connection..."
121+
kubectl cluster-info || {
122+
echo "❌ Failed to connect to cluster"
123+
exit 1
124+
}
125+
echo "✅ Cluster connection successful"
126+
127+
- name: Deploy Auth Service
128+
run: |
129+
echo "🚀 Deploying Auth Service..."
130+
131+
# Ensure namespace exists
132+
kubectl create namespace study-mate --dry-run=client -o yaml | kubectl apply -f -
133+
134+
# Deploy auth service with secrets
135+
helm upgrade --install auth-service ./infra/helm-charts/auth-service -n study-mate \
136+
--set authService.image.tag="${{ github.event.inputs.image_tag || github.sha }}" \
137+
--set secrets.jwt.data.jwtSecret="${{ secrets.JWT_SECRET }}" \
138+
--wait --timeout=5m || {
139+
echo "❌ Auth service deployment failed"
140+
echo "🔍 Checking deployment status..."
141+
helm status auth-service -n study-mate || echo "⚠️ Could not get release status"
142+
echo "🔍 Checking pod status..."
143+
kubectl get pods -n study-mate -l app.kubernetes.io/name=auth-service || echo "⚠️ Could not get pod status"
144+
exit 1
145+
}
146+
147+
echo "✅ Auth service deployed successfully"
148+
149+
- name: Verify Deployment
150+
run: |
151+
echo "🔍 Verifying auth service deployment..."
152+
153+
# Wait for pod to be ready
154+
kubectl wait --for=condition=ready pod -l app.kubernetes.io/name=auth-service -n study-mate --timeout=300s || {
155+
echo "❌ Auth service pod failed to become ready"
156+
echo "🔍 Pod status:"
157+
kubectl get pods -n study-mate -l app.kubernetes.io/name=auth-service -o wide
158+
echo "🔍 Pod logs:"
159+
kubectl logs -l app.kubernetes.io/name=auth-service -n study-mate --tail=50 || echo "⚠️ Could not get logs"
160+
exit 1
161+
}
162+
163+
echo "✅ Auth service is ready"
164+
165+
# Check service
166+
kubectl get service auth-service -n study-mate
167+
168+
# Health check
169+
echo "🏥 Performing health check..."
170+
kubectl port-forward svc/auth-service 8086:8086 -n study-mate &
171+
PF_PID=$!
172+
sleep 10
173+
174+
if curl -f http://localhost:8086/actuator/health > /dev/null 2>&1; then
175+
echo "✅ Auth service health check passed"
176+
else
177+
echo "❌ Auth service health check failed"
178+
fi
179+
180+
kill $PF_PID 2>/dev/null || true
181+
182+
- name: Deployment Summary
183+
run: |
184+
echo "🌐 Auth Service Deployment Complete!"
185+
echo "📦 Namespace: study-mate"
186+
echo "🔧 Release: auth-service"
187+
echo "🏷️ Image tag: ${{ github.event.inputs.image_tag || github.sha }}"
188+
echo ""
189+
echo "🔧 Useful commands:"
190+
echo " kubectl get pods -n study-mate -l app.kubernetes.io/name=auth-service"
191+
echo " kubectl logs -f deployment/auth-service -n study-mate"
192+
echo " kubectl port-forward svc/auth-service 8086:8086 -n study-mate"
193+
echo ""
194+
echo "🔍 Troubleshooting:"
195+
echo " kubectl get events -n study-mate --sort-by='.lastTimestamp'"
196+
echo " helm status auth-service -n study-mate"

0 commit comments

Comments
 (0)