#!/bin/bash
set -euo pipefail

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

echo "=== ScadaLink Docker Build ==="

# Ensure the shared network exists
if ! docker network inspect scadalink-net >/dev/null 2>&1; then
    echo "Creating scadalink-net network..."
    docker network create scadalink-net
fi

# Build from repo root (so COPY paths in Dockerfile resolve correctly)
echo "Building scadalink:latest image..."
docker build \
    -t scadalink:latest \
    -f "$SCRIPT_DIR/Dockerfile" \
    "$REPO_ROOT"

echo "Build complete: scadalink:latest"
