#!/bin/bash

counter=0
timeout=55 #times

sleep 5s

while [[ $counter -lt $timeout ]] && ! grep  "The build folder is ready to be deployed." /build_logs/build.log #-qs
  do
    echo "waiting react container is ready $(( $counter * 5 )) s"
    sleep 5s
    counter=$(( $counter + 1 ))
  done

if [[ $counter -eq $timeout ]]; then echo "timeout. react build failed."; fi

cp -f /react-build/index.html /usr/src/app/console/templates/console/index.html
rm -f /react-build/index.html
mkdir -p /usr/src/app/console/static/react
cp -rf /react-build/* /usr/src/app/console/static/react
/bin/bash ./start_dev_django_app.sh ${SERVE:-gunicorn}