Skip to content

Commit a0c1500

Browse files
authored
feat: support custom dependency track via Lagoon api env vars (#450)
* fix: "gathering insights" logs out of order * fix: supress notices of new trivy versions 📣 Notices: - Version 0.65.0 of Trivy is now available, current version is 0.63.0 * feat: support custom dependency track via Lagoon api env vars * fix: errors thrown during insights gathering halt entire build * feat: test custom dependency track credentials before configuring them
1 parent ca7d037 commit a0c1500

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

legacy/build-deploy-docker-compose.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1754,20 +1754,23 @@ if [ "$(featureFlag INSIGHTS)" = enabled ]; then
17541754
##############################################
17551755
### RUN insights gathering and store in configmap
17561756
##############################################
1757+
set +e # Ensure failures in exec-generate-insights-configmap.sh don't halt the entire build
17571758
INSIGHTS_WARNING_COUNT=0
17581759
for IMAGE_NAME in "${!IMAGES_BUILD[@]}"
17591760
do
17601761
IMAGE_TAG="${IMAGE_TAG:-latest}"
17611762
IMAGE_FULL="${REGISTRY}/${PROJECT}/${ENVIRONMENT}/${IMAGE_NAME}:${IMAGE_TAG}"
1762-
insightsOutput=$(. /kubectl-build-deploy/scripts/exec-generate-insights-configmap.sh)
1763+
insightsOutput=$(. /kubectl-build-deploy/scripts/exec-generate-insights-configmap.sh 2>&1)
17631764
if (exit $?); then
17641765
echo "${insightsOutput}"
17651766
else
17661767
((++INSIGHTS_WARNING_COUNT))
17671768
echo "> This insights run failed, this warning is for information only."
17681769
echo "${insightsOutput}"
17691770
fi
1771+
echo ""
17701772
done
1773+
set -e
17711774
if [[ "$INSIGHTS_WARNING_COUNT" -gt 0 ]]; then
17721775
((++BUILD_WARNING_COUNT))
17731776
echo "##############################################"

legacy/scripts/exec-generate-insights-configmap.sh

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ echo "Using image for scan ${IMAGECACHE_REGISTRY}${INSIGHTS_SCAN_IMAGE}"
6969

7070
# Setting JAVAOPT to skip the java db update, as the upstream image comes with a pre-populated database
7171
JAVAOPT="--skip-java-db-update"
72-
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock ${IMAGECACHE_REGISTRY}${INSIGHTS_SCAN_IMAGE} image ${JAVAOPT} ${IMAGE_FULL} --format ${SBOM_OUTPUT} | gzip > ${SBOM_OUTPUT_FILE}
72+
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock ${IMAGECACHE_REGISTRY}${INSIGHTS_SCAN_IMAGE} image ${JAVAOPT} ${IMAGE_FULL} --format ${SBOM_OUTPUT} --skip-version-check | gzip > ${SBOM_OUTPUT_FILE}
7373

7474
FILESIZE=$(stat -c%s "$SBOM_OUTPUT_FILE")
7575
echo "Size of ${SBOM_OUTPUT_FILE} = $FILESIZE bytes."
@@ -107,6 +107,27 @@ processSbom() {
107107
annotate configmap ${SBOM_CONFIGMAP} \
108108
lagoon.sh/branch=${BRANCH}
109109
fi
110+
# Support custom Depdency Track integration.
111+
local apiEndpoint
112+
apiEndpoint=$(featureFlag INSIGHTS_DEPENDENCY_TRACK_API_ENDPOINT)
113+
local apiKey
114+
apiKey=$(featureFlag INSIGHTS_DEPENDENCY_TRACK_API_KEY)
115+
local dtWarn
116+
if [ -n "$apiEndpoint" ]; then
117+
if [ -n "$apiKey" ]; then
118+
# Test API access
119+
local resp
120+
if ! resp=$(curl -sSf -m 60 -H "X-Api-Key:${apiKey}" "${apiEndpoint}/api/v1/project?pageSize=1" 2>&1); then
121+
dtWarn="\n\n**********\nCustom Dependency Track not enabled: API Error: ${resp}\n**********\n\n"
122+
else
123+
kubectl -n ${NAMESPACE} \
124+
annotate configmap ${SBOM_CONFIGMAP} \
125+
dependencytrack.insights.lagoon.sh/custom-endpoint="${apiEndpoint}"
126+
fi
127+
else
128+
dtWarn="\n\n**********\nCustom Dependency Track not enabled: Missing LAGOON_FEATURE_FLAG_INSIGHTS_DEPENDENCY_TRACK_API_KEY\n**********\n\n"
129+
fi
130+
fi
110131
kubectl \
111132
-n ${NAMESPACE} \
112133
label configmap ${SBOM_CONFIGMAP} \
@@ -119,6 +140,11 @@ processSbom() {
119140
lagoon.sh/environmentType=${ENVIRONMENT_TYPE} \
120141
lagoon.sh/buildType=${BUILD_TYPE} \
121142
insights.lagoon.sh/type=sbom
143+
144+
if [ -n "$dtWarn" ]; then
145+
printf '%b' "$dtWarn"
146+
return 1
147+
fi
122148
fi
123149
}
124150

0 commit comments

Comments
 (0)