Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
fix: Configure Trivy cache dir in the main container (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpacak authored Sep 29, 2019
1 parent 7ca7e12 commit 084cfd5
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ curl -v http://localhost:8080/api/v1/metadata
| `SCANNER_API_ADDR` | `:8080` | Binding address for the API server. |
| `SCANNER_API_READ_TIMEOUT` | `15s` | The maximum duration for reading the entire request, including the body. |
| `SCANNER_API_WRITE_TIMEOUT` | `15s` | The maximum duration before timing out writes of the response. |
| `SCANNER_TRIVY_CACHE_DIR` | `/root/.cache`/ | Trivy cache directory. |
| `SCANNER_STORE_REDIS_URL` | `redis://localhost:6379` | Redis server URI for a redis store. |
| `SCANNER_STORE_REDIS_NAMESPACE` | `harbor.scanner.trivy:data-store` | A namespace for keys in a redis store. |
| `SCANNER_STORE_REDIS_POOL_MAX_ACTIVE` | 5 | The max number of connections allocated by the pool for a redis store. |
Expand Down
4 changes: 1 addition & 3 deletions kube/harbor-scanner-trivy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ spec:
env:
- name: "SCANNER_API_ADDR"
value: ":8080"
- name: "SCANNER_TRIVY_DIR"
- name: "SCANNER_TRIVY_CACHE_DIR"
value: "/root/.cache"
- name: "SCANNER_DATA_DIR"
value: "/data/scanner"
- name: "SCANNER_STORE_REDIS_URL"
value: "redis://harbor-harbor-redis:6379"
- name: "SCANNER_JOB_QUEUE_REDIS_URL"
Expand Down
3 changes: 1 addition & 2 deletions pkg/etc/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import (
)

type WrapperConfig struct {
TrivyCacheDir string
ScannerDataDir string
TrivyCacheDir string `env:"SCANNER_TRIVY_CACHE_DIR" envDefault:"/root/.cache"`
}

type APIConfig struct {
Expand Down
23 changes: 23 additions & 0 deletions pkg/etc/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,29 @@ import (
"testing"
)

func TestGetWrapperConfig(t *testing.T) {
testCases := []struct {
Name string
Envs map[string]string
ExpectedError error
ExpectedConfig WrapperConfig
}{
{
Name: "Should return default config",
ExpectedConfig: WrapperConfig{
TrivyCacheDir: "/root/.cache",
},
},
}
for _, tc := range testCases {
t.Run(tc.Name, func(t *testing.T) {
config, err := GetWrapperConfig()
assert.Equal(t, tc.ExpectedError, err)
assert.Equal(t, tc.ExpectedConfig, config)
})
}
}

func TestGetRedisStoreConfig(t *testing.T) {
testCases := []struct {
Name string
Expand Down
2 changes: 1 addition & 1 deletion pkg/trivy/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (w *wrapper) Run(imageRef string, auth RegistryAuth) (report trivy.ScanResu
return report, err
}

reportFile, err := ioutil.TempFile(w.config.ScannerDataDir, "report-*.json")
reportFile, err := ioutil.TempFile("", "trivy-scan-report-*.json")
if err != nil {
return report, err
}
Expand Down

0 comments on commit 084cfd5

Please sign in to comment.