Skip to content

Commit f29f0b7

Browse files
committed
Build and Security scan Docker image
1 parent 8fb96ef commit f29f0b7

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

.github/workflows/build-image.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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

.github/workflows/scan-image.yaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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

0 commit comments

Comments
 (0)