Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 22eab57

Browse files
committed
fix issue when using --file flag with the snyk containerized provider
Signed-off-by: Guillaume Lours <guillaume.lours@docker.com>
1 parent de4c2c6 commit 22eab57

3 files changed

Lines changed: 45 additions & 15 deletions

File tree

.github/workflows/build-pr.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ jobs:
5858
- name: Download binaries
5959
run: make -f builder.Makefile download
6060

61-
- name: Build binary and run tests
62-
run: make TAG_NAME=${{ github.event.inputs.tag }} -f builder.Makefile build e2e
61+
- name: Build binary
62+
run: make TAG_NAME=${{ github.event.inputs.tag }} -f builder.Makefile build
6363

6464
- name: Build Cross
6565
run: make cross
@@ -68,7 +68,7 @@ jobs:
6868
run: make test-unit
6969

7070
- name: End-to-end Tests
71-
run: make e2e
71+
run: make TAG_NAME=${{ github.event.inputs.tag }} -f builder.Makefile e2e
7272

7373
- name: Upload binary artifact
7474
uses: actions/upload-artifact@v2

e2e/scan_test.go

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"fmt"
2222
"io/ioutil"
2323
"os"
24+
"path"
2425
"path/filepath"
2526
"runtime"
2627
"strings"
@@ -110,7 +111,7 @@ func TestScanSucceedWithDockerHub(t *testing.T) {
110111
}
111112

