#!/usr/bin/env bash

new_version=${1?param missing - new docker version.}
overwrite=${2:0}
docker_registry=docker-registry.zooxlabs.com

python pipedream/framework/scripts/deploy_pipedream.py
pipedream/scheduling/dockerize.sh

curl --silent --head -f  -lL   https://$docker_registry/v2/pipedream_scheduling/manifests/$new_version > /dev/null
retVal=$?

if [[ ($retVal -eq 0) && ($overwrite -eq 0) ]]; then
    echo "NOT PUSHING!!! Tag $new_version already exists"
    exit -1
fi

docker tag $docker_registry/pipedream_scheduling $docker_registry/pipedream_scheduling:$new_version
docker push $docker_registry/pipedream_scheduling:$new_version
