-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: Add snyk docker scanning feature #289
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,9 @@ version="9" | |
|
||
# shellcheck source=common_functions.sh | ||
source ./common_functions.sh | ||
# shellcheck source=snyk.sh | ||
source ./snyk.sh | ||
|
||
# shellcheck source=dockerfile_functions.sh | ||
source ./dockerfile_functions.sh | ||
|
||
|
@@ -43,25 +46,37 @@ function build_image() { | |
build=$1; shift; | ||
btype=$1; shift; | ||
|
||
tags="" | ||
for tag in "$@" | ||
do | ||
tags="${tags} -t ${repo}:${tag}" | ||
echo "docker push ${repo}:${tag}" >> "${push_cmdfile}" | ||
done | ||
local tags=("${@[@]}") # copy arguments to local array | ||
for i in "${tags[@]}" | ||
do | ||
echo "docker push ${repo}:${tags[$i]}" >> "${push_cmdfile}" | ||
done | ||
|
||
printf -v expanded_tags "-t ${repo}:%s " "${tags[@]}" # concatenate to single strin : -t repo:tag -t repo:tag2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. whitepsace again? |
||
expanded_tags=${expanded_tags%?} # remove trailing space | ||
dockerfile="Dockerfile.${vm}.${build}.${btype}" | ||
|
||
echo "#####################################################" | ||
echo "INFO: docker build --no-cache ${tags} -f ${dockerfile} ." | ||
echo "INFO: docker build --no-cache ${expanded_tags} -f ${dockerfile} ." | ||
echo "#####################################################" | ||
# shellcheck disable=SC2086 # ignoring ${tags} due to whitespace problem | ||
if ! docker build --pull --no-cache ${tags} -f "${dockerfile}" . ; then | ||
if ! docker build --pull --no-cache ${expanded_tags} -f "${dockerfile}" . ; then | ||
echo "#############################################" | ||
echo | ||
echo "ERROR: Docker build of image: ${tags} from ${dockerfile} failed." | ||
echo "ERROR: Docker build of image: ${expanded_tags} from ${dockerfile} failed." | ||
echo | ||
echo "#############################################" | ||
else | ||
if ((SNYK_ENABLED)); then | ||
echo "#####################################################" | ||
echo " Scanning with snyk for vulnerabilities " | ||
echo "#####################################################" | ||
for i in "${tags[@]}" | ||
do | ||
printf "...scanning %s" "${tags[$i]}" | ||
snyk test --docker "${tags[$i]}" --file=="${dockerfile}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. whitepspace |
||
done | ||
fi | ||
fi | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env bash | ||
if [ -z "${SNYK_AUTH_TOKEN}" ];then | ||
printf "Snyk authentication token not set, skipping snyk analysis" | ||
return | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wouldn't you exit? |
||
fi | ||
set -o pipefail | ||
export SNYK_ENABLED=0 | ||
if test -f "$HOME/.nvm/nvm.sh"; then | ||
echo "nvm found" | ||
else | ||
echo "No nvm on machine, snyk check will be skipped" | ||
exit 0 | ||
fi | ||
|
||
# shellcheck disable=SC1090 | ||
source "$HOME/.nvm/nvm.sh" | ||
|
||
echo "Installing node..." | ||
nvm install node | ||
|
||
echo "Installing snyk.." | ||
npm install -g snyk | ||
|
||
echo "Snyk version: $(snyk -v)" | ||
|
||
export SNYK_ENABLED=1 | ||
printf "Snyk installed succesfully\n" | ||
printf "Authenticating snyk\n" | ||
|
||
snyk auth "${SNYK_AUTH_TOKEN}" | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. kill extra whitespace |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whitespace embedding