#!/usr/bin/env bash
set -euo pipefail

APP_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd $APP_ROOT

export IMAGE_NAME="scenario_editor_frontend"
export CONTAINER_NAME="se_frontend_container"

if [ $# -ge 1 ] && [ "$1" == "-h" ]; then
  echo
  echo "usage:  run.sh [-h] [--no_rebuild]"
  echo
  exit
fi

if [ $# -eq 0 ] || [ "$1" != "--no_rebuild" ]; then
  set +e  # prevent error from stopping execution if image doesn't exist
  docker rmi -f $IMAGE_NAME
  set -e
  ./scripts/release/build_image.sh $IMAGE_NAME
fi

./scripts/release/run_image.sh
