#!/bin/bash
set -e

# Manual fallback — CI normally handles this via .gitea/workflows/build.yml
# Usage: ./build-and-push.sh [tag]
#   ./build-and-push.sh staging
#   ./build-and-push.sh v1.0.0

REGISTRY="10.10.1.132:3000/marwan/hh"
TAG=${1:-staging}

echo "========================================"
echo "  PX360 Manual Build & Push (fallback)"
echo "  Tag: $REGISTRY:$TAG"
echo "  $(date '+%Y-%m-%d %H:%M:%S')"
echo "========================================"
echo ""
echo "NOTE: CI normally handles this. Only use if CI is unavailable."
echo ""

docker login 10.10.1.132:3000

echo ""
echo "[1/3] Building image..."
docker build -t "$REGISTRY:$TAG" .

echo ""
echo "[2/3] Pushing to registry..."
docker push "$REGISTRY:$TAG"

echo ""
echo "[3/3] Done! Pushed: $REGISTRY:$TAG"
echo ""
echo "Deploy: ./deploy.staging.sh $TAG (or ./deploy.prod.sh $TAG)"
