Skip to content

Commit

Permalink
Merge pull request #54 from snyk/docker-image
Browse files Browse the repository at this point in the history
Added a Dockerfile to help with using snyk-to-html in pipelines
  • Loading branch information
lili2311 authored Jan 9, 2020
2 parents 7a5500f + f9e8646 commit 69e0db9
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM node:alpine

RUN npm install snyk-to-html -g

COPY docker-entrypoint.sh /usr/local/bin

ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
62 changes: 62 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/ash

# snykt-to-html is used to generate HTML reports from Snyk JSON output
#
# Packaging up as a Docker images make reuse easier, especially in
# modern CI pipelines
#
# snyk-to-html by default always outputs to a file but it's often useful
# to output to stdout so this images changes the behaviour to support
# the widest possible usage
#
# If no options passed
# Read from stdin, output to stdout
# if -i
# Read from file on disk, output to stdout
# if -o
# Read from stdin, output to disk
# If -i and -o
# Read from file and output to file

if ! [ -x "$(command -v snyk-to-html)" ]; then
echo "Error: snyk-to-html is not installed." >&2
exit 1
fi

while getopts ":i:o:" opt; do
case ${opt} in
i)
input=${OPTARG}
;;
o)
output=${OPTARG}
;;
\?)
echo "Invalid option: -${OPTARG}" >&2
exit 1
;;
:)
echo "Option -${OPTARG} requires an argument." >&2
exit 1
;;
esac
done

if [ -z "${output}" ]
then
if [ -z "${input}" ]
then
snyk-to-html -o snyk.html > /dev/null
cat snyk.html
else
snyk-to-html -i ${input} -o snyk.html > /dev/null
cat snyk.html
fi
else
if [ -z "${input}" ]
then
snyk-to-html -o ${output}
else
snyk-to-html -i ${input} -o ${output}
fi
fi

0 comments on commit 69e0db9

Please sign in to comment.