#!/usr/bin/env bash

# fail asap
set -e

# Check if an argument was provided
if [ $# -eq 0 ]; then
    echo "No arguments provided"
    echo "Usage: scripts/publish-internal.sh <buildnum> [debug]"
    echo ""
    echo "First argument indicates the day's build number, starting from 0."
    echo "Last argument specifies whether we should have a debug build as opposed to release build."
    exit 1
fi

TAG=$(date -u +%Y%m%d)-$1
DEBUG=$2
if [ "$DEBUG" = "true" ]; then
  TAG=$TAG-debug
fi

echo "Building images"
docker build -t localhost:5000/revoltchat/revite:$TAG -f Dockerfile .

echo "Pushing images to localhost:5000 with tag: $TAG!"
docker push localhost:5000/revoltchat/revite:$TAG

echo "Archiving source"
git archive --format=tar HEAD | bzip2 >../revite.tar.bz2
