#!/usr/bin/env bash

set -euox pipefail

current_directory="$(pwd)"

cleanup() {
    cd "${current_directory}"
    exit
}
trap cleanup INT TERM

if [[ "$OSTYPE" == "darwin"* ]]; then
  driving_root="$(cd ../.. && pwd)"
else
  driving_root="$(readlink -f $(dirname "${BASH_SOURCE[0]}")/../..)"
fi

source ./setup.sh
cd "${driving_root}/fleetdash_v2"

# Check if we are inside a container (ex: CI)
#   if we are, we need to change the default host.
if [ -f /.dockerenv ]; then
    docker -H unix:///var/run/ci_docker.sock ps
    export DOCKER_HOST=unix:///var/run/ci_docker.sock
    docker-compose -f docker-compose.yml build --no-cache --parallel
else
    docker-compose build --no-cache --parallel
fi
