#!/bin/sh

add_tag() {
    echo "Also tagging image as ${DOCKER_REPO}:${1}"
    docker tag $IMAGE_NAME $DOCKER_REPO:$1
    docker push $DOCKER_REPO:$1
}

CLOSEST_VER=$(git describe --tags --abbrev=0)
CLOSEST_MAJOR_VER=$(echo ${CLOSEST_VER} | cut -d'.' -f1)
CLOSEST_MINOR_VER=$(echo ${CLOSEST_VER} | cut -d'.' -f2)

add_tag "${CLOSEST_MAJOR_VER}-edge"
add_tag "${CLOSEST_MAJOR_VER}.${CLOSEST_MINOR_VER}-edge"

if git describe --exact-match --abbrev=0 2> /dev/null; then
    add_tag "${CLOSEST_MAJOR_VER}"
    add_tag "${CLOSEST_MAJOR_VER}.${CLOSEST_MINOR_VER}"
fi
