#!/usr/bin/env bash

set -euo pipefail

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

tag="$1"
bazel_image="bazel/infra/data_catalog:catalog_backend_run_gunicorn_image"
image_name="docker-registry.zooxlabs.com/datacatalog_backend:$tag"

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

(
  set -x
  bazel run //infra/data_catalog:catalog_backend_run_gunicorn_image -- -h

  docker tag "$bazel_image" "$image_name"
  docker push "$image_name"
)

echo Success!
echo Follow the instructions at /infra/terraform/catalog_backend/README.md
echo to finish deployment.
