-
Notifications
You must be signed in to change notification settings - Fork 0
318 lines (276 loc) · 13.6 KB
/
ci-cd.yaml
File metadata and controls
318 lines (276 loc) · 13.6 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
# name: CI/CD Pipeline
# on:
# workflow_dispatch:
# push:
# branches:
# - main
# paths:
# - 'server/**'
# - '!server/k8s/**'
# - '!server/docker-compose.yml'
# jobs:
# build-and-push:
# runs-on: ubuntu-latest
# strategy:
# matrix:
# service: [user, payment, session, notification, message]
# include:
# - service: user
# dockerfile: Usermanagement_Service/Usermanagement/Dockerfile
# image_name: user-management
# current_version: v1.4.4.4
# deployment_name: user-service
# container_name: user
# - service: payment
# dockerfile: Payment_Service/Payment/Dockerfile
# image_name: payment-management
# current_version: v1.4.1.6
# deployment_name: payment-service
# container_name: payment
# - service: session
# dockerfile: Session_And_Task_Management_Service/Session_And_Task_Management/Dockerfile
# image_name: session-and-task-management
# current_version: v1.4.2.1
# deployment_name: session-and-task-service
# container_name: session
# - service: notification
# dockerfile: Notification_Service/Notification/Dockerfile
# image_name: notification-management
# current_version: v1.4.4.0
# deployment_name: notification-service
# container_name: notification
# - service: message
# dockerfile: Message_And_Video_Service/Message_Video/Dockerfile
# image_name: messages-management
# current_version: v1.4.3.9
# deployment_name: communication-service
# container_name: message
# steps:
# - name: Checkout code
# uses: actions/checkout@v4
# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v2
# - name: Login to Docker Hub
# uses: docker/login-action@v2
# with:
# username: ${{ secrets.DOCKERHUB_USERNAME }}
# password: ${{ secrets.DOCKERHUB_TOKEN }}
# # Increment version number
# - name: Increment version
# id: version
# run: |
# # Parse current_version in format v1.4.4.4
# CURRENT_VERSION="${{ matrix.current_version }}"
# # Split version into components
# MAJOR=$(echo $CURRENT_VERSION | cut -d. -f1 | sed 's/v//')
# MINOR=$(echo $CURRENT_VERSION | cut -d. -f2)
# PATCH=$(echo $CURRENT_VERSION | cut -d. -f3)
# BUILD=$(echo $CURRENT_VERSION | cut -d. -f4)
# # Increment the build number
# NEW_BUILD=$((BUILD + 1))
# NEW_TAG="v${MAJOR}.${MINOR}.${PATCH}.${NEW_BUILD}"
# echo "new_tag=$NEW_TAG" >> $GITHUB_OUTPUT
# echo "New version tag: $NEW_TAG for ${{ matrix.service }}"
# - name: Build and push
# uses: docker/build-push-action@v4
# with:
# context: .
# file: ${{ matrix.dockerfile }}
# push: true
# tags: |
# mrlionbyte/${{ matrix.image_name }}:${{ steps.version.outputs.new_tag }}
# mrlionbyte/${{ matrix.image_name }}:latest
# cache-from: type=registry,ref=mrlionbyte/${{ matrix.image_name }}:latest
# cache-to: type=inline
# build-and-push-workers:
# runs-on: ubuntu-latest
# strategy:
# matrix:
# worker: [celery-worker, celery-worker-notification]
# include:
# - worker: celery-worker
# dockerfile: Usermanagement_Service/Usermanagement/Dockerfile
# image_name: usermanagement-celery_worker
# current_version: v1.4.1.4
# deployment_name: celery-worker
# container_name: celery-worker
# - worker: celery-worker-notification
# dockerfile: Notification_Service/Notification/Dockerfile
# image_name: celery-worker-notification
# current_version: v1.3.7
# deployment_name: celery-worker-notification
# container_name: celery-worker-notification
# steps:
# - name: Checkout code
# uses: actions/checkout@v4
# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v2
# - name: Login to Docker Hub
# uses: docker/login-action@v2
# with:
# username: ${{ secrets.DOCKERHUB_USERNAME }}
# password: ${{ secrets.DOCKERHUB_TOKEN }}
# # Increment version number based on the current version
# - name: Increment version
# id: version
# run: |
# # Parse current_version
# CURRENT_VERSION="${{ matrix.current_version }}"
# # Split version into components
# MAJOR=$(echo $CURRENT_VERSION | cut -d. -f1 | sed 's/v//')
# MINOR=$(echo $CURRENT_VERSION | cut -d. -f2)
# PATCH=$(echo $CURRENT_VERSION | cut -d. -f3)
# BUILD=$(echo $CURRENT_VERSION | cut -d. -f4)
# # Increment the build number
# NEW_BUILD=$((BUILD + 1))
# NEW_TAG="v${MAJOR}.${MINOR}.${PATCH}.${NEW_BUILD}"
# echo "new_tag=$NEW_TAG" >> $GITHUB_OUTPUT
# echo "New version tag: $NEW_TAG for ${{ matrix.worker }}"
# - name: Build and push
# uses: docker/build-push-action@v4
# with:
# context: .
# file: ${{ matrix.dockerfile }}
# push: true
# tags: |
# mrlionbyte/${{ matrix.image_name }}:${{ steps.version.outputs.new_tag }}
# mrlionbyte/${{ matrix.image_name }}:latest
# cache-from: type=registry,ref=mrlionbyte/${{ matrix.image_name }}:latest
# cache-to: type=inline
# deploy-to-gke:
# needs: [build-and-push, build-and-push-workers]
# runs-on: ubuntu-latest
# steps:
# - name: Checkout code
# uses: actions/checkout@v4
# - name: Set up Google Cloud SDK
# uses: google-github-actions/setup-gcloud@v2
# with:
# project_id: ${{ secrets.GCP_PROJECT_ID }}
# service_account_key: ${{ secrets.GCP_SA_KEY }}
# export_default_credentials: true
# - name: Authenticate kubectl with GKE
# run: |
# gcloud container clusters get-credentials ${{ secrets.GKE_CLUSTER_NAME }} \
# --zone ${{ secrets.GCP_ZONE }} \
# --project ${{ secrets.GCP_PROJECT_ID }}
# # Get the new versions from the build jobs
# - name: Get new versions for each service
# run: |
# # Create a function to get the new version tag for each image
# get_new_version() {
# local image_name=$1
# local current_version=$2
# # Split version into components
# MAJOR=$(echo $current_version | cut -d. -f1 | sed 's/v//')
# MINOR=$(echo $current_version | cut -d. -f2)
# PATCH=$(echo $current_version | cut -d. -f3)
# BUILD=$(echo $current_version | cut -d. -f4)
# # Increment the build number
# NEW_BUILD=$((BUILD + 1))
# echo "v${MAJOR}.${MINOR}.${PATCH}.${NEW_BUILD}"
# }
# # Get new version tags for each service
# USER_TAG=$(get_new_version "user-management" "v1.4.4.4")
# PAYMENT_TAG=$(get_new_version "payment-management" "v1.4.1.6")
# SESSION_TAG=$(get_new_version "session-and-task-management" "v1.4.2.1")
# NOTIFICATION_TAG=$(get_new_version "notification-management" "v1.4.4.0")
# MESSAGE_TAG=$(get_new_version "messages-management" "v1.4.3.9")
# CELERY_WORKER_TAG=$(get_new_version "usermanagement-celery_worker" "v1.4.1.4")
# NOTIFICATION_CELERY_TAG=$(get_new_version "celery-worker-notification" "v1.3.7")
# # Store in environment for next step
# echo "USER_TAG=$USER_TAG" >> $GITHUB_ENV
# echo "PAYMENT_TAG=$PAYMENT_TAG" >> $GITHUB_ENV
# echo "SESSION_TAG=$SESSION_TAG" >> $GITHUB_ENV
# echo "NOTIFICATION_TAG=$NOTIFICATION_TAG" >> $GITHUB_ENV
# echo "MESSAGE_TAG=$MESSAGE_TAG" >> $GITHUB_ENV
# echo "CELERY_WORKER_TAG=$CELERY_WORKER_TAG" >> $GITHUB_ENV
# echo "NOTIFICATION_CELERY_TAG=$NOTIFICATION_CELERY_TAG" >> $GITHUB_ENV
# - name: Update Deployments
# run: |
# # Update main services
# kubectl set image deployment/user-service user=mrlionbyte/user-management:${USER_TAG} -n studyzed
# kubectl set image deployment/payment-service payment=mrlionbyte/payment-management:${PAYMENT_TAG} -n studyzed
# kubectl set image deployment/session-and-task-service session=mrlionbyte/session-and-task-management:${SESSION_TAG} -n studyzed
# kubectl set image deployment/notification-service notification=mrlionbyte/notification-management:${NOTIFICATION_TAG} -n studyzed
# kubectl set image deployment/communication-service message=mrlionbyte/messages-management:${MESSAGE_TAG} -n studyzed
# # Update worker services
# kubectl set image deployment/celery-worker celery-worker=mrlionbyte/usermanagement-celery_worker:${CELERY_WORKER_TAG} -n studyzed
# kubectl set image deployment/celery-worker-notification celery-worker-notification=mrlionbyte/celery-worker-notification:${NOTIFICATION_CELERY_TAG} -n studyzed
# - name: Verify Deployment
# run: |
# kubectl rollout status deployment/user-service -n studyzed
# kubectl rollout status deployment/payment-service -n studyzed
# kubectl rollout status deployment/session-and-task-service -n studyzed
# kubectl rollout status deployment/notification-service -n studyzed
# kubectl rollout status deployment/communication-service -n studyzed
# kubectl rollout status deployment/celery-worker -n studyzed
# kubectl rollout status deployment/celery-worker-notification -n studyzed
# echo "Listing all pods in studyzed namespace:"
# kubectl get pods -n studyzed
name: CI/CD Pipeline
on:
workflow_dispatch:
push:
branches:
- main
paths:
- 'server/**'
- '!server/k8s/**'
- '!server/docker-compose.yml'
jobs:
deploy-to-gke:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GCP_SA_KEY }}
- name: Set up Google Cloud SDK
uses: google-github-actions/setup-gcloud@v2
with:
project_id: ${{ secrets.GCP_PROJECT_ID }}
- name: Install gke-gcloud-auth-plugin
run: |
gcloud components install gke-gcloud-auth-plugin -q
gcloud components update -q
which gke-gcloud-auth-plugin || echo "Plugin not found in PATH"
- name: Authenticate kubectl with GKE
run: |
gcloud container clusters get-credentials ${{ secrets.GKE_CLUSTER_NAME }} \
--zone ${{ secrets.GCP_ZONE }} \
--project ${{ secrets.GCP_PROJECT_ID }}
- name: Debug - Show deployment details
run: |
echo "Checking container names in deployments:"
kubectl describe deployment user-service -n studyzed | grep -A 5 "Containers:"
kubectl describe deployment payment-service -n studyzed | grep -A 5 "Containers:"
kubectl describe deployment session-and-task-service -n studyzed | grep -A 5 "Containers:"
kubectl describe deployment notification-service -n studyzed | grep -A 5 "Containers:"
kubectl describe deployment communication-service -n studyzed | grep -A 5 "Containers:"
kubectl describe deployment celery-worker -n studyzed | grep -A 5 "Containers:"
kubectl describe deployment celery-worker-notification -n studyzed | grep -A 5 "Containers:"
- name: Update Deployments
run: |
# Update main services -
kubectl set image deployment/user-service user-service=mrlionbyte/user-management:v1.4.6.8 -n studyzed
kubectl set image deployment/payment-service payment-service=mrlionbyte/payment-management:v1.4.2.6 -n studyzed
kubectl set image deployment/session-and-task-service session-and-task-service=mrlionbyte/session-and-task-management:v1.4.2.7 -n studyzed
kubectl set image deployment/notification-service notification-service=mrlionbyte/notification-management:v1.4.4.0 -n studyzed
kubectl set image deployment/communication-service communication-service=mrlionbyte/messages-management:v1.4.3.9 -n studyzed
# Update worker services -
kubectl set image deployment/celery-worker celery-worker=mrlionbyte/usermanagement-celery_worker:v1.4.2.2 -n studyzed
kubectl set image deployment/celery-worker-notification celery-worker-notification=mrlionbyte/celery-worker-notification:v1.3.7 -n studyzed
- name: Verify Deployment
run: |
kubectl rollout status deployment/user-service -n studyzed
kubectl rollout status deployment/payment-service -n studyzed
kubectl rollout status deployment/session-and-task-service -n studyzed
kubectl rollout status deployment/notification-service -n studyzed
kubectl rollout status deployment/communication-service -n studyzed
kubectl rollout status deployment/celery-worker -n studyzed
kubectl rollout status deployment/celery-worker-notification -n studyzed
echo "Listing all pods in studyzed namespace:"
kubectl get pods -n studyzed