-
Notifications
You must be signed in to change notification settings - Fork 0
124 lines (104 loc) · 3.75 KB
/
cd.yml
File metadata and controls
124 lines (104 loc) · 3.75 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
name: Continuous Deployment
on:
push:
branches: [ main ]
release:
types: [ published ]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
# Deploy to Staging
deploy-staging:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/develop'
environment: staging
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push images
run: |
docker build -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-backend:staging ./backend
docker build -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-frontend:staging ./frontend
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-backend:staging
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-frontend:staging
- name: Deploy to staging
run: |
echo "Deploying to staging environment..."
# Add your staging deployment commands here
# Example: kubectl apply -f k8s/staging/
# Deploy to Production
deploy-production:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' || github.event_name == 'release'
environment: production
needs: []
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract version
id: version
run: |
if [ "${{ github.event_name }}" = "release" ]; then
echo "version=${{ github.event.release.tag_name }}" >> $GITHUB_OUTPUT
else
echo "version=latest" >> $GITHUB_OUTPUT
fi
- name: Build and push production images
run: |
docker build -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-backend:${{ steps.version.outputs.version }} ./backend
docker build -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-frontend:${{ steps.version.outputs.version }} ./frontend
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-backend:${{ steps.version.outputs.version }}
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-frontend:${{ steps.version.outputs.version }}
- name: Deploy to production
run: |
echo "Deploying to production environment..."
# Add your production deployment commands here
# Example: kubectl apply -f k8s/production/
- name: Run smoke tests
run: |
echo "Running smoke tests..."
# Add smoke test commands here
# Example: curl -f https://api.stripeflow.com/health
- name: Notify deployment
if: always()
uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
channel: '#deployments'
webhook_url: ${{ secrets.SLACK_WEBHOOK }}
fields: repo,message,commit,author,action,eventName,ref,workflow
# Rollback on failure
rollback:
runs-on: ubuntu-latest
if: failure()
needs: [deploy-production]
steps:
- name: Rollback deployment
run: |
echo "Rolling back deployment..."
# Add rollback commands here
# Example: kubectl rollout undo deployment/stripeflow-backend
- name: Notify rollback
uses: 8398a7/action-slack@v3
with:
status: failure
channel: '#deployments'
webhook_url: ${{ secrets.SLACK_WEBHOOK }}
fields: repo,message,commit,author,action,eventName,ref,workflow