DOCKER_REGISTRY_URL="dockreg.ex.umbach.dev"
DOCKER_IMAGE_NAME="jnx-telegram-bot-manager"

# only allow to run this script as root
if [ "$EUID" -ne 0 ]
  then echo "Please run as root"
  exit
fi

echo "Starting go build of $DOCKER_IMAGE_NAME"
go build main.go
echo "Go build finished"

echo "Starting swagger build"
./swagger-gen.sh
echo "Finished swagger build"

# rm images
docker image rm $DOCKER_IMAGE_NAME

# build images
docker build -t $DOCKER_IMAGE_NAME .

# tag images
docker image tag $DOCKER_IMAGE_NAME:latest $DOCKER_REGISTRY_URL/$DOCKER_IMAGE_NAME:latest

# push to self-hosted docker registry
docker push $DOCKER_REGISTRY_URL/$DOCKER_IMAGE_NAME

echo "Uploaded $DOCKER_IMAGE_NAME to $DOCKER_REGISTRY_URL"