#!/usr/bin/env bash
#
# Build and push Invidious
#
# TODO: remove Docker hub, push with SSH.

set -e

destdir=$HOME/dev/invidious
image=netfluxio/invidious:latest 
remotehost=netflux

if [ ! -d $destdir ]; then
  echo "Cloning invidious..."
  cd $HOME/dev
  git clone -q --depth=1 https://github.com/iv-org/invidious.git invidious
else
  echo "Updating invidious..."
  cd $destdir
  git pull --rebase
fi

cd $destdir
docker build -t $image -f docker/Dockerfile .
docker push $image

ssh $remotehost 'cd dev/netflux-internals && docker-compose pull invidious && docker-compose up -d --force-recreate --no-deps invidious'