#!/bin/sh

CLOSEST_VER=$(git describe --tags --abbrev=0 ${SOURCE_COMMIT})
if git describe --exact-match --abbrev=0 ${SOURCE_COMMIT} 2> /dev/null; then
    BUILD_INFO="v${CLOSEST_VER}"
else
    BUILD_INFO="v${CLOSEST_VER}-edge-$(git rev-parse --short ${SOURCE_COMMIT})"
fi

echo "Using BUILD_INFO=${BUILD_INFO}"
docker build \
    --build-arg BUILD_INFO=${BUILD_INFO} \
    --build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \
    --build-arg SOURCE_COMMIT \
    --build-arg DOCKER_REPO \
    -f $DOCKERFILE_PATH -t $IMAGE_NAME .
