#!/usr/bin/env bash
# Build & push CaseGambling image to Docker Hub (user: foufure)
# Usage:
#   ./scripts/docker-build-push.sh           # tag: latest
#   ./scripts/docker-build-push.sh v1.0.0   # tag: v1.0.0 + latest
# Requires: docker login (docker login)
set -euo pipefail

ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT"

DOCKERHUB_USER="${DOCKERHUB_USER:-foufure}"
# Docker Hub requires lowercase repository names
IMAGE_NAME="${IMAGE_NAME:-casegambling}"
IMAGE="${DOCKERHUB_USER}/${IMAGE_NAME}"
TAG="${1:-latest}"

echo "==> Building ${IMAGE}:${TAG}"
docker build \
  -t "${IMAGE}:${TAG}" \
  -t "${IMAGE}:latest" \
  -f Dockerfile \
  .

echo "==> Pushing ${IMAGE}:${TAG}"
docker push "${IMAGE}:${TAG}"

if [[ "${TAG}" != "latest" ]]; then
  echo "==> Pushing ${IMAGE}:latest"
  docker push "${IMAGE}:latest"
fi

echo "==> Done: ${IMAGE}:${TAG}"
echo "    Pull: docker pull ${IMAGE}:${TAG}"
