@@ -2,7 +2,6 @@ package main
2
2
3
3
import (
4
4
"encoding/json"
5
- "fmt"
6
5
"log"
7
6
"os"
8
7
"strings"
@@ -16,15 +15,6 @@ import (
16
15
)
17
16
18
17
func RunTrivyImageScans (config * rest.Config , js nats.JetStreamContext ) error {
19
-
20
- pvcMountPath := "/mnt/agent/kbz"
21
- trivyImageCacheDir := fmt .Sprintf ("%s/trivy-imagecache" , pvcMountPath )
22
- err := os .MkdirAll (trivyImageCacheDir , 0755 )
23
- if err != nil {
24
- log .Printf ("Error creating Trivy Image cache directory: %v\n " , err )
25
- return err
26
- }
27
-
28
18
clearCacheCmd := "trivy image --clear-cache"
29
19
30
20
images , err := ListImages (config )
@@ -35,8 +25,7 @@ func RunTrivyImageScans(config *rest.Config, js nats.JetStreamContext) error {
35
25
36
26
for _ , image := range images {
37
27
var report types.Report
38
- scanCmd := fmt .Sprintf ("trivy image %s --timeout 60m -f json -q --cache-dir %s" , image .PullableImage , trivyImageCacheDir )
39
- out , err := executeCommand (scanCmd )
28
+ out , err := executeCommand ("trivy image " + image .PullableImage + " --timeout 60m -f json -q --cache-dir /tmp/.cache" )
40
29
if err != nil {
41
30
log .Printf ("Error scanning image %s: %v" , image .PullableImage , err )
42
31
continue // Move on to the next image in case of an error
@@ -85,3 +74,12 @@ func publishImageScanReports(report types.Report, js nats.JetStreamContext) erro
85
74
log .Printf ("Trivy image report with ID:%s has been published\n " , metrics .ID )
86
75
return nil
87
76
}
77
+
78
+ func cleanupCache (cacheDir string ) {
79
+ err := os .RemoveAll (cacheDir )
80
+ if err != nil {
81
+ log .Printf ("Failed to clean up cache directory %s: %v" , cacheDir , err )
82
+ } else {
83
+ log .Printf ("Cache directory %s cleaned up successfully" , cacheDir )
84
+ }
85
+ }
0 commit comments