#!/bin/bash

re="^v([0-9]+)\.([0-9]+)\.([0-9]+)$"

if [[ $DOCKER_TAG =~ $re ]]; then
  docker tag $IMAGE_NAME "$DOCKER_REPO:v${BASH_REMATCH[1]}.${BASH_REMATCH[2]}"
  docker push "$DOCKER_REPO:v${BASH_REMATCH[1]}.${BASH_REMATCH[2]}"

  docker tag $IMAGE_NAME "$DOCKER_REPO:v${BASH_REMATCH[1]}"
  docker push "$DOCKER_REPO:v${BASH_REMATCH[1]}"
fi
