Skip to content
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

SONAR-20590 - Adds retry mechanism for public and private scan tasks #649

Merged
merged 2 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 2 additions & 6 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ private_scan_task:
- curl -sSL https://unified-agent.s3.amazonaws.com/wss-unified-agent.jar -o wss-unified-agent.jar
- echo "docker.includes=${tag}" >> .cirrus/wss-unified-agent.config
scan_script:
- echo "Scan the ${STAGING_IMAGE_NAME}:${tag} image supporting linux/${platform}"
- docker pull --platform linux/${platform} "${STAGING_IMAGE_NAME}:${tag}"
- java -jar wss-unified-agent.jar -c .cirrus/wss-unified-agent.config -apiKey $MEND_API_KEY -product ${WS_PRODUCTNAME} -project ${STAGING_IMAGE_NAME}:${tag} -wss.url ${WS_WSS_URL} -docker.scanImages true
- .cirrus/private-scan-task.sh "${STAGING_IMAGE_NAME}" "${tag}" "${platform}" "${WS_PRODUCTNAME}" "${WS_WSS_URL}" "${MEND_API_KEY}"
depends_on: multi_arch_build

public_scan_task:
Expand All @@ -104,9 +102,7 @@ public_scan_task:
- curl -sSL https://unified-agent.s3.amazonaws.com/wss-unified-agent.jar -o wss-unified-agent.jar
- echo "docker.includes=${tag}" >> .cirrus/wss-unified-agent.config
scan_script:
- echo "Scan the ${PUBLIC_IMAGE_NAME}:${tag} image"
- docker pull "${PUBLIC_IMAGE_NAME}:${tag}"
- java -jar wss-unified-agent.jar -c .cirrus/wss-unified-agent.config -apiKey $MEND_API_KEY -product ${WS_PRODUCTNAME} -project ${PUBLIC_IMAGE_NAME}:${tag} -wss.url ${WS_WSS_URL} -docker.scanImages true
- .cirrus/public-scan-task.sh "${PUBLIC_IMAGE_NAME}" "${tag}" "${WS_PRODUCTNAME}" "${WS_WSS_URL}" "${MEND_API_KEY}"

multi_arch_test_task:
matrix:
Expand Down
43 changes: 43 additions & 0 deletions .cirrus/private-scan-task.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

STAGING_IMAGE_NAME=${1}
tag=${2}
platform=${3}
WS_PRODUCTNAME=${4}
WS_WSS_URL=${5}
MEND_API_KEY=${6}

IMAGE_PULLED=1
SCANNED=1

echo "Scan the ${STAGING_IMAGE_NAME}:${tag} image supporting linux/${platform}"

for i in $(seq 1 3); do
if docker pull --platform linux/"${platform}" "${STAGING_IMAGE_NAME}:${tag}"; then
IMAGE_PULLED=0
break
fi
echo "[${i}/3] Retrying to pull image ${STAGING_IMAGE_NAME}:${tag}..."
sleep 5
done

if [[ ${IMAGE_PULLED} -ne 0 ]]; then
echo "Failed to pull image ${STAGING_IMAGE_NAME}:${tag}"
exit 1
fi

for i in $(seq 1 3); do
if java -jar wss-unified-agent.jar -c .cirrus/wss-unified-agent.config -apiKey "${MEND_API_KEY}" -product "${WS_PRODUCTNAME}" -project "${STAGING_IMAGE_NAME}:${tag}" -wss.url ${WS_WSS_URL} -docker.scanImages true; then
SCANNED=0
break
fi
echo "[${i}/3] Retrying to scan image ${STAGING_IMAGE_NAME}:${tag}..."
sleep 5
done

if [[ ${SCANNED} -ne 0 ]]; then
echo "Failed to scan image ${STAGING_IMAGE_NAME}:${tag}"
exit 2
fi

exit 0
42 changes: 42 additions & 0 deletions .cirrus/public-scan-task.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

PUBLIC_IMAGE_NAME=${1}
tag=${2}
WS_PRODUCTNAME=${3}
WS_WSS_URL=${4}
MEND_API_KEY=${5}

IMAGE_PULLED=1
SCANNED=1

echo "Scan the ${PUBLIC_IMAGE_NAME}:${tag} image"

for i in $(seq 1 3); do
if docker pull "${PUBLIC_IMAGE_NAME}:${tag}"; then
IMAGE_PULLED=0
break
fi
echo "[${i}/3] Retrying to pull image ${PUBLIC_IMAGE_NAME}:${tag}..."
sleep 5
done

if [[ ${IMAGE_PULLED} -ne 0 ]]; then
echo "Failed to pull image ${PUBLIC_IMAGE_NAME}:${tag}"
exit 1
fi

for i in $(seq 1 3); do
if java -jar wss-unified-agent.jar -c .cirrus/wss-unified-agent.config -apiKey $MEND_API_KEY -product ${WS_PRODUCTNAME} -project ${PUBLIC_IMAGE_NAME}:${tag} -wss.url ${WS_WSS_URL} -docker.scanImages true; then
SCANNED=0
break
fi
echo "[${i}/3] Retrying to scan image ${PUBLIC_IMAGE_NAME}:${tag}..."
sleep 5
done

if [[ ${SCANNED} -ne 0 ]]; then
echo "Failed to scan image ${PUBLIC_IMAGE_NAME}:${tag}"
exit 2
fi

exit 0