Skip to content

Commit

Permalink
Introduce script for downloading Scanner blobs
Browse files Browse the repository at this point in the history
It's actually stolen from
#1334
with small modifications.
  • Loading branch information
msugakov committed Feb 1, 2024
1 parent 7993e3b commit e0328b0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 38 deletions.
22 changes: 3 additions & 19 deletions .tekton/scanner-db-pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -240,26 +240,10 @@ spec:
taskSpec:
steps:
- name: fetch-sql-definitions
image: registry.access.redhat.com/ubi8/ubi
image: registry.access.redhat.com/ubi8/ubi-minimal:latest
script: |
#!/usr/bin/env bash
mkdir -p "$(workspaces.source.path)/source"
blobs=(
pg-definitions.sql.gz
)
for blob in "${blobs[@]}"; do
echo "https://storage.googleapis.com/definitions.stackrox.io/scanner-data/latest/${blob} > $(workspaces.source.path)/source/blob-${blob}"
curl --fail -s --show-error --retry 4 --retry-max-time 30 --retry-connrefused \
--output "$(workspaces.source.path)/source/${blob}" \
"https://storage.googleapis.com/definitions.stackrox.io/scanner-data/latest/${blob}"
if [ "$?" != "0" ]; then
echo "Failed to download"
exit 1
fi
ls -lh $(workspaces.source.path)/source
done
"$(workspaces.source.path)/source/scripts/konflux/fetch-scanner-data.sh" pg-definitions.sql.gz
timeout: '10m'
workspaces:
- name: source
workspace: workspace
Expand Down
22 changes: 3 additions & 19 deletions .tekton/scanner-db-push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -238,26 +238,10 @@ spec:
taskSpec:
steps:
- name: fetch-sql-definitions
image: registry.access.redhat.com/ubi8/ubi
image: registry.access.redhat.com/ubi8/ubi-minimal:latest
script: |
#!/usr/bin/env bash
mkdir -p "$(workspaces.source.path)/source"
blobs=(
pg-definitions.sql.gz
)
for blob in "${blobs[@]}"; do
echo "https://storage.googleapis.com/definitions.stackrox.io/scanner-data/latest/${blob} > $(workspaces.source.path)/source/blob-${blob}"
curl --fail -s --show-error --retry 4 --retry-max-time 30 --retry-connrefused \
--output "$(workspaces.source.path)/source/${blob}" \
"https://storage.googleapis.com/definitions.stackrox.io/scanner-data/latest/${blob}"
if [ "$?" != "0" ]; then
echo "Failed to download"
exit 1
fi
ls -lh $(workspaces.source.path)/source
done
"$(workspaces.source.path)/source/scripts/konflux/fetch-scanner-data.sh" pg-definitions.sql.gz
timeout: '10m'
workspaces:
- name: source
workspace: workspace
Expand Down
27 changes: 27 additions & 0 deletions scripts/konflux/fetch-scanner-data.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

set -euo pipefail

REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd)"

if [[ "$#" < 1 ]]; then
>&2 echo "Error: please pass blob filenames as command line arguments."
>&2 echo "For example:"
>&2 echo " $(basename "${BASH_SOURCE[0]}") nvd-definitions.zip k8s-definitions.zip repo2cpe.zip genesis_manifests.json"
exit 1
fi

blobs=( "$@" )

for blob in "${blobs[@]}"; do

# TODO(ROX-22130): Assign proper suffix for tagged commits instead of /latest/.
url="https://storage.googleapis.com/definitions.stackrox.io/scanner-data/latest/${blob}"
dest="${REPO_ROOT}/blob-${blob}"

echo "Downloading ${url} > ${dest}"
curl --fail -s --show-error --retry 4 --retry-max-time 30 --retry-connrefused \
--output "${dest}" \
"${url}"

done

0 comments on commit e0328b0

Please sign in to comment.