File tree Expand file tree Collapse file tree 6 files changed +185
-48
lines changed
Expand file tree Collapse file tree 6 files changed +185
-48
lines changed Original file line number Diff line number Diff line change 1+ name : Build Image Video Service
2+
3+ on :
4+ workflow_call :
5+ secrets :
6+ DOCKER_HUB_ACCESS_TOKEN :
7+ required : true
8+
9+ jobs :
10+ build-image :
11+ name : Build and Push Docker Image
12+ runs-on : ubuntu-latest
13+ steps :
14+ - name : Checkout code
15+ uses : actions/checkout@v3
16+
17+ - name : Setup JDK 17
18+ uses : actions/setup-java@v3
19+ with :
20+ distribution : ' corretto'
21+ java-version : 17
22+
23+ - name : Login to Docker Hub
24+ uses : docker/login-action@v2
25+ with :
26+ username : datuits
27+ password : ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
28+
29+ - name : Build the application
30+ run : |
31+ mvn clean
32+ mvn -B package --file pom.xml
33+
34+ - name : Build and Push the docker image
35+ run : |
36+ docker build -t datuits/devops-video-service:latest .
37+ docker push datuits/devops-video-service:latest
Original file line number Diff line number Diff line change 66 - main
77
88jobs :
9- build-deploy :
10- name : Build and Deploy Comment Service
9+ testing :
10+ name : Testing Video Service
1111 runs-on : ubuntu-latest
1212 steps :
13+
1314 - name : Checkout code
1415 uses : actions/checkout@v3
1516
2324 run : echo "SPRING_DATA_MONGODB_URI=mongodb://localhost:27017/video-service" >> $GITHUB_ENV
2425
2526 - name : Unit Tests
26- run : mvn -B test --file pom.xml
27+ run : mvn -B test --file pom.xml
28+
29+ # - name: SonarQube Scan
30+ # env:
31+ # SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
32+ # run: mvn org.sonarsource.scanner.maven:sonar-maven-plugin:4.0.0.4121:sonar \
33+ # -Dsonar.projectKey=devops-video-sharing \
34+ # -Dsonar.host.url=https://sonarcloud.io \
35+ # -Dsonar.login=${{ secrets.SONAR_TOKEN }}
36+
37+ build-image :
38+ needs : testing
39+ uses : ./.github/workflows/build-image.yaml
40+ secrets :
41+ DOCKER_HUB_ACCESS_TOKEN : ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
42+
43+ scan-image :
44+ needs : build-image
45+ uses : ./.github/workflows/scan-image.yaml
46+
47+ notify :
48+ needs : scan-image
49+ uses : ./.github/workflows/notifyCI.yaml
50+ secrets :
51+ SLACK_WEBHOOK_URL : ${{ secrets.SLACK_WEBHOOK_URL }}
Original file line number Diff line number Diff line change 1+ name : Send Slack Notification for Video Service
2+
3+ on :
4+ workflow_call :
5+ secrets :
6+ SLACK_WEBHOOK_URL :
7+ required : true
8+
9+ jobs :
10+ success_notifier :
11+ if : ${{ github.event.workflow_run.conclusion == 'success' }}
12+ runs-on : ubuntu-latest
13+ steps :
14+ - name : Send success notification on Slack
15+ 16+ with :
17+ payload : |
18+ {
19+ "text": "The Continuous Integration for Video Service workflow has completed successfully."
20+ }
21+ env :
22+ SLACK_WEBHOOK_URL : ${{ secrets.SLACK_WEBHOOK_URL }}
23+
24+ failure_notifier :
25+ if : ${{ github.event.workflow_run.conclusion != 'success' }}
26+ runs-on : ubuntu-latest
27+ steps :
28+ - name : Send failure notification on Slack
29+ 30+ with :
31+ payload : |
32+ {
33+ "text": "The Continuous Integration for Video Service workflow has failed."
34+ }
35+ env :
36+ SLACK_WEBHOOK_URL : ${{ secrets.SLACK_WEBHOOK_URL }}
Original file line number Diff line number Diff line change 1+ name : Scan Image Video Service
2+ on :
3+ workflow_call :
4+
5+ jobs :
6+ scan-image :
7+ name : Security Scan
8+ runs-on : ubuntu-latest
9+ steps :
10+ - name : Install Trivy
11+ run : |
12+ sudo apt-get update
13+ sudo apt-get install -y wget
14+ wget https://github.com/aquasecurity/trivy/releases/download/v0.40.0/trivy_0.40.0_Linux-64bit.deb
15+ sudo dpkg -i trivy_0.40.0_Linux-64bit.deb
16+
17+ - name : Scan Docker image with Trivy
18+ id : scan-image
19+ run : |
20+ trivy image --format json --output scan-results.json datuits/devops-video-service:latest
21+
22+ - name : Extract high and critical vulnerabilities
23+ id : extract_vulnerabilities
24+ run : |
25+ jq -r '
26+ def hr(severity):
27+ if severity == "HIGH" or severity == "CRITICAL" then true else false end;
28+ def to_md:
29+ "| " + (.VulnerabilityID // "") + " | " + (.PkgName // "") + " | " + (.InstalledVersion // "") + " | " + (.Severity // "") + " | " + (.Title // "") + " |";
30+ [
31+ "# Docker Image Scan Results",
32+ "",
33+ "## High and Critical Vulnerabilities",
34+ "",
35+ "| Vulnerability ID | Package | Version | Severity | Description |",
36+ "|------------------|---------|---------|----------|-------------|",
37+ (.Results[] | .Vulnerabilities[] | select(hr(.Severity)) | to_md),
38+ ""
39+ ] | join("\n")
40+ ' scan-results.json > vulnerability-report.md
41+
42+ - name : Upload vulnerability report
43+ uses : actions/upload-artifact@v2
44+ with :
45+ name : vulnerability-report
46+ path : vulnerability-report.md
Original file line number Diff line number Diff line change 1+ apiVersion : apps/v1
2+ kind : Deployment
3+ metadata :
4+ name : video-mongo-deployment
5+ spec :
6+ replicas : 1
7+ selector :
8+ matchLabels :
9+ app : mongo
10+ template :
11+ metadata :
12+ labels :
13+ app : mongo
14+ spec :
15+ containers :
16+ - name : mongo
17+ image : mongo:latest
18+ ports :
19+ - containerPort : 27017
20+ env :
21+ - name : MONGO_INITDB_DATABASE
22+ value : video-service
23+ resources :
24+ limits :
25+ memory : 512Mi
26+ cpu : " 1"
27+ ---
28+ apiVersion : v1
29+ kind : Service
30+ metadata :
31+ name : video-mongo-service
32+ spec :
33+ selector :
34+ app : mongo
35+ ports :
36+ - protocol : TCP
37+ port : 27017
38+ targetPort : 27017
Original file line number Diff line number Diff line change 1- apiVersion : apps/v1
2- kind : Deployment
3- metadata :
4- name : video-mongo-deployment
5- spec :
6- replicas : 1
7- selector :
8- matchLabels :
9- app : mongo
10- template :
11- metadata :
12- labels :
13- app : mongo
14- spec :
15- containers :
16- - name : mongo
17- image : mongo:latest
18- ports :
19- - containerPort : 27017
20- env :
21- - name : MONGO_INITDB_DATABASE
22- value : video-service
23- resources :
24- requests :
25- memory : 128Mi
26- cpu : " 0.2"
27- limits :
28- memory : 256Mi
29- cpu : " 1"
30- ---
31- apiVersion : v1
32- kind : Service
33- metadata :
34- name : video-mongo-service
35- spec :
36- selector :
37- app : mongo
38- ports :
39- - protocol : TCP
40- port : 27017
41- targetPort : 27017
42-
431---
442apiVersion : apps/v1
453kind : Deployment
6624 - name : SPRING_DATA_MONGODB_URI
6725 value : mongodb://video-mongo-service:27017/video-service
6826 resources :
69- requests :
70- memory : 256Mi
71- cpu : " 0.4"
7227 limits :
7328 memory : 512Mi
7429 cpu : " 1"
You can’t perform that action at this time.
0 commit comments