forked from soulpage/fullstack-assignment
-
Notifications
You must be signed in to change notification settings - Fork 0
265 lines (253 loc) · 9.03 KB
/
main.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
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
264
265
name: ChatGPT Workflow
on:
push:
branches:
- main
- ujwal-devops
- ujwal-cicd
paths:
- ".github/workflows/main.yml"
- "backend/**"
- "frontend/**"
- "images/**"
- "prompts/**"
pull_request:
types: [synchronize]
workflow_dispatch:
defaults:
run:
shell: bash
permissions:
actions: write
contents: write
jobs:
# SonarQube-Analysis:
# runs-on: ubuntu-24.04
# steps:
# - name: Checkout Code
# uses: actions/checkout@v4
# with:
# ref: ${{ github.ref_name }}
# - name: Setup Environment variables
# run: echo -e ${{ secrets.SONAR_PROPERTIES }} > sonar-project.properties
# - name: Sonar Scan
# uses: SonarSource/sonarcloud-github-action@master
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
# Build-App-Backend:
# runs-on: ubuntu-22.04
# needs: [SonarQube-Analysis]
# defaults:
# run:
# shell: bash
# working-directory: backend/
# steps:
# - name: Checkout Code
# uses: actions/checkout@v4
# with:
# ref: ${{ github.ref_name }}
# - name: Setup Python Environment
# uses: actions/setup-python@v5
# with:
# python-version: "3.11"
# - name: Install PM2
# run: npm install -g pm2
# - name: Setup Env variables
# run: |
# echo -e ${{ secrets.BACKEND_ENV }} > .env
# - name: Install Dependencies
# run: pwd && pip install -r dependencies.txt
# - name: Make Migrations
# run: python manage.py migrate
# - name: Collect Static Content
# run: python manage.py collectstatic
# - name: Start App
# run: pm2 start "gunicorn backend.wsgi:application -b 0.0.0.0:8000 --reload" --name backend
# Build-App-Frontend:
# runs-on: ubuntu-22.04
# needs: [SonarQube-Analysis]
# defaults:
# run:
# shell: bash
# working-directory: frontend/
# steps:
# - name: Checkout Code
# uses: actions/checkout@v4
# with:
# ref: ${{ github.ref_name }}
# - name: Setup node Environment
# uses: actions/setup-node@v4
# with:
# node-version: 18.20.5
# - name: Install PM2
# run: npm install -g pm2
# - name: Setup Env variables
# run: |
# echo -e ${{ secrets.FRONTEND_ENV }} > .env.local
# - name: Install Dependencies
# run: pwd && npm install
# - name: Static Build
# run: npm run build
# - name: Start App
# run: pm2 start "npm start" --name frontend
# Image-Vuln-Check-Backend:
# runs-on: ubuntu-24.04
# needs: [Build-App-Backend]
# continue-on-error: true
# defaults:
# run:
# shell: bash
# working-directory: backend/
# steps:
# - name: Checkout Code
# uses: actions/checkout@v4
# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v3
# - name: Build Docker Image
# run: docker build -t docker.io/${{ vars.DOCKERHUB_USERNAME }}/chatgpt-backend:${{ github.sha }} .
# - name: Run Trivy Vulnerability Scanner
# uses: aquasecurity/trivy-action@0.20.0
# with:
# image-ref: "docker.io/${{ vars.DOCKERHUB_USERNAME }}/chatgpt-backend:${{ github.sha }}"
# format: "table"
# exit-code: "1"
# ignore-unfixed: true
# output: trivy-report-backend.txt
# vuln-type: "os,library"
# severity: "CRITICAL,HIGH"
# - name: Upload Artifact
# uses: actions/upload-artifact@v4
# with:
# name: trivy-report-backend
# path: trivy-report-backend.txt
# Image-Vuln-Check-Frontend:
# runs-on: ubuntu-24.04
# needs: [Build-App-Frontend]
# continue-on-error: true
# defaults:
# run:
# shell: bash
# working-directory: frontend/
# steps:
# - name: Checkout Code
# uses: actions/checkout@v4
# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v3
# - name: Build Docker Image
# run: docker build -t docker.io/${{ vars.DOCKERHUB_USERNAME }}/chatgpt-frontend:${{ github.sha }} .
# - name: Run Trivy Vulnerability Scanner
# uses: aquasecurity/trivy-action@0.20.0
# with:
# image-ref: "docker.io/${{ vars.DOCKERHUB_USERNAME }}/chatgpt-frontend:${{ github.sha }}"
# format: "table"
# exit-code: "1"
# ignore-unfixed: true
# output: trivy-report-frontend.txt
# vuln-type: "os,library"
# severity: "CRITICAL,HIGH"
# - name: Upload Artifact
# uses: actions/upload-artifact@v4
# with:
# name: trivy-report-frontend
# path: trivy-report-frontend.txt
Push-To-DockerHub-Backend:
runs-on: ubuntu-24.04
# needs: [Image-Vuln-Check-Backend]
defaults:
run:
shell: bash
working-directory: backend/
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
ref: ${{ github.ref_name }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Registry
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Building Docker Image
run: docker build . -t ${{ vars.DOCKERHUB_USERNAME }}/chatgpt-backend:1.${{ github.run_number }}.${{ github.run_attempt}}
- name: Pushing Docker Image
run: docker push ${{ vars.DOCKERHUB_USERNAME }}/chatgpt-backend:1.${{ github.run_number }}.${{ github.run_attempt}}
# - name: Build and push
# uses: docker/build-push-action@v6
# with:
# file: backend/Dockerfile
# push: true
# tags: ${{ vars.DOCKERHUB_USERNAME }}/chatgpt-backend:1.${{ github.run_number }}.${{ github.run_attempt}}
Push-To-DockerHub-Frontend:
runs-on: ubuntu-24.04
# needs: [Image-Vuln-Check-Frontend]
defaults:
run:
shell: bash
working-directory: frontend/
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
ref: ${{ github.ref_name }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Registry
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Building Docker Image
run: docker build . -t ${{ vars.DOCKERHUB_USERNAME }}/chatgpt-frontend:1.${{ github.run_number }}.${{ github.run_attempt}}
- name: Pushing Docker Image
run: docker push ${{ vars.DOCKERHUB_USERNAME }}/chatgpt-frontend:1.${{ github.run_number }}.${{ github.run_attempt}}
# - name: Build and push
# uses: docker/build-push-action@v6
# with:
# file: frontend/Dockerfile
# push: true
# tags: ${{ vars.DOCKERHUB_USERNAME }}/chatgpt-frontend:1.${{ github.run_number }}.${{ github.run_attempt}}
Update-Helm-Chart-Backend:
runs-on: ubuntu-24.04
needs: [Push-To-DockerHub-Backend]
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Update tag in Helm chart
run: |
sed -i 's/tag: .*/tag: "1.${{ github.run_number }}.${{ github.run_attempt}}"/' helm/charts/chatgpt-backend/values.yaml
- name: Update tag in K8s Deployment
run: |
sed -i 's|\(uj5ghare/chatgpt-backend:\)[^[:space:]]*|\1"1.${{ github.run_number }}.${{ github.run_attempt}}"|' k8s/manifests/backend/deployment.yml
- name: Commit and push changes
run: |
git config --global user.email "${{ secrets.GH_USER_MAIL }}"
git config --global user.name "${{ vars.GH_USER_NAME }}"
git add .
git commit -m "[helm] Updated tag in chatgpt-backend/values.yaml && [k8s] updated backend deployment image tag"
git push
Update-Helm-Chart-Frontend:
runs-on: ubuntu-24.04
needs: [Push-To-DockerHub-Frontend]
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Update tag in Helm chart
run: |
sed -i 's/tag: .*/tag: "1.${{ github.run_number }}.${{ github.run_attempt}}"/' helm/charts/chatgpt-frontend/values.yaml
- name: Update tag in K8s Deployment
run: |
sed -i 's|\(uj5ghare/chatgpt-frontend:\)[^[:space:]]*|\1"1.${{ github.run_number }}.${{ github.run_attempt}}"|' k8s/manifests/frontend/deployment.yml
- name: Commit and push changes
run: |
git config --global user.email "${{ secrets.GH_USER_MAIL }}"
git config --global user.name "${{ vars.GH_USER_NAME }}"
git add .
git commit -m "[helm] Updated tag in chatgpt-frontend/values.yaml && [k8s] updated frontend deployment image tag"
git push