#!/usr/bin/env bash

set -euo pipefail

if [[ -z "${1:-}" || "$1" == '--help' || "$1" == '-h' ]]; then
  echo "Usage: $0 TAG"
  exit 1
fi

tag="$1"
metrics_server_image_name="pcp.docker.zooxlabs.com/pcp-ci-metrics-backend:$tag"

cd "$( (builtin cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) )"

(
  set -x
  bazel build -c opt //web_apps/pcp_ci/metrics_server:metrics_server_image.tar

  docker load -i $(bazel info bazel-bin)/web_apps/pcp_ci/metrics_server/metrics_server_image.tar

  docker tag bazel/web_apps/pcp_ci/metrics_server:metrics_server_image "$metrics_server_image_name"

  docker push "$metrics_server_image_name"
)

echo Success!
