Skip to content

Commit ec2e163

Browse files
committedMar 27, 2025
Replace docker run by oci-tool fetch file
Tool: gitpod/catfood.gitpod.cloud
1 parent ed5bdb3 commit ec2e163

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed
 

‎.github/workflows/build.yml

+1
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ jobs:
325325
run: |
326326
INSTALLER_IMAGE_BASE_REPO=${{ needs.configuration.outputs.image_repo_base }}
327327
./scripts/trivy/trivy-scan-images.sh ${{ needs.configuration.outputs.version }} CRITICAL
328+
exit $?
328329
329330
install-app:
330331
runs-on: ${{ needs.create-runner.outputs.label }}

‎scripts/trivy/scan-installer-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ observability:
4343
logLevel: info
4444
openVSX:
4545
url: https://open-vsx.org
46-
repository: eu.gcr.io/gitpod-dev-artifact/build
46+
repository: example.org
4747
workspace:
4848
maxLifetime: 36h0m0s
4949
resources:

‎scripts/trivy/trivy-scan-images.sh

+20-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Licensed under the GNU Affero General Public License (AGPL).
44
# See License.AGPL.txt in the project root for license information.
55

6-
set -uo pipefail
6+
set -euo pipefail
77

88
# Check if VERSION and FAIL_ON are provided
99
if [[ $# -lt 2 ]]; then
@@ -40,8 +40,7 @@ echo "Working directory: $SCAN_DIR"
4040

4141
# Directory where this script is located
4242
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
43-
CONFIG_DIR="$SCRIPT_DIR"
44-
INSTALLER_CONFIG_FILE="scan-installer-config.yaml"
43+
INSTALLER_CONFIG_PATH="$SCRIPT_DIR/scan-installer-config.yaml"
4544
TRIVYIGNORE_PATH="$SCRIPT_DIR/trivyignore.yaml"
4645

4746
# Ensure Trivy is installed
@@ -53,11 +52,25 @@ if ! command -v "$TRIVY_CMD" &> /dev/null; then
5352
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b "$SCAN_DIR/bin"
5453
fi
5554

55+
OCI_TOOL_CMD="oci-tool"
56+
OCI_TOOL_VERSION="0.2.0"
57+
if ! command -v "$OCI_TOOL_CMD" &> /dev/null; then
58+
mkdir -p "$SCAN_DIR/bin"
59+
OCI_TOOL_CMD="$SCAN_DIR/bin/oci-tool"
60+
curl -fsSL https://github.com/csweichel/oci-tool/releases/download/v${OCI_TOOL_VERSION}/oci-tool_${OCI_TOOL_VERSION}_linux_amd64.tar.gz | tar xz -C "$(dirname "$OCI_TOOL_CMD")" && chmod +x "$OCI_TOOL_CMD"
61+
fi
62+
5663
echo "=== Gathering list of all images for $VERSION"
5764

65+
# Extract installer binary from installer image
66+
INSTALLER_IMAGE="$INSTALLER_IMAGE_BASE_REPO/build/installer:${VERSION}"
67+
INSTALLER="$SCAN_DIR/installer"
68+
"$OCI_TOOL_CMD" fetch file -o "$INSTALLER" --platform=linux-amd64 "${INSTALLER_IMAGE}" app/installer
69+
echo ""
70+
chmod +x "$INSTALLER"
71+
5872
# Run the installer docker image to get the list of images
59-
docker run --rm -v "$CONFIG_DIR:/config" "$INSTALLER_IMAGE_BASE_REPO/build/installer:${VERSION}" mirror list \
60-
-c "/config/$INSTALLER_CONFIG_FILE" > "$SCAN_DIR/mirror.json"
73+
"$INSTALLER" mirror list -c "$INSTALLER_CONFIG_PATH" > "$SCAN_DIR/mirror.json"
6174

6275
# Extract original image references
6376
jq -r '.[].original' "$SCAN_DIR/mirror.json" > "$SCAN_DIR/images.txt"
@@ -97,6 +110,7 @@ while IFS= read -r IMAGE_REF; do
97110

98111
# Run Trivy on the image
99112
scan_time=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
113+
set +e
100114
trivy_output=$("$TRIVY_CMD" image "$IMAGE_REF" --ignorefile "$TRIVYIGNORE_PATH" --scanners vuln --format json "$@" | jq -c)
101115
scan_status=$?
102116

@@ -127,6 +141,7 @@ while IFS= read -r IMAGE_REF; do
127141
'{image: $image, scan_time: $scan_time, error: $error, error_details: $details}' >> "$RESULT_FILE"
128142
((FAILED=FAILED+1))
129143
fi
144+
set -e
130145

131146
echo ""
132147
done < "$SCAN_DIR/images.txt"

0 commit comments

Comments
 (0)
Failed to load comments.