File tree Expand file tree Collapse file tree 5 files changed +190
-0
lines changed
Expand file tree Collapse file tree 5 files changed +190
-0
lines changed Original file line number Diff line number Diff line change 1+ name : Build Image Frontend
2+
3+ on :
4+ workflow_call :
5+ secrets :
6+
7+ DOCKER_HUB_ACCESS_TOKEN :
8+ required : true
9+
10+ jobs :
11+ build-image :
12+ name : Build and Push Docker Image
13+ runs-on : ubuntu-latest
14+ steps :
15+ - name : Build Docker Image
16+ 17+ with :
18+ push : false
19+ tags : datuits/devops-frontend:latest
20+
21+ - name : Login to Docker Hub
22+ uses : docker/login-action@v1
23+ with :
24+ username : datuits
25+ password : ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
26+
27+ - name : Push to Docker Hub
28+ uses : docker/build-push-action@v2
29+ with :
30+ push : true
31+ tags : datuits/devops-frontend:latest
Original file line number Diff line number Diff line change 1+ name : Continuous Integration for Frontend
2+
3+ on :
4+ push :
5+ branches :
6+ - main
7+
8+ jobs :
9+ testing :
10+ name : Testing Frontend
11+ runs-on : ubuntu-latest
12+
13+ strategy :
14+ matrix :
15+ node-version : [18.x]
16+
17+ steps :
18+ - name : Checkout code
19+ uses : actions/checkout@v3
20+
21+ - name : Use Node.js ${{ matrix.node-version }}
22+ uses : actions/setup-node@v3
23+ with :
24+ node-version : ${{ matrix.node-version }}
25+
26+ - name : Run Build App
27+ run :
28+ npm ci
29+ npm run build
30+ env :
31+ CI : " "
32+
33+ - name : Set up MongoDB URI
34+ run : echo "SPRING_DATA_MONGODB_URI=mongodb://localhost:27017/frontend" >> $GITHUB_ENV
35+
36+ # sonar-cloud-scan:
37+ # needs: testing
38+ # uses: ./.github/workflows/sonarqube-scan.yaml
39+ # secrets:
40+ # SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
41+
42+ build-image :
43+ needs : testing
44+ uses : ./.github/workflows/build-image.yaml
45+ secrets :
46+ DOCKER_HUB_ACCESS_TOKEN : ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
47+
48+ # scan-image:
49+ # needs: build-image
50+ # uses: ./.github/workflows/scan-image.yaml
51+
52+ # notify:
53+ # needs: scan-image
54+ # uses: ./.github/workflows/notifyCI.yaml
55+ # secrets:
56+ # SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
57+
58+ # ## Push image ###
Original file line number Diff line number Diff line change 1+ name : Send Slack Notification for Frontend
2+
3+ on :
4+ workflow_call :
5+ secrets :
6+ SLACK_WEBHOOK_URL :
7+ required : true
8+
9+ jobs :
10+ success_notifier :
11+ if : 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 Frontend workflow has completed successfully."
20+ }
21+ env :
22+ SLACK_WEBHOOK_URL : ${{ secrets.SLACK_WEBHOOK_URL }}
23+
24+ failure_notifier :
25+ if : failure()
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 Frontend 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 Frontend
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-frontend: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
47+
Original file line number Diff line number Diff line change 1+ name : SonarCloud for Frontend
2+ on :
3+ workflow_call :
4+ secrets :
5+ SONAR_TOKEN :
6+ required : true
7+ jobs :
8+ sonarcloud-scan :
9+ name : SonarCloud
10+ runs-on : ubuntu-latest
11+ steps :
12+ - uses : actions/checkout@v3
13+ with :
14+ fetch-depth : 0 # Shallow clones should be disabled for a better relevancy of analysis
15+ - name : SonarCloud Scan
16+ uses : SonarSource/sonarcloud-github-action@master
17+ env :
18+ SONAR_TOKEN : ${{ secrets.SONAR_TOKEN }}
You can’t perform that action at this time.
0 commit comments