message: rejig sbom process step
diff: TMP_DIR="${TMP_DIR:-/tmp}"
  SBOM_OUTPUT="cyclonedx-json"
  SBOM_OUTPUT_FILE="${TMP_DIR}/${IMAGE_NAME}.cyclonedx.json.gz"
  +SBOM_CONFIGMAP="lagoon-sbom-${IMAGE_NAME}"
  set -x
  # Run sbom and dump to file
  @@ -13,21 +14,15 @@ set +x
  DOCKER_HOST=docker-host.lagoon.svc docker run --rm -v /var/run/docker.sock:/var/run/docker.sock imagecache.amazeeio.cloud/anchore/syft packages ${IMAGE_FULL} -o ${SBOM_OUTPUT} | gzip > ${SBOM_OUTPUT_FILE}
  -IMAGE_FULL="/Users/tim.clifford/playground/fleet-portal.ch/fleet-portal-ch.gz"
  -SBOM_OUTPUT_FILE="/Users/tim.clifford/playground/fleet-portal.ch/fleet-portal-ch.gz"
  -
  -FILESIZE=$(stat -f%z "$IMAGE_FULL")
  -# FILESIZE=$(stat -c%s "$SBOM_OUTPUT_FILE")
  +FILESIZE=$(stat -c%s "$SBOM_OUTPUT_FILE")
  echo "Size of ${SBOM_OUTPUT_FILE} = $FILESIZE bytes."
  -checkFileSizeLimit() {
  +processSbom() {
  if (( $FILESIZE > 950000 )); then
  echo "$SBOM_OUTPUT_FILE is too large, skipping pushing to configmap"
  return
  else
  - if [ -f "${SBOM_OUTPUT_FILE}" ]; then
  echo "Successfully generated SBOM for ${IMAGE_FULL}"
  - SBOM_CONFIGMAP=lagoon-sbom-${IMAGE_NAME}
  set -x
  # If sbom configmap already exists then we need to update, else create new
  @@ -38,35 +33,23 @@ checkFileSizeLimit() {
  --from-file=${SBOM_OUTPUT_FILE} \
  -o json \
  --dry-run=client | kubectl replace -f -
  - kubectl --insecure-skip-tls-verify \
  - -n ${NAMESPACE} \
  - label configmap ${SBOM_CONFIGMAP} \
  - lagoon.sh/insightsType=sbom \
  - lagoon.sh/buildName=${LAGOON_BUILD_NAME} \
  - lagoon.sh/project=${PROJECT} \
  - lagoon.sh/environment=${ENVIRONMENT} \
  - lagoon.sh/service=${IMAGE_NAME}
  -
  else
  # Create configmap and add label (#have to add label separately: https://github.com/kubernetes/kubernetes/issues/60295)
  kubectl --insecure-skip-tls-verify \
  -n ${NAMESPACE} \
  create configmap ${SBOM_CONFIGMAP} \
  --from-file=${SBOM_OUTPUT_FILE}
  + fi
  kubectl --insecure-skip-tls-verify \
  -n ${NAMESPACE} \
  label configmap ${SBOM_CONFIGMAP} \
  - lagoon.sh/insightsType=sbom \
  + lagoon.sh/insightsType=sbom-gz \
  lagoon.sh/buildName=${LAGOON_BUILD_NAME} \
  lagoon.sh/project=${PROJECT} \
  lagoon.sh/environment=${ENVIRONMENT} \
  lagoon.sh/service=${IMAGE_NAME}
  - fi
  set +x
  - else
  - echo "Failed to generate SBOM for ${IMAGE_FULL}"
  - fi
  fi
  }
  -checkFileSizeLimit
  +processSbom
  