| 1 | #!/usr/bin/env bash |
| 2 | # Pre-push hook: build the container image when a Containerfile/Dockerfile is |
| 3 | # present, to catch broken builds locally before they reach CI. |
| 4 | # |
| 5 | # DevSecOps Guardrails epic (jmservera/SquadScope-Coordinator#33), issue #544. |
| 6 | # SquadScope ships no container file today, so this hook is a no-op until one is |
| 7 | # added at the repo root (Containerfile or Dockerfile). |
| 8 | set -euo pipefail |
| 9 | |
| 10 | containerfile="" |
| 11 | for candidate in Containerfile Dockerfile; do |
| 12 | if [ -f "$candidate" ]; then |
| 13 | containerfile="$candidate" |
| 14 | break |
| 15 | fi |
| 16 | done |
| 17 | |
| 18 | if [ -z "$containerfile" ]; then |
| 19 | echo "docker-build: no Containerfile/Dockerfile found — skipping." |
| 20 | exit 0 |
| 21 | fi |
| 22 | |
| 23 | if ! command -v docker >/dev/null 2>&1; then |
| 24 | echo "docker-build: '$containerfile' present but docker is not installed." >&2 |
| 25 | echo "docker-build: install Docker or push with --no-verify (then fix locally)." >&2 |
| 26 | exit 1 |
| 27 | fi |
| 28 | |
| 29 | echo "docker-build: building image from $containerfile ..." |
| 30 | docker build -f "$containerfile" -t squadscope-local-build-check . |
| 31 | echo "docker-build: build succeeded." |