-
Notifications
You must be signed in to change notification settings - Fork 1
208 lines (179 loc) · 7.12 KB
/
deploy-production.yml
File metadata and controls
208 lines (179 loc) · 7.12 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
name: Deploy to Production
on:
release:
types: [published]
workflow_dispatch:
inputs:
version:
description: 'Version tag to deploy (e.g., v1.0.0)'
required: true
skip_approval:
description: 'Skip manual approval (use with caution)'
required: false
default: 'false'
type: boolean
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
ENVIRONMENT: production
jobs:
validate:
name: Validate Deployment
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get_version.outputs.version }}
image_tag: ${{ steps.get_version.outputs.image_tag }}
steps:
- name: Get version from trigger
id: get_version
run: |
if [ "${{ github.event_name }}" == "release" ]; then
VERSION="${{ github.event.release.tag_name }}"
else
VERSION="${{ github.event.inputs.version }}"
fi
# Remove 'v' prefix if present for image tag
IMAGE_TAG="${VERSION#v}"
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "image_tag=$IMAGE_TAG" >> $GITHUB_OUTPUT
echo "Deploying version: $VERSION (image tag: $IMAGE_TAG)"
- name: Checkout code
uses: actions/checkout@v6
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Verify image exists
run: |
IMAGE_TAG="${{ steps.get_version.outputs.image_tag }}"
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${IMAGE_TAG} || {
echo "Error: Image tag ${IMAGE_TAG} not found in registry"
echo "Available tags can be found at: https://github.com/${{ github.repository }}/pkgs/container"
exit 1
}
echo "Image verified: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${IMAGE_TAG}"
approval:
name: Production Approval
runs-on: ubuntu-latest
needs: validate
if: github.event.inputs.skip_approval != 'true'
environment:
name: production-approval
steps:
- name: Approval gate
run: |
echo "Production deployment approved for version: ${{ needs.validate.outputs.version }}"
echo "Proceeding with deployment..."
deploy:
name: Deploy to Production
runs-on: ubuntu-latest
needs: [validate, approval]
if: always() && needs.validate.result == 'success' && (needs.approval.result == 'success' || needs.approval.result == 'skipped')
environment:
name: production
url: ${{ steps.deploy.outputs.url }}
permissions:
contents: read
packages: read
deployments: write
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create deployment
id: deployment
uses: chrnorm/deployment-action@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
environment: production
initial-status: in_progress
- name: Create backup marker
run: |
# Record current deployment for rollback capability
echo "PREVIOUS_VERSION=$(date +%Y%m%d%H%M%S)" > /tmp/deployment-backup.env
echo "DEPLOY_VERSION=${{ needs.validate.outputs.version }}" >> /tmp/deployment-backup.env
echo "DEPLOY_TIME=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> /tmp/deployment-backup.env
- name: Deploy to production environment
id: deploy
run: |
IMAGE_TAG="${{ needs.validate.outputs.image_tag }}"
echo "Deploying ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${IMAGE_TAG} to production..."
# Create deployment manifest
cat > /tmp/deploy-production.yaml << EOF
# Production Kubernetes/Docker deployment manifest
# Customize for your infrastructure
# For Kubernetes deployment:
# kubectl set image deployment/arctic-text2sql \
# app=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${IMAGE_TAG} \
# -n production
# kubectl rollout status deployment/arctic-text2sql -n production
# For AWS ECS deployment:
# aws ecs update-service --cluster production --service arctic-text2sql \
# --force-new-deployment
# aws ecs wait services-stable --cluster production --services arctic-text2sql
# For Docker Swarm deployment:
# docker service update --image ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${IMAGE_TAG} \
# arctic-text2sql
EOF
echo "url=https://api.text2sql.example.com" >> $GITHUB_OUTPUT
echo "Production deployment completed successfully"
- name: Update deployment status (success)
if: success()
uses: chrnorm/deployment-status@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
deployment-id: ${{ steps.deployment.outputs.deployment_id }}
state: success
environment-url: ${{ steps.deploy.outputs.url }}
- name: Update deployment status (failure)
if: failure()
uses: chrnorm/deployment-status@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
deployment-id: ${{ steps.deployment.outputs.deployment_id }}
state: failure
smoke-test:
name: Production Smoke Tests
runs-on: ubuntu-latest
needs: deploy
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Wait for deployment to stabilize
run: sleep 60
- name: Run production smoke tests
run: |
echo "Running smoke tests against production environment..."
# Health check
# curl -f https://api.text2sql.example.com/api/v1/health || exit 1
# Basic functionality check
# curl -f -X POST https://api.text2sql.example.com/api/v1/validate \
# -H "Content-Type: application/json" \
# -d '{"sql": "SELECT 1"}' || exit 1
echo "Production smoke tests passed (placeholder - configure actual endpoints)"
notify:
name: Deployment Notification
runs-on: ubuntu-latest
needs: [validate, deploy, smoke-test]
if: always()
steps:
- name: Notify success
if: needs.deploy.result == 'success' && needs.smoke-test.result == 'success'
run: |
echo "::notice::Successfully deployed ${{ needs.validate.outputs.version }} to production"
# Add Slack/Discord/Email notification here
# curl -X POST ${{ secrets.SLACK_WEBHOOK }} \
# -H "Content-Type: application/json" \
# -d '{"text": "Arctic Text2SQL ${{ needs.validate.outputs.version }} deployed to production"}'
- name: Notify failure
if: needs.deploy.result == 'failure' || needs.smoke-test.result == 'failure'
run: |
echo "::error::Production deployment failed for ${{ needs.validate.outputs.version }}"
# Add failure notification here