#!/bin/sh

set -e

STACK_LOCAL_INSTALL_ROOT=`stack path --local-install-root`
EXE_FILE="${STACK_LOCAL_INSTALL_ROOT}/bin/get-client-ip"

# docker hub user name or private registry URL with username.
DOCKER_IMAGE_PREFIX=sylecn

stack build
if [ ! -e "$EXE_FILE" ]; then
	echo "Error: stack build failed" > /dev/stderr
	exit 1
fi

VERSION=`grep "^version:" get-client-ip.cabal | awk '{print $2}'`

ln -f "$EXE_FILE" docker/get-client-ip
docker build -t $DOCKER_IMAGE_PREFIX/get-client-ip:"$VERSION" docker/
docker push $DOCKER_IMAGE_PREFIX/get-client-ip:"${VERSION}"
