#!/bin/bash

source "$( dirname "${BASH_SOURCE[0]}")/.functions.sh"

docker-compose stop usasapp usasdb
resetDbVolume usasdb
docker-compose rm -vf usasapp usasdb

export IMP_IRN=${IMP_IRN}
export IMP_URL=${IMP_URL-ftp://username:password@nwoca.org}
export IMP_PATH=${IMP_PATH}

[ -f "docker-compose.override.yml" ] && export OVERRIDE=" -f docker-compose.override.yml"
#
docker-compose -f docker-compose.yml -f ${SSDT_HOME}/pilot/import-usas.yml $OVERRIDE rm -f usasimport 
# start import and wait for completion
docker-compose -f docker-compose.yml -f ${SSDT_HOME}/pilot/import-usas.yml $OVERRIDE up usasimport | tee usasimport.log
# remove temporary container
docker-compose -f docker-compose.yml -f ${SSDT_HOME}/pilot/import-usas.yml $OVERRIDE rm -f usasimport
# start application
docker-compose up -d usasapp

