Skip to content

Commit

Permalink
Merge 85811ed into 30f468f
Browse files Browse the repository at this point in the history
  • Loading branch information
matthyx committed Jul 13, 2023
2 parents 30f468f + 85811ed commit 9cd9def
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 10 deletions.
12 changes: 11 additions & 1 deletion adapters/v1/grype.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,21 @@ func (g *GrypeAdapter) Ready(ctx context.Context) bool {
logger.L().Info("updating grype DB",
helpers.String("listingURL", g.dbConfig.ListingURL))
var err error
g.store, g.dbStatus, g.dbCloser, err = grype.LoadVulnerabilityDB(g.dbConfig, true)
newStore, newDbStatus, newDbCloser, err := grype.LoadVulnerabilityDB(g.dbConfig, true)
if err != nil {
logger.L().Ctx(ctx).Error("failed to update grype DB", helpers.Error(err))
if g.dbCloser != nil {
g.dbCloser.Close()
logger.L().Debug("closed DB")
}
err := tools.DeleteContents(g.dbConfig.DBRootDir)
logger.L().Debug("cleaned up cache", helpers.Error(err),
helpers.String("DBRootDir", g.dbConfig.DBRootDir))
return false
}
g.store = newStore
g.dbStatus = newDbStatus
g.dbCloser = newDbCloser
g.lastDbUpdate = now
logger.L().Info("grype DB updated")
return true
Expand Down
14 changes: 7 additions & 7 deletions build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
FROM golang:1.20-alpine as builder
FROM --platform=$BUILDPLATFORM golang:1.20-alpine as builder

ENV GO111MODULE=on CGO_ENABLED=0
WORKDIR /work
ARG TARGETOS TARGETARCH

ADD go.mod go.sum /work/
RUN go mod download

ADD . .
RUN go build -o build/kubevuln cmd/http/main.go
RUN --mount=target=. \
--mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o /out/kubevuln cmd/http/main.go

FROM alpine

RUN addgroup -S ks && adduser -S ks -G ks
USER ks
WORKDIR /home/ks/

COPY --from=builder /work/build/kubevuln /usr/bin/kubevuln
COPY --from=builder /out/kubevuln /usr/bin/kubevuln

ARG image_version
ENV RELEASE=$image_version
Expand Down
4 changes: 2 additions & 2 deletions build/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ git clone https://github.com/kubescape/kubevuln.git kubevuln && cd "$_"

2. Build
```
docker build -t kubevuln -f build/Dockerfile .
```
docker buildx build -t kubevuln -f build/Dockerfile --load .
```
15 changes: 15 additions & 0 deletions internal/tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tools
import (
"encoding/json"
"os"
"path"
"regexp"
"runtime/debug"
"testing"
Expand Down Expand Up @@ -83,3 +84,17 @@ func FileToCVEManifest(path string) domain.CVEManifest {
}
return cve
}

func DeleteContents(dir string) error {
d, err := os.ReadDir(dir)
if err != nil {
return err
}
for _, c := range d {
err := os.RemoveAll(path.Join([]string{dir, c.Name()}...))
if err != nil {
return err
}
}
return nil
}

0 comments on commit 9cd9def

Please sign in to comment.