1
0

audit.sh 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env bash
  2. # R01-N16 — surface known CVEs in the locked composer dependencies.
  3. #
  4. # Runs `composer audit` against composer.lock inside the project's runtime
  5. # image, so the audit reflects the exact versions the running container
  6. # has. Intended for periodic operator use (e.g. weekly cron) and as a
  7. # pre-deploy gate after `git pull`.
  8. #
  9. # Exit status mirrors composer's: 0 = clean, non-zero = advisories found
  10. # (or composer itself errored). Operators can pipe to `mail` / `wall` etc.
  11. set -euo pipefail
  12. # Resolve repo root so the script works regardless of cwd.
  13. SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
  14. REPO_ROOT="$(cd -- "${SCRIPT_DIR}/.." &>/dev/null && pwd)"
  15. cd "${REPO_ROOT}"
  16. IMAGE="${SPRINT_PLANER_IMAGE:-sprint_planer_web-app:latest}"
  17. if ! command -v docker >/dev/null 2>&1; then
  18. echo "audit.sh: docker is required (composer + the right ext-* set live in the image)" >&2
  19. exit 2
  20. fi
  21. if ! docker image inspect "${IMAGE}" >/dev/null 2>&1; then
  22. echo "audit.sh: image '${IMAGE}' not found locally — run 'docker compose build' first" >&2
  23. exit 2
  24. fi
  25. exec docker run --rm \
  26. -v "${REPO_ROOT}:/app" \
  27. -w /app \
  28. "${IMAGE}" \
  29. sh -c "git config --global --add safe.directory /app && composer audit --locked --no-interaction"