forked from PinSpace-Org/GistPin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscan-containers.sh
More file actions
39 lines (32 loc) · 925 Bytes
/
Copy pathscan-containers.sh
File metadata and controls
39 lines (32 loc) · 925 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env bash
set -euo pipefail
# scan-containers.sh — Scan Docker images for vulnerabilities
# Usage: ./scan-containers.sh [image-tag]
TAG="${1:-latest}"
IMAGES=(
"gistpin-backend:$TAG"
"gistpin-frontend:$TAG"
"gistpin-postgres:$TAG"
)
REPORT_DIR="${REPORT_DIR:-/tmp/security-reports}"
mkdir -p "$REPORT_DIR"
FAILED=0
log() { echo "[$(date +%H:%M:%S)] $*"; }
for IMAGE in "${IMAGES[@]}"; do
log "Scanning $IMAGE..."
REPORT="$REPORT_DIR/container-$(echo "$IMAGE" | tr '/:' '--')-$(date +%Y%m%d).json"
trivy image \
--severity HIGH,CRITICAL \
--format json \
--output "$REPORT" \
--exit-code 1 \
"$IMAGE" 2>/dev/null || {
log "VULNERABILITIES found in $IMAGE — see $REPORT"
FAILED=1
}
done
if [[ "$FAILED" -eq 1 ]]; then
log "Container scan FAILED — fix vulnerabilities before deploying"
exit 1
fi
log "All container scans passed. Reports in $REPORT_DIR"