#!/usr/bin/env bash
set -euo pipefail

scripts="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

# Push the current Version of this service image to the registry

service=$(basename $PWD)
if [ $service == "kong" ]; then
  service="restapi"
fi

version_next=$(git rev-parse --short HEAD)
image_tag="marvel2-$service:$version_next"
image_tag_latest="marvel2-$service:latest"
remote="sim.docker.zooxlabs.com"

echo Pushing $service version $version_next

# Tag and push Docker image
# Prerequisite: docker login sim.docker.zooxlabs.com
(
  set -x
  docker tag $image_tag "$remote/$image_tag"
  docker tag $image_tag "$remote/$image_tag_latest"
  docker push "$remote/$image_tag"
  docker push "$remote/$image_tag_latest"
)
echo Pushed $service image, version $version_next

# If this is a Go service, push its Go module to our module repo
# Prerequisite: jfrog rt config
if [ -f go.mod ]; then
  jfrog rt gp go-zoox v0.0.0-$version_next

  echo Pushed $service module, version v0.0.0-$version_next
fi
