-
Notifications
You must be signed in to change notification settings - Fork 0
173 lines (142 loc) · 5.81 KB
/
deploy-client.yml
File metadata and controls
173 lines (142 loc) · 5.81 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
name: Deploy Client
on:
push:
branches: [main]
paths:
- 'client/**'
- 'infra/helm-charts/client/**'
- '.github/workflows/deploy-client.yml'
pull_request:
types: [opened, synchronize, reopened]
paths:
- 'client/**'
- 'infra/helm-charts/client/**'
- '.github/workflows/deploy-client.yml'
workflow_dispatch:
inputs:
image_tag:
description: 'Image tag to deploy'
required: true
default: 'k8s-latest'
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'
cache-dependency-path: client/package-lock.json
- name: Install dependencies
run: |
cd client
npm ci
echo "✅ Dependencies installed successfully"
- name: Build React app
run: |
cd client
npm run build
echo "✅ React app built successfully"
- name: Build Docker Image
run: |
cd client
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 }} .
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 .
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 client
docker push ghcr.io/aet-devops25/team-3/client:${{ github.event.inputs.image_tag || github.sha }}
docker push ghcr.io/aet-devops25/team-3/client:k8s-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: client
CHART_PATH: ./infra/helm-charts/client
HELM_NAMESPACE: study-mate
IMAGE_TAG: ${{ github.event.inputs.image_tag || github.sha }}
run: |
echo "🚀 Deploying Client..."
helm upgrade --install ${{ env.HELM_RELEASE_NAME }} ${{ env.CHART_PATH }} \
--namespace ${{ env.HELM_NAMESPACE }} \
--set image.tag=k8s-latest \
--set apiBaseUrl="https://study-mate.student.k8s.aet.cit.tum.de" \
--wait --timeout=5m
echo "✅ Client deployed successfully"
- name: Verify Deployment
run: |
echo "🔍 Verifying client deployment..."
# Wait for pod to be ready
kubectl wait --for=condition=ready pod -l app.kubernetes.io/name=client -n study-mate --timeout=300s || {
echo "❌ Client pod failed to become ready"
echo "🔍 Pod status:"
kubectl get pods -n study-mate -l app.kubernetes.io/name=client -o wide
echo "🔍 Pod logs:"
kubectl logs -l app.kubernetes.io/name=client -n study-mate --tail=50 || echo "⚠️ Could not get logs"
exit 1
}
echo "✅ Client is ready"
# Check service
kubectl get service client -n study-mate
# Check ingress
kubectl get ingress study-mate-client-ingress -n study-mate
# Health check
echo "🏥 Performing health check..."
kubectl port-forward svc/client 80:80 -n study-mate &
PF_PID=$!
sleep 10
if curl -f http://localhost:80/ > /dev/null 2>&1; then
echo "✅ Client health check passed"
else
echo "❌ Client health check failed"
fi
kill $PF_PID 2>/dev/null || true
- name: Deployment Summary
run: |
echo "🌐 Client Deployment Complete!"
echo "📦 Namespace: study-mate"
echo "🔧 Release: client"
echo "🏷️ Image tag: ${{ github.event.inputs.image_tag || github.sha }}"
echo "🌍 URL: https://study-mate.student.k8s.aet.cit.tum.de"
echo ""
echo "🔧 Useful commands:"
echo " kubectl get pods -n study-mate -l app.kubernetes.io/name=client"
echo " kubectl logs -f deployment/client -n study-mate"
echo " kubectl port-forward svc/client 80:80 -n study-mate"
echo ""
echo "🔍 Troubleshooting:"
echo " kubectl get events -n study-mate --sort-by='.lastTimestamp'"
echo " helm status client -n study-mate"