#!/bin/bash
. .env

container=$(docker-compose ps -q)
if [[ "${container}" != "" ]]; then
  name=$(docker container ls -f id=${container} --format "{{.Names}}")
  if [[ "${name}" == "" ]]; then
    >&2 echo "No container name found for ${container}"
    exit 1
  fi

  >&2 echo "ketr.chat is already running as ${name}. Try './shell'."
  exit 1
fi

if [[ -z ${DEVELOPMENT} ]]; then
  echo "Launching PRODUCTION"
  docker-compose  \
    -f docker-compose.yml -f production.yml up -d ketr.chat-production $@
else
  echo "Launching DEVELOPMENT"
  docker-compose \
    -f docker-compose.yml -f development.yml up -d ketr.chat $@
fi
