Skip to content

Better retry, waiting and timeout for 'analyzed' step and getting scan report #3

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,40 @@ echo "Waiting for analysis to complete"
result=0
user_time=0
retries=0
notanalyzed=1 #1 when failure, 0 when success
while [ $user_time -lt $TIMEOUT ]; do
anchore-cli image get $IMAGE_DIGEST | grep analyzed > /dev/null
if [ $? -ne 0 ]; then
notanalyzed=$?
if [ $notanalyzed -ne 0 ]; then
echo -n "."
sleep 10
let "user_time=user_time+10"
else
let "retries=retries+1"
if [ $retries -lt $MAX_RETRIES ]; then
if [ $notanalyzed -ne 0 ] && [ $retries -lt $MAX_RETRIES ]; then
echo -n "#"
sleep 10
else
result=1
break
fi
fi
done
[ $result -ne 1 ] && echo "Scan timedout." && exit 1

echo "Analysis complete"
anchore-cli evaluate check ${IMAGE_DIGEST} --tag $IMAGE_TAG
[ $notanalyzed -ne 0 ] && echo "Scan timedout." && exit 1
echo "Waiting for scan analysis report to be ready"
retries=0
user_time=0
wait=5
report=$(anchore-cli evaluate check ${IMAGE_DIGEST} --tag $IMAGE_TAG)
result=$?
while [ $result -ne 0 ] && [ $user_time -lt $TIMEOUT ]; do
let "retries=retries+1"
echo -n "."
sleep $wait
let "user_time=user_time+wait"
let "wait=wait+5"
report=$(anchore-cli evaluate check ${IMAGE_DIGEST} --tag $IMAGE_TAG)
result=$?
done
[ $retries -gt 0 ] && echo
echo "$report"
exit $result