Skip to content

Commit aea4ae6

Browse files
committed
2 parents edca68e + 8b1288b commit aea4ae6

File tree

6 files changed

+185
-48
lines changed

6 files changed

+185
-48
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/main.yaml

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ on:
66
- main
77

88
jobs:
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

@@ -23,4 +24,28 @@ jobs:
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 }}

.github/workflows/notifyCI.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
uses: slackapi/[email protected]
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+
uses: slackapi/[email protected]
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 }}

.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

database.yaml

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

resources.yaml

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,3 @@
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
---
442
apiVersion: apps/v1
453
kind: Deployment
@@ -66,9 +24,6 @@ spec:
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"

0 commit comments

Comments
 (0)