#!/bin/bash
set -e

cd "$(dirname "$0")/.."

REGISTRY="${GITEA_REGISTRY:-git.msksbr.com}"
USERNAME="${GITEA_USERNAME:-msksbr}"
IMAGE="$REGISTRY/$USERNAME/bookmgr-client"
VERSION=$(node -e "console.log(require('./package.json').version)")

echo ">>> 版本: $VERSION"
echo ">>> 镜像: $IMAGE"

echo ">>> 构建镜像..."
docker build \
  --network=host \
  -t "$IMAGE:$VERSION" \
  -t "$IMAGE:latest" \
  .

echo ">>> 推送镜像..."
docker push "$IMAGE:$VERSION"
docker push "$IMAGE:latest"

echo ""
echo "完成！"
echo "  镜像: $IMAGE:$VERSION"
echo "  镜像: $IMAGE:latest"
echo ""
echo "部署："
echo "  docker run -d -p 80:80 $IMAGE:$VERSION"
