Skip to content

Commit

Permalink
feat: enable --json for docker cli by default
Browse files Browse the repository at this point in the history
`snyk test` and `snyk monitor` via Docker cli
expect to have json vulnerabilities data to
generate the report. Make `--json` hardcoded
to avoid parsing errors and match the default
expecation.
  • Loading branch information
lili2311 committed Jan 27, 2020
1 parent a0293d0 commit 75f9a7d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ The package argument is optional. If no package is given, Snyk will run the comm

Snyk is also provided as a set of Docker images that carry the runtime environment of each package manager. For example, the npm image will carry all of the needed setup to run `npm install` on the currently running container. Currently there are images for npm, Ruby, Maven, Gradle and SBT.

The images can perform `snyk test` by default on the specified project which is mounted to the container as a read/write volume, and `snyk monitor` if the `MONITOR` environment variable is set when running the docker container. If you want an HTML report for `test` command, make sure `--json` parameter is provided. `monitor` command appends it automatically. An HTML file called `snyk_report.html` and a CSS file called `snyk_report.css` will be generated. The image also writes a file called `snyk-res.json` for internal use and `snyk-error.log` for errors that we can look at if something goes wrong.
The images can perform `snyk test` by default on the specified project which is mounted to the container as a read/write volume, and `snyk monitor` if the `MONITOR` environment variable is set when running the docker container. If you want an HTML report for `test` command (`--json` is appended automatically). An HTML file called `snyk_report.html` and a CSS file called `snyk_report.css` will be generated. The image also writes a file called `snyk-res.json` for internal use and `snyk-error.log` for errors that we can look at if something goes wrong.

The following environment variables can be used when running the container on docker:

Expand Down
4 changes: 1 addition & 3 deletions docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ cd "${PROJECT_PATH}/${PROJECT_FOLDER}/${PROJECT_SUBDIR}" ||
exitWithMsg "Can't cd to ${PROJECT_PATH}/${PROJECT_FOLDER}/${PROJECT_SUBDIR}" 1

runCmdAsDockerUser "PATH=${PATH} snyk ${SNYK_COMMAND} ${SNYK_PARAMS} \
${ADDITIONAL_ENV} > \"${OUTPUT_FILE}\" 2>\"${ERROR_FILE}\""
${ADDITIONAL_ENV} --json > \"${OUTPUT_FILE}\" 2>\"${ERROR_FILE}\""

RC=$?

Expand Down Expand Up @@ -115,8 +115,6 @@ sed 's/<\/head>/ <link rel=\"stylesheet\" href=\"snyk_report.css\"><\/head>/' \

runCmdAsDockerUser "cat /home/node/snyk_report.css > \
\"${PROJECT_PATH}/${PROJECT_FOLDER}/snyk_report.css\""
# fi
#

if [ $RC -ne "0" ]; then
exitWithMsg "${OUTPUT_FILE}" "$RC"
Expand Down

0 comments on commit 75f9a7d

Please sign in to comment.