#!/usr/bin/env bash

# Abort on first error
set -e

TAG="$1"

if [[ -z "$TAG" ]]; then
  echo
  echo "Error: please provide a version as docker image tag as first argument, e.g.:"
  echo "./deploy.sh 1.0.0"
  echo
  echo "You can check the currently deployed tag with"
  echo 'docker ps --format "{{.Names}}: {{.Image}}"'
  echo
  exit 1
fi

# Login to Greenbaum's private docker registry
echo "$DOCKER_PASSWORD" | docker login --username "$DOCKER_USERNAME" --password-stdin registry.greenbaum.cloud

# Use our tag for docker-compose
export DEPLOY_TAG="$TAG"

# Pull the latest image
docker pull registry.greenbaum.cloud/pub_solar/miom.space:"$DEPLOY_TAG"

# Deploy on Greenbaum Cloud
docker-compose --project-name miomspace up --detach
