-
Notifications
You must be signed in to change notification settings - Fork 0
196 lines (180 loc) · 6.22 KB
/
deploy-staging.yml
File metadata and controls
196 lines (180 loc) · 6.22 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
name: Deploy to Staging
on:
push:
branches:
- main
paths:
- 'src/**'
- 'infrastructure/helm/**'
- 'Dockerfile'
- '.github/workflows/deploy-staging.yml'
workflow_dispatch:
jobs:
deploy-staging:
runs-on: ubuntu-latest
environment: staging
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Extract version
id: version
run: |
VERSION=$(git describe --tags --always --abbrev=7)
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Deploying version: $VERSION"
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Update kubeconfig for EKS
run: |
aws eks update-kubeconfig \
--region ${{ secrets.AWS_REGION }} \
--name lexecon-staging
- name: Verify kubectl connection
run: |
kubectl cluster-info
kubectl get nodes
- name: Deploy to Kubernetes
env:
DATABASE_URL: ${{ secrets.DATABASE_URL_STAGING }}
run: |
chmod +x infrastructure/scripts/deploy.sh
./infrastructure/scripts/deploy.sh staging ${{ steps.version.outputs.version }}
- name: Wait for rollout to complete
run: |
kubectl wait --for=condition=available --timeout=5m \
deployment/lexecon-staging -n staging
echo "✅ Deployment rollout complete"
- name: Verify deployment health
run: |
echo "Checking pod health..."
kubectl get pods -n staging -l app.kubernetes.io/name=lexecon
POD_NAME=$(kubectl get pods -n staging -l app.kubernetes.io/name=lexecon -o jsonpath='{.items[0].metadata.name}')
echo "Running health checks..."
kubectl exec -n staging $POD_NAME -- curl -sf http://localhost:8000/health || exit 1
echo "✅ Health check passed"
- name: Get deployment info
run: |
echo "=== Deployment Status ==="
kubectl get deployment lexecon-staging -n staging -o wide
echo ""
echo "=== Pods ==="
kubectl get pods -n staging -l app.kubernetes.io/name=lexecon
echo ""
echo "=== Service ==="
kubectl get service lexecon-staging -n staging
- name: Notify Slack - Success
if: success()
uses: slackapi/slack-github-action@v1
with:
webhook-url: ${{ secrets.SLACK_WEBHOOK }}
payload: |
{
"text": "✅ Staging deployment successful",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "✅ Staging Deployed"
}
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Version:*\n${{ steps.version.outputs.version }}"
},
{
"type": "mrkdwn",
"text": "*Environment:*\nStaging (EKS)"
},
{
"type": "mrkdwn",
"text": "*Commit:*\n<${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}|${{ github.sha }}>'"
},
{
"type": "mrkdwn",
"text": "*Deployed by:*\n${{ github.actor }}"
}
]
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "View Workflow"
},
"url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}
]
}
]
}
- name: Notify Slack - Failure
if: failure()
uses: slackapi/slack-github-action@v1
with:
webhook-url: ${{ secrets.SLACK_WEBHOOK }}
payload: |
{
"text": "❌ Staging deployment failed",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "❌ Staging Deployment Failed"
}
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Version:*\n${{ steps.version.outputs.version }}"
},
{
"type": "mrkdwn",
"text": "*Status:*\n❌ Failed"
},
{
"type": "mrkdwn",
"text": "*Commit:*\n`${{ github.sha }}`"
},
{
"type": "mrkdwn",
"text": "*Attempted by:*\n${{ github.actor }}"
}
]
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Staging deployment failed. Check logs for details."
}
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "View Logs"
},
"style": "danger",
"url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}
]
}
]
}