-
Notifications
You must be signed in to change notification settings - Fork 1
263 lines (229 loc) · 8.84 KB
/
cd.yml
File metadata and controls
263 lines (229 loc) · 8.84 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
# .github/workflows/cd.yml
# Continuous Deployment workflow for Three Horizons Accelerator
name: CD
on:
push:
branches: [main]
paths:
- "terraform/**"
- "deploy/**"
workflow_dispatch:
inputs:
environment:
description: "Target environment"
required: true
type: choice
options:
- dev
- staging
- prod
horizon:
description: "Horizon to deploy"
required: true
type: choice
options:
- h1-foundation
- h2-enhancement
- h3-innovation
- all
dry_run:
description: "Dry run (plan only)"
required: false
type: boolean
default: true
concurrency:
group: cd-${{ github.event.inputs.environment || 'dev' }}
cancel-in-progress: false
env:
ARM_USE_OIDC: true
TF_VERSION: "1.5.0"
jobs:
# Job 1: Prepare deployment
prepare:
runs-on: ubuntu-latest
outputs:
environment: ${{ steps.config.outputs.environment }}
horizon: ${{ steps.config.outputs.horizon }}
dry_run: ${{ steps.config.outputs.dry_run }}
steps:
- name: Set Configuration
id: config
run: |
# Determine configuration from inputs or defaults
ENV="${{ github.event.inputs.environment || 'dev' }}"
HORIZON="${{ github.event.inputs.horizon || 'all' }}"
DRY_RUN="${{ github.event.inputs.dry_run || 'true' }}"
echo "environment=$ENV" >> $GITHUB_OUTPUT
echo "horizon=$HORIZON" >> $GITHUB_OUTPUT
echo "dry_run=$DRY_RUN" >> $GITHUB_OUTPUT
echo "## Deployment Configuration" >> $GITHUB_STEP_SUMMARY
echo "| Setting | Value |" >> $GITHUB_STEP_SUMMARY
echo "|---------|-------|" >> $GITHUB_STEP_SUMMARY
echo "| Environment | $ENV |" >> $GITHUB_STEP_SUMMARY
echo "| Horizon | $HORIZON |" >> $GITHUB_STEP_SUMMARY
echo "| Dry Run | $DRY_RUN |" >> $GITHUB_STEP_SUMMARY
# Job 2: Deploy H1 Foundation
deploy-h1:
runs-on: ubuntu-latest
needs: prepare
if: needs.prepare.outputs.horizon == 'h1-foundation' || needs.prepare.outputs.horizon == 'all'
environment: ${{ needs.prepare.outputs.environment }}
steps:
- uses: actions/checkout@v4
- name: Azure Login
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ env.TF_VERSION }}
- name: Terraform Init
working-directory: terraform
run: |
terraform init \
-backend-config="resource_group_name=${{ secrets.TF_STATE_RG }}" \
-backend-config="storage_account_name=${{ secrets.TF_STATE_STORAGE }}" \
-backend-config="container_name=tfstate" \
-backend-config="key=${{ needs.prepare.outputs.environment }}.tfstate"
- name: Terraform Plan
working-directory: terraform
run: |
terraform plan \
-var-file="environments/${{ needs.prepare.outputs.environment }}.tfvars" \
-out=tfplan
- name: Terraform Apply
if: needs.prepare.outputs.dry_run == 'false'
working-directory: terraform
run: terraform apply -auto-approve tfplan
- name: Output Infrastructure Details
if: needs.prepare.outputs.dry_run == 'false'
working-directory: terraform
run: |
echo "## H1 Infrastructure Deployed" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
terraform output -json | jq -r 'to_entries[] | "- **\(.key)**: \(.value.value)"' >> $GITHUB_STEP_SUMMARY
# Job 3: Deploy H2 Enhancement
deploy-h2:
runs-on: ubuntu-latest
needs: [prepare, deploy-h1]
if: |
always() &&
(needs.prepare.outputs.horizon == 'h2-enhancement' || needs.prepare.outputs.horizon == 'all') &&
(needs.deploy-h1.result == 'success' || needs.deploy-h1.result == 'skipped')
environment: ${{ needs.prepare.outputs.environment }}
steps:
- uses: actions/checkout@v4
- name: Azure Login
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Get AKS Credentials
run: |
az aks get-credentials \
--resource-group ${{ secrets.RESOURCE_GROUP }} \
--name ${{ secrets.AKS_CLUSTER_NAME }} \
--overwrite-existing
- name: Deploy ArgoCD
if: needs.prepare.outputs.dry_run == 'false'
run: |
helm repo add argo https://argoproj.github.io/argo-helm
helm repo update
helm upgrade --install argocd argo/argo-cd \
--namespace argocd \
--create-namespace \
--values deploy/helm/argocd/values.yaml \
--wait
- name: Deploy Observability Stack
if: needs.prepare.outputs.dry_run == 'false'
run: |
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
helm upgrade --install kube-prometheus-stack prometheus-community/kube-prometheus-stack \
--namespace monitoring \
--create-namespace \
--values deploy/helm/monitoring/values.yaml \
--wait
# Job 4: Deploy H3 Innovation
deploy-h3:
runs-on: ubuntu-latest
needs: [prepare, deploy-h2]
if: |
always() &&
(needs.prepare.outputs.horizon == 'h3-innovation' || needs.prepare.outputs.horizon == 'all') &&
(needs.deploy-h2.result == 'success' || needs.deploy-h2.result == 'skipped')
environment: ${{ needs.prepare.outputs.environment }}
steps:
- uses: actions/checkout@v4
- name: Azure Login
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Deploy Microsoft Foundry Resources
if: needs.prepare.outputs.dry_run == 'false'
working-directory: terraform/modules/ai-foundry
run: |
terraform init
terraform apply -auto-approve \
-var="environment=${{ needs.prepare.outputs.environment }}"
# Job 5: Validation
validate-deployment:
runs-on: ubuntu-latest
needs: [prepare, deploy-h1, deploy-h2, deploy-h3]
if: always() && needs.prepare.outputs.dry_run == 'false'
steps:
- uses: actions/checkout@v4
- name: Azure Login
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Run Validation Script
run: |
./.github/skills/validation-scripts/scripts/validate-deployment.sh \
--environment ${{ needs.prepare.outputs.environment }} \
--horizon ${{ needs.prepare.outputs.horizon }}
- name: Deployment Summary
run: |
echo "## Deployment Complete" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Component | Status |" >> $GITHUB_STEP_SUMMARY
echo "|-----------|--------|" >> $GITHUB_STEP_SUMMARY
echo "| H1 Foundation | ${{ needs.deploy-h1.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| H2 Enhancement | ${{ needs.deploy-h2.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| H3 Innovation | ${{ needs.deploy-h3.result }} |" >> $GITHUB_STEP_SUMMARY
# Job 6: Notification
notify:
runs-on: ubuntu-latest
needs: [prepare, validate-deployment]
if: always()
steps:
- name: Send Teams Notification
if: env.TEAMS_WEBHOOK != ''
env:
TEAMS_WEBHOOK: ${{ secrets.TEAMS_WEBHOOK }}
run: |
STATUS="${{ needs.validate-deployment.result }}"
COLOR=$([ "$STATUS" == "success" ] && echo "00FF00" || echo "FF0000")
curl -H "Content-Type: application/json" -d '{
"@type": "MessageCard",
"@context": "http://schema.org/extensions",
"themeColor": "'$COLOR'",
"summary": "Deployment '${{ needs.prepare.outputs.environment }}'",
"sections": [{
"activityTitle": "🚀 Deployment Update",
"facts": [
{"name": "Environment", "value": "${{ needs.prepare.outputs.environment }}"},
{"name": "Horizon", "value": "${{ needs.prepare.outputs.horizon }}"},
{"name": "Status", "value": "'$STATUS'"},
{"name": "Actor", "value": "${{ github.actor }}"}
]
}]
}' "$TEAMS_WEBHOOK"