<commit_before>APPNAME=<%= appName %>
APP_PATH=/opt/$APPNAME
START_SCRIPT=$APP_PATH/config/start.sh
DEPLOY_CHECK_WAIT_TIME=<%= deployCheckWaitTime %>
DEPLOY_CHECK_PORT=<%= deployCheckPort %>
HOST=<%= host %>

cd $APP_PATH

revert_app (){
  docker logs --tail=50 $APPNAME 1>&2
  if [ -d last ]; then
    sudo mv last current
    sudo bash $START_SCRIPT > /dev/null 2>&1

    echo " " 1>&2
    echo "=> Redeploying previous version of the app" 1>&2
    echo " " 1>&2
  fi
  
  echo 
  echo "To see more logs type 'mup logs --tail=50'"
  echo ""
}

elaspsed=0
while [[ true ]]; do
  sleep 1
  elaspsed=$((elaspsed+1))
  curl \
    --fail \
    -L \
    localhost:$DEPLOY_CHECK_PORT \
    <% if (host) { %> --header "HOST:$HOST" <% } %>  \
    && exit 0

  if [ "$elaspsed" == "$DEPLOY_CHECK_WAIT_TIME" ]; then
    revert_app
    exit 1
  fi
done
 <commit_msg>Fix deploy check sometimes failing when using certificates<commit_after>APPNAME=<%= appName %>
APP_PATH=/opt/$APPNAME
START_SCRIPT=$APP_PATH/config/start.sh
DEPLOY_CHECK_WAIT_TIME=<%= deployCheckWaitTime %>
DEPLOY_CHECK_PORT=<%= deployCheckPort %>
HOST=<%= host %>

cd $APP_PATH

revert_app (){
  docker logs --tail=50 $APPNAME 1>&2
  if [ -d last ]; then
    sudo mv last current
    sudo bash $START_SCRIPT > /dev/null 2>&1

    echo " " 1>&2
    echo "=> Redeploying previous version of the app" 1>&2
    echo " " 1>&2
  fi
  
  echo 
  echo "To see more logs type 'mup logs --tail=50'"
  echo ""
}

elaspsed=0
while [[ true ]]; do
  sleep 1
  elaspsed=$((elaspsed+1))

  # Since this failing causes the app to rollback, it should only
  # fail because of a problem with the app, not from problems with the config.
  #
  # --fail Before the app is started, nginx returns an error page. Without this, it would take that as meaning the app was running
  # --L Follow redirects. Needed to still work when using --fail and redirected to https version
  # --insecure Without this, it would fail if there was a problem with the certificates
  curl \
    --fail \
    -L \
    --insecure \
    localhost:$DEPLOY_CHECK_PORT \
    <% if (host) { %> --header "HOST:$HOST" <% } %>  \
    && exit 0

  if [ "$elaspsed" == "$DEPLOY_CHECK_WAIT_TIME" ]; then
    revert_app
    exit 1
  fi
done
 
{'fraction_non_alphanumeric': 0.13080357142857144, 'fraction_numerical': 0.016964285714285713, 'mean_word_length': 3.0305755395683454, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6606880', 'n_tokens_mistral': 878, 'n_tokens_neox': 796, 'n_words': 247}