Skip to content

Commit 2ade7eb

Browse files
authored
Merge pull request #41 from AET-DevOps25/feature/make-kubernetes-deployment-modular
Make modular kubernetes deployment
2 parents e2098da + 8deed6a commit 2ade7eb

Some content is hidden

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

71 files changed

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

0 commit comments

Comments
 (0)