-
Notifications
You must be signed in to change notification settings - Fork 3
198 lines (176 loc) · 6.38 KB
/
cd.yml
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
name: Continuous Deployment
on:
workflow_run:
workflows: ["Continuous Integration"]
types: [completed]
branches: [main]
env:
NODE_VERSION: '18.x'
DOCKER_REGISTRY: ${{ secrets.DOCKER_REGISTRY }}
DEPLOYMENT_TIMEOUT: '300'
HEALTH_CHECK_RETRIES: '5'
VITE_API_URL: ${{ secrets.API_URL }}
jobs:
prepare-deployment:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
outputs:
deployment_id: ${{ steps.create_deployment.outputs.deployment_id }}
steps:
- name: Create Deployment
id: create_deployment
run: |
DEPLOY_ID=$(date +%s)
echo "deployment_id=${DEPLOY_ID}" >> $GITHUB_OUTPUT
deploy-backend:
needs: prepare-deployment
runs-on: ubuntu-latest
environment: production
concurrency:
group: production_backend
cancel-in-progress: false
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
version: latest
buildkitd-flags: --debug
- name: Login to Container Registry
uses: docker/login-action@v2
with:
registry: ${{ env.DOCKER_REGISTRY }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and Push Backend Image
uses: docker/build-push-action@v3
with:
context: ./src/backend
file: ./src/backend/Dockerfile
push: true
tags: |
${{ env.DOCKER_REGISTRY }}/backend:${{ github.sha }}
${{ env.DOCKER_REGISTRY }}/backend:latest
cache-from: type=registry,ref=${{ env.DOCKER_REGISTRY }}/backend:buildcache
cache-to: type=registry,ref=${{ env.DOCKER_REGISTRY }}/backend:buildcache,mode=max
build-args: |
NODE_ENV=production
labels: |
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.version=${{ needs.prepare-deployment.outputs.deployment_id }}
- name: Deploy to Replit
env:
REPLIT_TOKEN: ${{ secrets.REPLIT_TOKEN }}
run: |
echo "Deploying backend service..."
# Add Replit deployment commands here
- name: Health Check Backend
run: |
attempts=0
max_attempts=${{ env.HEALTH_CHECK_RETRIES }}
until curl -s -f "${API_URL}/health" || [ $attempts -eq $max_attempts ]
do
attempts=$((attempts + 1))
echo "Attempt $attempts of $max_attempts"
sleep 10
done
if [ $attempts -eq $max_attempts ]; then
echo "Backend health check failed after $max_attempts attempts"
exit 1
fi
deploy-frontend:
needs: [prepare-deployment, deploy-backend]
runs-on: ubuntu-latest
environment: production
concurrency:
group: production_frontend
cancel-in-progress: false
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
version: latest
buildkitd-flags: --debug
- name: Login to Container Registry
uses: docker/login-action@v2
with:
registry: ${{ env.DOCKER_REGISTRY }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and Push Frontend Image
uses: docker/build-push-action@v3
with:
context: ./src/web
file: ./src/web/Dockerfile
push: true
tags: |
${{ env.DOCKER_REGISTRY }}/frontend:${{ github.sha }}
${{ env.DOCKER_REGISTRY }}/frontend:latest
cache-from: type=registry,ref=${{ env.DOCKER_REGISTRY }}/frontend:buildcache
cache-to: type=registry,ref=${{ env.DOCKER_REGISTRY }}/frontend:buildcache,mode=max
build-args: |
API_URL=${{ secrets.API_URL }}
NODE_ENV=production
labels: |
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.version=${{ needs.prepare-deployment.outputs.deployment_id }}
- name: Deploy to Replit
env:
REPLIT_TOKEN: ${{ secrets.REPLIT_TOKEN }}
run: |
echo "Deploying frontend service..."
# Add Replit deployment commands here
- name: Health Check Frontend
run: |
attempts=0
max_attempts=${{ env.HEALTH_CHECK_RETRIES }}
until curl -s -f "${VITE_API_URL}" || [ $attempts -eq $max_attempts ]
do
attempts=$((attempts + 1))
echo "Attempt $attempts of $max_attempts"
sleep 10
done
if [ $attempts -eq $max_attempts ]; then
echo "Frontend health check failed after $max_attempts attempts"
exit 1
fi
post-deployment:
needs: [deploy-backend, deploy-frontend]
runs-on: ubuntu-latest
steps:
- name: Update Deployment Status
run: |
echo "Deployment completed successfully"
echo "Deployment ID: ${{ needs.prepare-deployment.outputs.deployment_id }}"
echo "Commit SHA: ${{ github.sha }}"
- name: Notify Monitoring Systems
if: always()
run: |
# Add monitoring notification logic here
echo "Notifying monitoring systems of deployment status"
- name: Verify Deployment
run: |
# Add comprehensive deployment verification
echo "Running post-deployment verification checks"
rollback:
needs: [deploy-backend, deploy-frontend]
if: failure()
runs-on: ubuntu-latest
steps:
- name: Initiate Rollback
run: |
echo "Deployment failed - initiating rollback procedure"
# Add rollback logic here
- name: Notify Emergency Contacts
if: always()
run: |
echo "Notifying emergency contacts of deployment failure and rollback status"