#!/bin/bash
# Make a cpu-enabled docker image and push it to quay
# Todo: it'd be nice to get travis to do this to be more consistent with normal docker
# Note: must be run for cactus/ directory

set -x
set -beEu -o pipefail
mydir=$(dirname $(which $0))
source ${mydir}/releaseLib.sh

buildDir=$(realpath -m build)
binBuildDir="${buildDir}/cpu-docker-tmp"

set -x
rm -rf ${binBuildDir}
mkdir -p ${binBuildDir}
cd ${binBuildDir}
git clone --recursive https://github.com/ComparativeGenomicsToolkit/cactus.git
cd cactus
git fetch --tags origin

REL_TAG=$(getLatestReleaseTag)
git checkout "${REL_TAG}"
git submodule update --init --recursive

docker build . -f Dockerfile -t ${dockname}:${REL_TAG}
docker tag ${dockname}:${REL_TAG} ${dockname}:latest

read -p "Are you sure you want to push ${dockname}:${REL_TAG} to quay?" yn
case $yn in
    [Yy]* ) docker push ${dockname}:${REL_TAG} && docker push ${dockname}:latest ; break;;
    [Nn]* ) exit;;
    * ) echo "Please answer yes or no.";;
esac
popd
