#!/bin/bash
# 构建算力引擎镜像（new-api 源码在 code/compute-engine，server-core 的兄弟仓库）
set -euo pipefail

# 本脚本位于 server-core/serverrun/compute-engine/
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# 计算源仓库：server-core/serverrun/compute-engine → ../../.. → code/ → compute-engine
SRC_DIR="$(cd "$SCRIPT_DIR/../../.." && pwd)"
ENGINE_SRC="${ENGINE_SRC:-$SRC_DIR/compute-engine}"
TAG="${COMPUTE_ENGINE_TAG:-opc-compute-engine:latest}"

if [ ! -f "$ENGINE_SRC/Dockerfile" ]; then
    echo "错误：未找到算力引擎源码 $ENGINE_SRC/Dockerfile" >&2
    echo "（clone: git clone http://code.infoepoch.cn/Pine/compute-engine.git $ENGINE_SRC）" >&2
    exit 1
fi

echo "构建算力引擎镜像：$TAG（源码 $ENGINE_SRC）..."
docker build -t "$TAG" "$ENGINE_SRC"
echo "构建完成：$TAG"
