Skip to content

Commit e806b12

Browse files
committed
Merge branch 'dev' of https://github.com/Giabaoday/DevSecOps_Project into dev
2 parents fbf527d + 43982c6 commit e806b12

2 files changed

Lines changed: 84 additions & 48 deletions

File tree

.github/workflows/frontend.yml

Lines changed: 83 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
name: Frontend CI/CD
1+
name: Frontend CI/CD - Development
22
on:
33
push:
4-
branches: [ "main", "dev" ]
4+
branches: [ "dev" ]
55
paths:
66
- 'frontend/**'
7+
- 'helm/frontend/**'
78
pull_request:
8-
branches: [ "main", "dev" ]
9+
branches: [ "dev" ]
910
paths:
1011
- 'frontend/**'
12+
- 'helm/frontend/**'
1113

1214
env:
1315
AWS_REGION: ap-southeast-1
1416
SECRETS_MANAGER_SECRET_NAME: devsecops/tokens
17+
ENVIRONMENT: dev
1518

1619
jobs:
1720
GitLeaks:
@@ -31,7 +34,7 @@ jobs:
3134
Build:
3235
runs-on: ubuntu-latest
3336
needs: GitLeaks
34-
name: Unit Test and SAST
37+
name: Unit Test and Build
3538
steps:
3639
- uses: actions/checkout@v4
3740
- uses: actions/setup-node@v4
@@ -47,23 +50,44 @@ jobs:
4750
run: |
4851
cd frontend
4952
npm run test || true
50-
51-
SAST:
53+
54+
helm-validate:
5255
runs-on: ubuntu-latest
5356
needs: Build
57+
name: Validate Helm Chart
58+
steps:
59+
- name: Checkout code
60+
uses: actions/checkout@v4
61+
62+
- name: Install Helm
63+
uses: azure/setup-helm@v4
64+
with:
65+
version: '3.12.0'
66+
67+
- name: Lint Helm Chart
68+
run: |
69+
helm lint helm/frontend
70+
71+
- name: Template Helm Chart (Dev)
72+
run: |
73+
helm template whattoeat-frontend helm/frontend \
74+
--values helm/frontend/values-dev.yaml \
75+
--set image.tag=dev-test-tag
76+
77+
SAST:
78+
runs-on: ubuntu-latest
79+
needs: helm-validate
5480
name: SAST - SonarCloud
5581
steps:
5682
- uses: actions/checkout@v4
5783

58-
# AWS credentials
5984
- name: Configure AWS credentials
6085
uses: aws-actions/configure-aws-credentials@v4
6186
with:
6287
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
6388
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
6489
aws-region: ${{ env.AWS_REGION }}
6590

66-
# Lấy secrets từ AWS Secrets Manager
6791
- name: Get secrets from AWS Secrets Manager
6892
uses: aws-actions/aws-secretsmanager-get-secrets@v2
6993
with:
@@ -88,15 +112,13 @@ jobs:
88112
steps:
89113
- uses: actions/checkout@v4
90114

91-
# AWS credentials
92115
- name: Configure AWS credentials
93116
uses: aws-actions/configure-aws-credentials@v4
94117
with:
95118
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
96119
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
97120
aws-region: ${{ env.AWS_REGION }}
98121

99-
# Lấy secrets từ AWS Secrets Manager
100122
- name: Get secrets from AWS Secrets Manager
101123
uses: aws-actions/aws-secretsmanager-get-secrets@v2
102124
with:
@@ -112,11 +134,12 @@ jobs:
112134
with:
113135
command: test
114136
args: --file=frontend/package.json
115-
137+
116138
- name: OWASP Dependency Check
117139
uses: dependency-check/Dependency-Check_Action@main
140+
continue-on-error: true # Don't block dev workflow
118141
with:
119-
project: 'Frontend'
142+
project: 'Frontend-Dev'
120143
path: 'frontend'
121144
format: 'HTML'
122145
out: 'reports'
@@ -134,34 +157,29 @@ jobs:
134157
uses: zaproxy/action-baseline@v0.11.0
135158
continue-on-error: true
136159
with:
137-
target: 'https://dev.product-tracer.com/'
160+
target: 'https://example.com/'
138161
allow_issue_writing: false
139162
fail_action: false
140163
artifact_name: 'zap-scan-report'
141164

142165
docker:
143166
runs-on: ubuntu-latest
144-
needs: DAST
145-
name: Build, scan and push docker image to Docker Hub
167+
needs: SCA
168+
name: Build and push Docker image
146169
steps:
147170
- name: Checkout code
148171
uses: actions/checkout@v4
149172

150-
- name: Set up QEMU
151-
uses: docker/setup-qemu-action@v3
152-
153173
- name: Set up Docker Buildx
154174
uses: docker/setup-buildx-action@v3
155175

156-
# AWS credentials
157176
- name: Configure AWS credentials
158177
uses: aws-actions/configure-aws-credentials@v4
159178
with:
160179
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
161180
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
162181
aws-region: ${{ env.AWS_REGION }}
163182

164-
# Docker Hub credentials
165183
- name: Get Docker Hub secrets from AWS Secrets Manager
166184
uses: aws-actions/aws-secretsmanager-get-secrets@v2
167185
with:
@@ -171,76 +189,94 @@ jobs:
171189

