-
Notifications
You must be signed in to change notification settings - Fork 0
151 lines (132 loc) · 5.25 KB
/
cd.yml
File metadata and controls
151 lines (132 loc) · 5.25 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
name: CD Pipeline
on:
workflow_run:
workflows: [CI Pipeline]
types:
- completed
conclusion: success
workflow_dispatch:
jobs:
# Check if we should deploy based on the workflow_run event
evaluate_deployment:
name: Evaluate Deployment Conditions
runs-on: ubuntu-latest
#if: ${{ github.event.workflow_run.conclusion == 'success' }}
outputs:
deploy_environment: ${{ steps.set-env.outputs.environment }}
should_deploy: ${{ steps.set-env.outputs.should_deploy }}
steps:
- name: Set environment based on branch
id: set-env
run: |
if [[ "${{ github.event.workflow_run.head_branch }}" == "main" ]]; then
echo "environment=production" >> $GITHUB_OUTPUT
echo "should_deploy=true" >> $GITHUB_OUTPUT
elif [[ "${{ github.event.workflow_run.head_branch }}" == "dev" ]]; then
echo "environment=staging" >> $GITHUB_OUTPUT
echo "should_deploy=true" >> $GITHUB_OUTPUT
else
echo "environment=none" >> $GITHUB_OUTPUT
echo "should_deploy=false" >> $GITHUB_OUTPUT
fi
# Deploy to staging environment
deploy_staging:
name: Deploy to Staging
needs: [evaluate_deployment]
if: ${{ needs.evaluate_deployment.outputs.should_deploy == 'true' && needs.evaluate_deployment.outputs.deploy_environment == 'staging' }}
runs-on: ubuntu-latest
environment:
name: staging
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_sha }}
- name: Setup Helm
uses: azure/setup-helm@v3
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Setup kubectl
uses: azure/setup-kubectl@v3
with:
version: "latest"
- name: Configure kubeconfig
run: |
mkdir -p $HOME/.kube
echo "${{ secrets.KUBECONFIG }}" > $HOME/.kube/config
- name: Run Helm Upgrade
run: |
cd helm/ai-event-concepter
helm upgrade --install ai-event-concepter . \
--namespace team-git-push-force-dev \
--create-namespace \
--set ingress.host=dev-aieventconcepter.student.k8s.aet.cit.tum.de \
--set client.image.tag=dev \
--set gateway.image.tag=dev \
--set usersvc.image.tag=dev \
--set conceptsvc.image.tag=dev \
--set genaisvc.image.tag=dev
- name: Rollout Restart Deployments
run: |
kubectl rollout restart deployment -n team-git-push-force-dev
- name: Verify Deployment
run: |
echo "Verifying deployment to staging environment..."
RETRY_COUNT=0
MAX_RETRIES=10
until kubectl get pods -n team-git-push-force-dev -l app.kubernetes.io/name=ai-event-concepter -o jsonpath='{.items[*].status.containerStatuses[*].ready}' | grep -q "true" || [ $RETRY_COUNT -eq $MAX_RETRIES ]; do
echo "Waiting for pods to be ready... ($(($RETRY_COUNT+1))/$MAX_RETRIES)"
sleep 10
RETRY_COUNT=$((RETRY_COUNT+1))
done
if [ $RETRY_COUNT -eq $MAX_RETRIES ]; then
echo "Pods didn't become ready within the timeout period"
kubectl get pods -n team-git-push-force-dev
exit 1
fi
echo "✅ Staging deployment verified successfully!"
# Deploy to production environment
deploy_production:
name: Deploy to Production
needs: [evaluate_deployment]
if: ${{ needs.evaluate_deployment.outputs.should_deploy == 'true' && needs.evaluate_deployment.outputs.deploy_environment == 'production' }}
runs-on: ubuntu-latest
environment:
name: production
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_sha }}
- name: Setup Helm
uses: azure/setup-helm@v3
- name: Setup kubectl
uses: azure/setup-kubectl@v3
with:
version: "latest"
- name: Configure kubeconfig
run: |
mkdir -p $HOME/.kube
echo "${{ secrets.KUBECONFIG }}" > $HOME/.kube/config
- name: Run Helm
run: |
cd helm/ai-event-concepter
helm upgrade --debug --install -n team-git-push-force ai-event-concepter . \
--set ingress.host=aieventconcepter.student.k8s.aet.cit.tum.de
kubectl rollout restart deployment -n team-git-push-force
- name: Verify Deployment
run: |
echo "Verifying deployment to production environment..."
RETRY_COUNT=0
MAX_RETRIES=10
until kubectl get pods -n team-git-push-force -l app.kubernetes.io/name=ai-event-concepter -o jsonpath='{.items[*].status.containerStatuses[*].ready}' | grep -q "true" || [ $RETRY_COUNT -eq $MAX_RETRIES ]; do
echo "Waiting for pods to be ready... ($(($RETRY_COUNT+1))/$MAX_RETRIES)"
sleep 10
RETRY_COUNT=$((RETRY_COUNT+1))
done
if [ $RETRY_COUNT -eq $MAX_RETRIES ]; then
echo "Pods didn't become ready within the timeout period"
kubectl get pods -n team-git-push-force
exit 1
fi
echo "✅ Production deployment verified successfully!"