112113
func TestScanWithSnyk(t *testing.T) {
113-
if runtime.GOOS == "windows" || runtime.GOOS == "darwin" {
114+
if runtime.GOOS != "linux" {
114115
t.Skip("Can't run on this ci platform (windows containers or no engine installed)")
115116
}
116117
_, cleanFunction := createSnykConfFile(t, os.Getenv("E2E_TEST_AUTH_TOKEN"))
@@ -164,7 +165,7 @@ func TestScanWithSnyk(t *testing.T) {
164165
}
165166

166167
func TestScanJsonOutput(t *testing.T) {
167-
if runtime.GOOS == "windows" || runtime.GOOS == "darwin" {
168+
if runtime.GOOS != "linux" {
168169
t.Skip("Can't run on this ci platform (windows containers or no engine installed)")
169170
}
170171
_, cleanFunction := createSnykConfFile(t, os.Getenv("E2E_TEST_AUTH_TOKEN"))
@@ -216,7 +217,7 @@ type JSONOutput struct {
216217
}
217218

218219
func TestScanWithFileAndExcludeBaseImageVulns(t *testing.T) {
219-
if runtime.GOOS == "windows" || runtime.GOOS == "darwin" {
220+
if runtime.GOOS != "linux" {
220221
t.Skip("Can't run on this ci platform (windows containers or no engine installed)")
221222
}
222223
_, cleanFunction := createSnykConfFile(t, os.Getenv("E2E_TEST_AUTH_TOKEN"))
@@ -233,7 +234,7 @@ func TestScanWithFileAndExcludeBaseImageVulns(t *testing.T) {
233234
}
234235

235236
func TestScanWithExcludeBaseImageVulns(t *testing.T) {
236-
if runtime.GOOS == "windows" || runtime.GOOS == "darwin" {
237+
if runtime.GOOS != "linux" {
237238
t.Skip("Can't run on this ci platform (windows containers or no engine installed)")
238239
}
239240
_, cleanFunction := createSnykConfFile(t, os.Getenv("E2E_TEST_AUTH_TOKEN"))
@@ -251,7 +252,7 @@ func TestScanWithExcludeBaseImageVulns(t *testing.T) {
251252
}
252253

253254
func TestScanWithDependencies(t *testing.T) {
254-
if runtime.GOOS == "windows" || runtime.GOOS == "darwin" {
255+
if runtime.GOOS != "linux" {
255256
t.Skip("Can't run on this ci platform (windows containers or no engine installed)")
256257
}
257258
_, cleanFunction := createSnykConfFile(t, os.Getenv("E2E_TEST_AUTH_TOKEN"))
@@ -269,7 +270,7 @@ func TestScanWithDependencies(t *testing.T) {
269270
}
270271

271272
func TestScanWithSeverity(t *testing.T) {
272-
if runtime.GOOS == "windows" || runtime.GOOS == "darwin" {
273+
if runtime.GOOS != "linux" {
273274
t.Skip("Can't run on this ci platform (windows containers or no engine installed)")
274275
}
275276
_, cleanFunction := createSnykConfFile(t, os.Getenv("E2E_TEST_AUTH_TOKEN"))
@@ -288,7 +289,7 @@ func TestScanWithSeverity(t *testing.T) {
288289
}
289290

290291
func TestScanWithSeverityBadValue(t *testing.T) {
291-
if runtime.GOOS == "windows" || runtime.GOOS == "darwin" {
292+
if runtime.GOOS != "linux" {
292293
t.Skip("Can't run on this ci platform (windows containers or no engine installed)")
293294
}
294295
_, cleanFunction := createSnykConfFile(t, os.Getenv("E2E_TEST_AUTH_TOKEN"))
@@ -306,7 +307,7 @@ func TestScanWithSeverityBadValue(t *testing.T) {
306307
}
307308

308309
func TestScanWithJsonAndGroupIssues(t *testing.T) {
309-
if runtime.GOOS == "windows" || runtime.GOOS == "darwin" {
310+
if runtime.GOOS != "linux" {
310311
t.Skip("Can't run on this ci platform (windows containers or no engine installed)")
311312
}
312313
_, cleanFunction := createSnykConfFile(t, os.Getenv("E2E_TEST_AUTH_TOKEN"))
@@ -326,7 +327,7 @@ func TestScanWithJsonAndGroupIssues(t *testing.T) {
326327
}
327328

328329
func TestScanWithGroupIssues(t *testing.T) {
329-
if runtime.GOOS == "windows" || runtime.GOOS == "darwin" {
330+
if runtime.GOOS != "linux" {
330331
t.Skip("Can't run on this ci platform (windows containers or no engine installed)")
331332
}
332333
_, cleanFunction := createSnykConfFile(t, os.Getenv("E2E_TEST_AUTH_TOKEN"))
@@ -344,7 +345,7 @@ func TestScanWithGroupIssues(t *testing.T) {
344345
}
345346

346347
func TestScanWithContainerizedSnyk(t *testing.T) {
347-
if runtime.GOOS == "windows" || runtime.GOOS == "darwin" {
348+
if runtime.GOOS != "linux" {
348349
t.Skip("Can't run on this ci platform (windows containers or no engine installed)")
349350
}
350351
homeDir, cleanFunction := createSnykConfFile(t, os.Getenv("E2E_TEST_AUTH_TOKEN"))
@@ -399,7 +400,7 @@ func TestScanLocalImageWithContainerizedSnyk(t *testing.T) {
399400
if runtime.GOOS != "linux" {
400401
t.Skip("Can't run on this ci platform (windows containers or no engine installed)")
401402
}
402-
homeDir, cleanFunction := createSnykConfFile(t, os.Getenv("E2E_TEST_AUTH_TOKEN"))
403+
_, cleanFunction := createSnykConfFile(t, os.Getenv("E2E_TEST_AUTH_TOKEN"))
403404
defer cleanFunction()
404405

405406
cmd, configDir, cleanup := dockerCli.createTestCmd()
@@ -408,14 +409,31 @@ func TestScanLocalImageWithContainerizedSnyk(t *testing.T) {
408409

409410
// Build a local image
410411
cmd.Command = dockerCli.Command("build", "-f", "./testdata/Dockerfile", "-t", LocalBuildImage, ".")
411-
cmd.Env = append(cmd.Env, fmt.Sprintf("HOME=%s", homeDir.Path()))
412412
icmd.RunCmd(cmd).Assert(t, icmd.Success)
413413

414414
cmd.Command = dockerCli.Command("scan", LocalBuildImage)
415415
output := icmd.RunCmd(cmd).Assert(t, icmd.Expected{ExitCode: 1}).Combined()
416416
assert.Assert(t, strings.Contains(output, "vulnerability found"))
417417
}
418418

419+
func TestScanWithFileAndExcludeBaseImageVulnsContainerizedProvider(t *testing.T) {
420+
if runtime.GOOS != "linux" {
421+
t.Skip("Can't run on this ci platform (windows containers or no engine installed)")
422+
}
423+
pwd, _ := os.Getwd()
424+
dockerfilePath := path.Join(pwd, "/testdata/Dockerfile")
425+
_, cleanFunction := createSnykConfFile(t, os.Getenv("E2E_TEST_AUTH_TOKEN"))
426+
defer cleanFunction()
427+
428+
cmd, configDir, cleanup := dockerCli.createTestCmd()
429+
defer cleanup()
430+
createScanConfigFileOptinAndPath(t, configDir, true, "")
431+
432+
cmd.Command = dockerCli.Command("scan", "--file", dockerfilePath, "--exclude-base", ImageBaseImageVulnerabilities)
433+
output := icmd.RunCmd(cmd).Assert(t, icmd.Success).Combined()
434+
assert.Assert(t, strings.Contains(output, "found 0 issues."))
435+
}
436+
419437
func createSnykConfDirectories(t *testing.T, withConfFile bool, token string) (*fs.Dir, func()) {
420438
content := fmt.Sprintf(`{"api" : "%s"}`, token)
421439
var confFiles []fs.PathOp

internal/provider/containerizedsnyk.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,18 @@ func (d *dockerSnykProvider) newCommand(envVars []string, arg ...string) (string
268268
bindings := dockerBindings{
269269
"/var/run/docker.sock:/var/run/docker.sock",
270270
}
271+
for index, argument := range arg {
272+
if strings.HasPrefix(argument, "--file") {
273+
argSplit := strings.Split(argument, "=")
274+
filePath, err := filepath.Abs(argSplit[1])
275+
if err != nil {
276+
return "", nil, err
277+
}
278+
279+
bindings = append(bindings, fmt.Sprintf(`%s:/app/Dockerfile`, filePath))
280+
arg[index] = "--file=/app/Dockerfile"
281+
}
282+
}
271283
defaultEnvs := []string{"NO_UPDATE_NOTIFIER=true", "SNYK_CFG_DISABLESUGGESTIONS=true",
272284
"SNYK_INTEGRATION_NAME=DOCKER_DESKTOP"}
273285
envVars = append(envVars, defaultEnvs...)

0 commit comments

Comments
 (0)