#!/bin/bash
set -e

REGISTRY="registry.bcos.cloud"
SHOULD_PUSH=false

while [[ "$#" -gt 0 ]]; do
    case $1 in
        --registry) REGISTRY="$2"; shift ;;
        --push) SHOULD_PUSH=true ;;
    esac
    shift
done

IMAGE="$REGISTRY/hiveiq-aria:latest"

echo "Building JAR..."
mvn clean package -DskipTests -B

echo "Building Docker image: $IMAGE"
docker build -t "$IMAGE" .

if [ "$SHOULD_PUSH" = true ]; then
    echo "Pushing $IMAGE..."
    docker push "$IMAGE"
fi

echo "Done: $IMAGE"