172190
- name: Set version
173191
id: vars
174-
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
192+
run: |
193+
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
194+
echo "dev_tag=dev-$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
175195
176-
# Build Docker image nhưng chưa push
177-
- name: Build Docker image (without pushing)
196+
- name: Build Docker image
178197
uses: docker/build-push-action@v6
179198
with:
180199
push: false
181200
load: true
182201
build-args: |
183202
API_URL=https://vvbcaer9bc.execute-api.ap-southeast-1.amazonaws.com/default
184203
tags: |
185-
baotg0502/devsecops:latest
186-
baotg0502/devsecops:${{ steps.vars.outputs.sha_short }}
204+
baotg0502/devsecops:${{ steps.vars.outputs.dev_tag }}
205+
baotg0502/devsecops:dev-latest
187206
context: ./frontend
188207

189-
# Scan với Trivy
190208
- name: Run Trivy vulnerability scanner
191209
uses: aquasecurity/trivy-action@master
192210
with:
193-
image-ref: 'baotg0502/devsecops:latest'
211+
image-ref: 'baotg0502/devsecops:${{ steps.vars.outputs.dev_tag }}'
194212
format: 'table'
195-
exit-code: '1'
213+
exit-code: '0' # Don't fail on dev branch
196214
severity: 'CRITICAL,HIGH'
197215

198-
# Login và push sau khi scan thành công
199216
- name: Login to Docker Hub
200217
uses: docker/login-action@v3
201218
with:
202219
username: ${{ env.DEVSECOPS_TOKENS_DOCKERHUB_USERNAME }}
203220
password: ${{ env.DEVSECOPS_TOKENS_DOCKERHUB_TOKEN }}
204221

205-
# Push image lên Docker Hub
206222
- name: Push Docker image
207223
uses: docker/build-push-action@v6
208224
with:
209225
push: true
210226
build-args: |
211227
API_URL=https://vvbcaer9bc.execute-api.ap-southeast-1.amazonaws.com/default
212228
tags: |
213-
baotg0502/devsecops:latest
214-
baotg0502/devsecops:${{ steps.vars.outputs.sha_short }}
229+
baotg0502/devsecops:${{ steps.vars.outputs.dev_tag }}
230+
baotg0502/devsecops:dev-latest
215231
context: ./frontend
216232

217-
update-manifest:
233+
update-helm-values:
218234
runs-on: ubuntu-latest
219235
needs: docker
220-
name: Update Kubernetes Manifests
236+
name: Update Dev Helm Values
221237
permissions:
222-
contents: write # Cấp quyền ghi vào repository
238+
contents: write
223239
steps:
224240
- name: Checkout code
225241
uses: actions/checkout@v4
242+
with:
243+
token: ${{ secrets.GITHUB_TOKEN }}
226244

227245
- name: Set version
228246
id: vars
229-
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
247+
run: echo "dev_tag=dev-$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
230248

231-
- name: Update Kubernetes Deployment
249+
- name: Update Helm values for dev environment
232250
run: |
233-
# Cập nhật image tag trong file deployment.yaml
234-
sed -i "s|image: baotg0502/devsecops:.*|image: baotg0502/devsecops:${{ steps.vars.outputs.sha_short }}|g" kubernetes/frontend/deployment.yaml
251+
NEW_TAG="${{ steps.vars.outputs.dev_tag }}"
252+
VALUES_FILE="helm/frontend/values-dev.yaml"
235253
236-
# Xem file sau khi thay đổi
237-
cat kubernetes/frontend/deployment.yaml
254+
# Update the image tag in dev values file
255+
sed -i "s|tag: \".*\"|tag: \"${NEW_TAG}\"|g" $VALUES_FILE
238256
239-
# Cấu hình Git
240-
git config --global user.name "GitHub Actions"
241-
git config --global user.email "github-actions@github.com"
257+
echo "Updated $VALUES_FILE with new image tag: $NEW_TAG"
258+
cat $VALUES_FILE
242259
243-
# Commit và push thay đổi
244-
git add kubernetes/frontend/deployment.yaml
245-
git commit -m "Update frontend image to ${{ steps.vars.outputs.sha_short }} [skip ci]"
260+
- name: Commit and push changes
261+
run: |
262+
NEW_TAG="${{ steps.vars.outputs.dev_tag }}"
263+
264+
git config --global user.name "GitHub Actions [Dev]"
265+
git config --global user.email "github-actions-dev@github.com"
266+
267+
git add helm/frontend/values-dev.yaml
268+
git commit -m "🚀 Update dev frontend image to ${NEW_TAG} [skip ci]" || exit 0
246269
git push
270+
271+
notify-deployment:
272+
runs-on: ubuntu-latest
273+
needs: update-helm-values
274+
name: Notify Dev Deployment
275+
steps:
276+
- name: Development Deployment Notification
277+
run: |
278+
echo "🚀 Development deployment initiated!"
279+
echo "📋 Environment: Development"
280+
echo "🔄 ArgoCD will auto-sync the changes"
281+
echo "🔗 Monitor at: https://argocd.your-domain.com"
282+
echo "📱 Application: whattoeat-frontend-dev"

terraform/environments/dev/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ variable "public_subnets" {
4949
variable "app_version" {
5050
description = "Version of the application"
5151
type = string
52-
default = "c1e3dcf4512cc636f907e67f3868a92d4b70f838"
52+
default = "acccd4fefe50986ab48b887cd242dba0616a821e"
5353
}
5454

5555
variable "certificate_arn" {

0 commit comments

Comments
 (0)