Skip to content

Commit

Permalink
chore: docker entrypoint readability with line breaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Drukh committed Dec 6, 2018
1 parent 7a199f0 commit 416401b
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ exitWithMsg () {
}

##
## Start of backward compatability code
## Should be phased out when we phase out the current version of the jenkins plugin
## These parameters should only be used with the Jenkins plugin! Please see README.md for more info
## Start of backward compatability code.
## Should be phased out when we phase out the current version of the jenkins
## plugin.
## These parameters should only be used with the Jenkins plugin! Please see
## README.md for more info.
##

TEST_SETTINGS="";
Expand Down Expand Up @@ -77,9 +79,11 @@ if [ -n "${ENV_FLAGS}" ]; then
ADDITIONAL_ENV="-- ${ENV_FLAGS}"
fi

cd "${PROJECT_PATH}/${PROJECT_FOLDER}/${PROJECT_SUBDIR}" || exitWithMsg "Can't cd to ${PROJECT_PATH}/${PROJECT_FOLDER}/${PROJECT_SUBDIR}" 1
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}\""
runCmdAsDockerUser "PATH=${PATH} snyk ${SNYK_COMMAND} ${SNYK_PARAMS} \
${ADDITIONAL_ENV} > \"${OUTPUT_FILE}\" 2>\"${ERROR_FILE}\""

RC=$?

Expand All @@ -88,21 +92,30 @@ if [ "$RC" -ne "0" ] && [ "$RC" -ne "1" ]; then
fi

#
# Commented out the condition because we want to always generate the html file until we phase out the old version of the Jenkins plugin
# Commented out the condition because we want to always generate the html
# file until we phase out the old version of the Jenkins plugin.
# TODO: Re-add this option to documentation once back
#
# - `GENERATE_REPORT` - [OPTIONAL] if set, this will generate the HTML report with a summary of the vulnerabilities detected by snyk.
# - `GENERATE_REPORT` - [OPTIONAL] if set, this will generate the HTML report
# with a summary of the vulnerabilities detected by snyk.
#
# if [ -n $GENERATE_REPORT ]; then
runCmdAsDockerUser "touch \"${PROJECT_PATH}/${PROJECT_FOLDER}/${HTML_FILE}\""

if [ -n "$MONITOR" ]; then
runCmdAsDockerUser "PATH=${PATH} snyk monitor --json ${SNYK_PARAMS} ${ADDITIONAL_ENV} | jq -r \".uri\" | awk '{print \"<center><a target=\\\"_blank\\\" href=\\\"\" \$0 \"\\\">View On Snyk.io</a></center>\"}' > \"${PROJECT_PATH}/${PROJECT_FOLDER}/${HTML_FILE}\" 2>\"${ERROR_FILE}\""
runCmdAsDockerUser "PATH=${PATH} snyk monitor --json ${SNYK_PARAMS} \
${ADDITIONAL_ENV} | jq -r \".uri\" | awk '{print \"<center><a target=\\\"_blank\\\" href=\\\"\" \$0 \"\\\">View On Snyk.io</a></center>\"}' > \"${PROJECT_PATH}/${PROJECT_FOLDER}/${HTML_FILE}\" 2>\"${ERROR_FILE}\""
fi


runCmdAsDockerUser "cat \"${OUTPUT_FILE}\" | jq '.vulnerabilities|= map(. + {severity_numeric: (if(.severity) == \"high\" then 1 else (if(.severity) == \"medium\" then 2 else (if(.severity) == \"low\" then 3 else 4 end) end) end)}) |.vulnerabilities |= sort_by(.severity_numeric) | del(.vulnerabilities[].severity_numeric)' | snyk-to-html | sed 's/<\/head>/ <link rel=\"stylesheet\" href=\"snyk_report.css\"><\/head>/' >> \"${PROJECT_PATH}/${PROJECT_FOLDER}/${HTML_FILE}\""
runCmdAsDockerUser "cat /home/node/snyk_report.css > \"${PROJECT_PATH}/${PROJECT_FOLDER}/snyk_report.css\""
runCmdAsDockerUser "cat \"${OUTPUT_FILE}\" | \
jq '.vulnerabilities|= map(. + {severity_numeric: (if(.severity) == \"high\" then 1 else (if(.severity) == \"medium\" then 2 else (if(.severity) == \"low\" then 3 else 4 end) end) end)}) |.vulnerabilities |= sort_by(.severity_numeric) | del(.vulnerabilities[].severity_numeric)' | \
snyk-to-html | \
sed 's/<\/head>/ <link rel=\"stylesheet\" href=\"snyk_report.css\"><\/head>/' \
>> \"${PROJECT_PATH}/${PROJECT_FOLDER}/${HTML_FILE}\""

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

Expand Down

0 comments on commit 416401b

Please sign in to comment.